From 347bac104173f6ecf48f26590e6c58638c12a089 Mon Sep 17 00:00:00 2001 From: Adrian Riobo Lorenzo Date: Wed, 10 Jan 2024 11:07:52 -0500 Subject: [PATCH] chore: add gh action to run e2e tests on Windows Desktops machines Signed-off-by: Adrian Riobo Lorenzo --- .github/workflows/all.yml | 170 ++++++++++++++++++++++++++++++++++ .github/workflows/builder.yml | 56 +++++++++++ .github/workflows/tester.yml | 95 +++++++++++++++++++ Makefile | 7 ++ docs/e2e.md | 29 ++++++ oci/e2e/Containerfile | 23 +++++ oci/e2e/run.ps1 | 10 ++ 7 files changed, 390 insertions(+) create mode 100644 .github/workflows/all.yml create mode 100644 .github/workflows/builder.yml create mode 100644 .github/workflows/tester.yml create mode 100644 docs/e2e.md create mode 100644 oci/e2e/Containerfile create mode 100755 oci/e2e/run.ps1 diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml new file mode 100644 index 0000000..6cc11ea --- /dev/null +++ b/.github/workflows/all.yml @@ -0,0 +1,170 @@ +name: all + +on: + push: + branches: + - "main" + pull_request: {} + +env: + OCI_E2E_NAME: libhvee-e2e + CORRELATE: ${{ github.sha }} + +jobs: + build-oci-e2e: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Build and archive e2e image + # use github.sha as ID to correlate various workflows triggered by the same event + run: | + VERSION=${{ env.CORRELATE}} make build-oci-e2e + podman save -o ${{ env.OCI_E2E_NAME }}.tar quay.io/rhqp/${{ env.OCI_E2E_NAME}}:v${{ env.CORRELATE }} + + - name: Upload e2e flat image as artifact + uses: actions/upload-artifact@v4 + with: + name: libhvee-e2e-v${{ env.CORRELATE }} + path: libhvee-e2e.tar + + build-executables: + runs-on: windows-2022 + strategy: + fail-fast: false + steps: + + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.18' + + - name: Build libhvee executables + run: make build + + - name: Upload libhvee executables as artifact + uses: actions/upload-artifact@v4 + with: + name: libhvee-v${{ env.CORRELATE }} + path: bin/*.exe + + e2e-windows-destkop: + needs: + - build-oci-e2e + - build-executables + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + windows-version: ['10','11'] + windows-featurepack: ['22h2-ent', '23h2-ent'] + exclude: + - windows-version: '10' + windows-featurepack: '23h2-ent' + - windows-version: '11' + windows-featurepack: '22h2-ent' + + steps: + - name: Create instance + run: | + # Create instance + podman run -d --name windows-create --rm \ + -v ${PWD}:/workspace:z \ + -e ARM_TENANT_ID=${{ secrets.ARM_TENANT_ID }} \ + -e ARM_SUBSCRIPTION_ID=${{ secrets.ARM_SUBSCRIPTION_ID }} \ + -e ARM_CLIENT_ID=${{ secrets.ARM_CLIENT_ID }} \ + -e ARM_CLIENT_SECRET='${{ secrets.ARM_CLIENT_SECRET }}' \ + -e AZURE_STORAGE_ACCOUNT='${{ secrets.AZURE_STORAGE_ACCOUNT }}' \ + -e AZURE_STORAGE_KEY='${{ secrets.AZURE_STORAGE_KEY }}' \ + quay.io/rhqp/qenvs:v0.6.1 azure \ + windows create \ + --project-name 'windows-desktop-${{ matrix.windows-version }}-${{ matrix.windows-featurepack }}' \ + --backed-url azblob://qenvs-state/${{ github.sha }} \ + --conn-details-output '/workspace' \ + --windows-version '${{ matrix.windows-version }}' \ + --windows-featurepack '${{ matrix.windows-featurepack }}' \ + --tags org=containers,project=libhvee,origin=ghaction \ + --spot + # Check logs + podman logs -f windows-create + + - name: Check instance system info + run: | + ssh -i id_rsa \ + -o StrictHostKeyChecking=no \ + -o UserKnownHostsFile=/dev/null \ + -o ServerAliveInterval=30 \ + -o ServerAliveCountMax=1200 \ + $(cat username)@$(cat host) "systeminfo" + + - name: Download libhvee artifacts + id: download-libhvee-artifacts + uses: actions/download-artifact@v4 + + - name: Run libhvee e2e + run: | + # Load image from artifact + podman load -i libhvee-e2e-v${{ env.CORRELATE }}/libhvee-e2e.tar + + # Run container + podman run --rm -d --name libhvee-e2e \ + -v $PWD:/workspace:z \ + -v $PWD/libhvee-v${{ env.CORRELATE }}/createvm.exe:/opt/libhvee-e2e/createvm.exe:z \ + -v $PWD/libhvee-v${{ env.CORRELATE }}/dumpvms.exe:/opt/libhvee-e2e/dumpvms.exe:z \ + -v $PWD/libhvee-v${{ env.CORRELATE }}/kvpctl.exe:/opt/libhvee-e2e/kvpctl.exe:z \ + -v $PWD/libhvee-v${{ env.CORRELATE }}/updatevm.exe:/opt/libhvee-e2e/updatevm.exe:z \ + -e PLATFORM=windows \ + -e TARGET_HOST=$(cat host) \ + -e TARGET_HOST_USERNAME=$(cat username) \ + -e TARGET_HOST_KEY_PATH=/workspace/id_rsa \ + -e TARGET_FOLDER=libhvee-e2e \ + -e TARGET_RESULTS=libhvee-e2e.xml \ + -e OUTPUT_FOLDER=/workspace \ + -e DEBUG=true \ + quay.io/rhqp/libhvee-e2e:v${{ env.CORRELATE }} \ + libhvee-e2e/run.ps1 \ + -targetFolder libhvee-e2e \ + -junitResultsFilename libhvee-e2e.xml + # Check logs + podman logs -f libhvee-e2e + + - name: Evaluate libhvee e2e results + uses: mikepenz/action-junit-report@v4 + with: + fail_on_failure: true + include_passed: true + detailed_summary: true + require_tests: true + report_paths: libhvee-e2e.xml + + - name: Upload libhvee e2e results + uses: actions/upload-artifact@v4 + with: + name: libhvee-e2e-${{ matrix.windows-version }}${{ matrix.windows-featurepack }} + path: libhvee-e2e.xml + + - name: Destroy instance + if: always() + run: | + # Destroy instance + podman run -d --name windows-destroy --rm \ + -v ${PWD}:/workspace:z \ + -e ARM_TENANT_ID=${{ secrets.ARM_TENANT_ID }} \ + -e ARM_SUBSCRIPTION_ID=${{ secrets.ARM_SUBSCRIPTION_ID }} \ + -e ARM_CLIENT_ID=${{ secrets.ARM_CLIENT_ID }} \ + -e ARM_CLIENT_SECRET='${{ secrets.ARM_CLIENT_SECRET }}' \ + -e AZURE_STORAGE_ACCOUNT='${{ secrets.AZURE_STORAGE_ACCOUNT }}' \ + -e AZURE_STORAGE_KEY='${{ secrets.AZURE_STORAGE_KEY }}' \ + quay.io/rhqp/qenvs:v0.6.1 azure \ + windows destroy \ + --project-name 'windows-desktop-${{ matrix.windows-version }}-${{ matrix.windows-featurepack }}' \ + --backed-url azblob://qenvs-state/${{ github.sha }} + # Check logs + podman logs -f windows-destroy diff --git a/.github/workflows/builder.yml b/.github/workflows/builder.yml new file mode 100644 index 0000000..3233349 --- /dev/null +++ b/.github/workflows/builder.yml @@ -0,0 +1,56 @@ +name: builder + +# on: +# push: +# branches: +# - "main" +# pull_request: {} + +env: + OCI_E2E_NAME: libhvee-e2e + +jobs: + build-oci-e2e: + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Build and archive e2e image + # use github.sha as ID to correlate various workflows triggered by the same event + run: | + VERSION=${{ github.sha }} make build-oci-e2e + podman save -o ${{ env.OCI_E2E_NAME }}.tar quay.io/rhqp/${{ env.OCI_E2E_NAME}}:v${{ github.sha }} + + - name: Upload e2e flat image as artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ env.OCI_E2E_NAME }}-v${{ github.sha }} + path: ${{ env.OCI_E2E_NAME }}.tar + + build-executables: + runs-on: windows-2022 + strategy: + fail-fast: false + + steps: + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.18' + + - name: Build libhvee executables + run: make build + + - name: Upload libhvee executables as artifact + uses: actions/upload-artifact@v3 + with: + name: libhvee-v${{ github.sha }} + path: bin/*.exe + \ No newline at end of file diff --git a/.github/workflows/tester.yml b/.github/workflows/tester.yml new file mode 100644 index 0000000..1e2687a --- /dev/null +++ b/.github/workflows/tester.yml @@ -0,0 +1,95 @@ +name: tester + +# TODO unconmment when moved to upstream +# on: +# workflow_run: +# workflows: +# - builder +# types: +# - completed + +jobs: + e2e-windows-destkop: + # TODO remove When moved to upstream needs will be removed + # as job will be executed from a workflow_run + needs: + - build-oci-e2e + - build-executables + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + windows-version: ['10','11'] + windows-featurepack: ['22h2-ent', '23h2-ent'] + exclude: + - windows-version: '10' + windows-featurepack: '23h2-ent' + - windows-version: '11' + windows-featurepack: '22h2-ent' + + steps: + # When moving to be executed on upstream we need to save the context + # to try match the ${{ github.sha }} or some other correlation value + - name: Create instance + run: | + # Create instance + podman run -d --name windows-create --rm \ + -v ${PWD}:/workspace:z \ + -e ARM_TENANT_ID=${{ secrets.ARM_TENANT_ID }} \ + -e ARM_SUBSCRIPTION_ID=${{ secrets.ARM_SUBSCRIPTION_ID }} \ + -e ARM_CLIENT_ID=${{ secrets.ARM_CLIENT_ID }} \ + -e ARM_CLIENT_SECRET='${{ secrets.ARM_CLIENT_SECRET }}' \ + -e AZURE_STORAGE_ACCOUNT='${{ secrets.AZURE_STORAGE_ACCOUNT }}' \ + -e AZURE_STORAGE_KEY='${{ secrets.AZURE_STORAGE_KEY }}' \ + quay.io/rhqp/qenvs:v0.6.1 azure \ + windows create \ + --project-name 'windows-desktop' \ + --backed-url azblob://qenvs-state/${{ github.sha }} \ + --conn-details-output '/workspace' \ + --windows-version '${{ matrix.windows-version }}' \ + --windows-featurepack '${{ matrix.windows-featurepack }}' \ + --tags org=containers,project=libhvee,origin=ghaction \ + --spot + # Check logs + podman logs -f windows-create + + - name: Check instance system info + run: | + ssh -i id_rsa \ + -o StrictHostKeyChecking=no \ + -o UserKnownHostsFile=/dev/null \ + -o ServerAliveInterval=30 \ + -o ServerAliveCountMax=1200 \ + $(cat username)@$(cat host) "systeminfo" + + - name: Download e2e flat image as artifact + id: download-images-artifact + uses: dawidd6/action-download-artifact@v3 + with: + # workflow_conclusion: completed + # workflow: build-tests.yml + name: libhvee-e2e-v${{ github.sha }} + + - name: Run libhvee e2e + run: | + # load libhvee-e2e image from tar file + podman load -i libhvee-e2e.tar + + - name: Destroy instance + if: always() + run: | + # Destroy instance + podman run -d --name windows-destroy --rm \ + -v ${PWD}:/workspace:z \ + -e ARM_TENANT_ID=${{ secrets.ARM_TENANT_ID }} \ + -e ARM_SUBSCRIPTION_ID=${{ secrets.ARM_SUBSCRIPTION_ID }} \ + -e ARM_CLIENT_ID=${{ secrets.ARM_CLIENT_ID }} \ + -e ARM_CLIENT_SECRET='${{ secrets.ARM_CLIENT_SECRET }}' \ + -e AZURE_STORAGE_ACCOUNT='${{ secrets.AZURE_STORAGE_ACCOUNT }}' \ + -e AZURE_STORAGE_KEY='${{ secrets.AZURE_STORAGE_KEY }}' \ + quay.io/rhqp/qenvs:v0.6.1 azure \ + windows destroy \ + --project-name 'windows-desktop' \ + --backed-url azblob://qenvs-state/${{ github.sha }} + # Check logs + podman logs -f windows-destroy diff --git a/Makefile b/Makefile index 4c45600..0189b55 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ export GOOS=windows export GOARCH=amd64 SRC = $(shell find . -type f -name '*.go') +VERSION ?= 0.0.1 +IMG ?= quay.io/rhqp/libhvee-e2e:v${VERSION} +CONTAINER_MANAGER ?= podman .PHONY: default default: build @@ -37,3 +40,7 @@ bin/updatevm.exe: $(SRC) go.mod go.sum clean: rm -rf bin + +.PHONY: build-oci-e2e +build-oci-e2e: + ${CONTAINER_MANAGER} build -t ${IMG} -f oci/e2e/Containerfile --build-arg=OS=${GOOS} --build-arg=ARCH=${GOARCH} . diff --git a/docs/e2e.md b/docs/e2e.md new file mode 100644 index 0000000..4ded85e --- /dev/null +++ b/docs/e2e.md @@ -0,0 +1,29 @@ +# e2e + +TBC + +## Container + +Build container image + +```bash +make build-oci-e2e +``` + +Sample for running the container with e2e on remote target + +```bash +podman run --rm -it --name libhvee-e2e \ + -e TARGET_HOST=$(cat host) \ + -e TARGET_HOST_USERNAME=$(cat username) \ + -e TARGET_HOST_KEY_PATH=/data/id_rsa \ + -e TARGET_FOLDER=libhvee-e2e \ + -e TARGET_RESULTS=libhvee-e2e.xml \ + -e OUTPUT_FOLDER=/data \ + -e DEBUG=true \ + -v $PWD:/data:z \ + quay.io/rhqp/libhvee-e2e:v0.0.1 \ + libhvee-e2e/run.ps1 \ + -targetFolder libhvee-e2e \ + -junitResultsFilename libhvee-e2e.xml +``` \ No newline at end of file diff --git a/oci/e2e/Containerfile b/oci/e2e/Containerfile new file mode 100644 index 0000000..fcc5e04 --- /dev/null +++ b/oci/e2e/Containerfile @@ -0,0 +1,23 @@ + +FROM registry.access.redhat.com/ubi9/go-toolset:1.18 as builder + +COPY . . + +ARG OS +ARG ARCH + +RUN GOOS=${OS} GOARCH=${ARCH} go test -v test/e2e/*.go -c -o ./build/libhvee-e2e.exe + +FROM quay.io/rhqp/deliverest:v0.0.3 + +ARG OS +ARG ARCH + +ENV ASSETS_FOLDER=/opt/libhvee-e2e \ + OS=${OS} \ + ARCH=${ARCH} + +# LABEL org.opencontainpoders.image.authors="Adrian Riobo" + +COPY --from=builder /opt/app-root/src/build/libhvee-e2e.exe ${ASSETS_FOLDER}/ +COPY oci/e2e/run.ps1 ${ASSETS_FOLDER}/ diff --git a/oci/e2e/run.ps1 b/oci/e2e/run.ps1 new file mode 100755 index 0000000..732979f --- /dev/null +++ b/oci/e2e/run.ps1 @@ -0,0 +1,10 @@ +param( + [Parameter(Mandatory,HelpMessage='folder on target host where assets are copied')] + $targetFolder, + [Parameter(Mandatory,HelpMessage='junit results filename')] + $junitResultsFilename +) + +# Run e2e +$env:PATH="$env:PATH;$env:HOME\$targetFolder;" +libhvee-e2e.exe --ginkgo.vv --ginkgo.junit-report="$targetFolder/$junitResultsFilename"