Skip to content

Commit

Permalink
tester
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Riobo Lorenzo <[email protected]>
  • Loading branch information
adrianriobo committed Jan 23, 2024
1 parent 710e0e6 commit 1023483
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 0 deletions.
184 changes: 184 additions & 0 deletions .github/workflows/tester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
name: tester

on:
workflow_run:
workflows:
- builder
types:
- completed

env:
STATUS_CONTEXT: ci/e2e/windows-desktop

jobs:
e2e-windows-destkop:
runs-on: ubuntu-latest
permissions:
statuses: write # needed to update commit status (pending/failure/sucess)
checks: write # as documented in https://github.com/mikepenz/action-junit-report?tab=readme-ov-file#pr-run-permissions
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: Get context
id: download-gh-context-artifact
uses: dawidd6/action-download-artifact@v3
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: gh_context

- name: Correlate with PR
run: |
set -xuo
# SHA used as ID to correlate artifacts between buld-tests, windows-installer, and windows-e2e workflows
echo "SHA=$(cat gh_context.json | jq -r '.sha')" >> "$GITHUB_ENV"
COMMIT_ID=$(cat gh_context.json | jq -r '.event.after')
# if this is a new PR, .event.after is empty, use .sha instead in that case
if [[ -z "$COMMIT_ID" ]]; then
COMMIT_ID=$(cat gh_context.json | jq -r '.sha')
fi
# COMMIT_SHA used to identify commit whose status needs to be set to reflect test results
echo "COMMIT_SHA=$COMMIT_ID" >> "$GITHUB_ENV"
- name: Add status to PR
run: |
OUTCOME="pending"
DESCRIPTION="Running e2e on Windows Desktop"
CONTEXT="${{ env.STATUS_CONTEXT}}-${{ matrix.windows-version }}-${{ matrix.windows-featurepack }}"
# post result to commit status
curl -L -v \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.COMMIT_SHA }} \
-d "{\"state\":\"${OUTCOME}\", \"description\":\"${DESCRIPTION}\", \"context\":\"${CONTEXT}\", \"target_url\":\"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}"
- name: Get libhvee e2e oci image from PR as artifact
id: download-oci-image-artifact
uses: dawidd6/action-download-artifact@v3
with:
workflow_conclusion: completed
workflow: builder.yml
name: libhvee-e2e-v${{ env.SHA }}

- name: Get libhvee binaries from PR as artifact
id: download-binaries-artifact
uses: dawidd6/action-download-artifact@v3
with:
workflow_conclusion: completed
workflow: builder.yml
name: libhvee-v${{ env.SHA }}


- 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/${{ env.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: Run libhvee e2e
run: |
# Load image from artifact
podman load -i libhvee-e2e.tar
# Run container
podman run --rm -d --name libhvee-e2e \
-v $PWD:/workspace:z \
-v $PWD/createvm.exe:/opt/libhvee-e2e/createvm.exe:z \
-v $PWD/dumpvms.exe:/opt/libhvee-e2e/dumpvms.exe:z \
-v $PWD/kvpctl.exe:/opt/libhvee-e2e/kvpctl.exe:z \
-v $PWD/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.SHA }} \
libhvee-e2e/run.ps1 \
-targetFolder libhvee-e2e \
-junitResultsFilename libhvee-e2e.xml
# Check logs
podman logs -f libhvee-e2e
- name: Test Report
if: always()
id: test-report
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: Result status to PR
if: always()
run: |
OUTCOME="success"
if [[ ${{steps.test-report.outcome}} != "success" ]]; then
OUTCOME="failure";
fi
DESCRIPTION="Finished e2e on Windows e2e"
CONTEXT="${{ env.STATUS_CONTEXT}}-${{ matrix.windows-version }}-${{ matrix.windows-featurepack }}"
# post result to commit status
curl -L -v \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.COMMIT_SHA }} \
-d "{\"state\":\"${OUTCOME}\", \"description\":\"${DESCRIPTION}\", \"context\":\"${CONTEXT}\", \"target_url\":\"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}"
- 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/${{ env.SHA }}
# Check logs
podman logs -f windows-destroy
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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} .
29 changes: 29 additions & 0 deletions docs/e2e.md
Original file line number Diff line number Diff line change
@@ -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
```
23 changes: 23 additions & 0 deletions oci/e2e/Containerfile
Original file line number Diff line number Diff line change
@@ -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<[email protected]>"

COPY --from=builder /opt/app-root/src/build/libhvee-e2e.exe ${ASSETS_FOLDER}/
COPY oci/e2e/run.ps1 ${ASSETS_FOLDER}/
10 changes: 10 additions & 0 deletions oci/e2e/run.ps1
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 1023483

Please sign in to comment.