From 57b4d2078d4dbb3d6dd554f080ca37be660c42c1 Mon Sep 17 00:00:00 2001 From: Rafal Kolucki Date: Wed, 12 Apr 2023 15:16:30 +0200 Subject: [PATCH] Publish unit test logs to GitHub Pages Signed-off-by: Rafal Kolucki --- .github/workflows/verification-deploy.yml | 55 ++++++++++++++++++++++ .github/workflows/verification-remove.yml | 32 +++++++++++++ .github/workflows/verification.yml | 57 ++++++++++++++++++++++- 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/verification-deploy.yml create mode 100644 .github/workflows/verification-remove.yml diff --git a/.github/workflows/verification-deploy.yml b/.github/workflows/verification-deploy.yml new file mode 100644 index 0000000000..65fcca0a38 --- /dev/null +++ b/.github/workflows/verification-deploy.yml @@ -0,0 +1,55 @@ +name: Deploy PR preview + +on: + workflow_run: + workflows: ["VeeR-EL2 verification"] + types: + - completed + +jobs: + deploy: + name: Deploy PR preview + runs-on: ubuntu-22.04 + concurrency: + group: gh-pages + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} + + steps: + - name: Download current deployment + uses: actions/checkout@v3 + with: + ref: gh-pages + path: ./public + + - name: Download artifacts + uses: actions/github-script@v3.1.0 + with: + script: | + var artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{ github.event.workflow_run.id }}, + }); + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "pr_deployment" + })[0]; + var download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + console.log("::set-output name=artifact_id::" + matchArtifact.id); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/pr_deployment.zip', Buffer.from(download.data)); + + - name: Unpack artifacts + run: | + unzip -o pr_deployment.zip -d ./public/verification/preview + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + if: ${{ github.ref == 'refs/heads/main' }} + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./public diff --git a/.github/workflows/verification-remove.yml b/.github/workflows/verification-remove.yml new file mode 100644 index 0000000000..448f5fbfd7 --- /dev/null +++ b/.github/workflows/verification-remove.yml @@ -0,0 +1,32 @@ +name: Remove closed PR preview + +on: + pull_request: + types: + - closed # this should trigger the CI both for merge and close + +jobs: + remove: + name: Remove PR preview + runs-on: ubuntu-latest + concurrency: + group: gh-pages + + steps: + - name: Download current deployment + uses: actions/checkout@v3 + with: + ref: gh-pages + path: ./public + + - name: Remove Preview for the PR that was just closed + run: | + rm -rf ./public/verification/preview/${{ github.event.number }} + + - name: Redeploy + uses: peaceiris/actions-gh-pages@v3 + if: ${{ github.base_ref == 'main' }} + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./public + commit_message: "Remove the preview of #${{ github.event.number }}" diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index 97fff41eef..0476096d0f 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -102,7 +102,7 @@ jobs: $RV_ROOT/configs/veer.config pytest verification/test.py -v --timeout=480 --html=test.html --md=$GITHUB_STEP_SUMMARY - - name: Pack artifacts + - name: Upload artifacts if: always() uses: actions/upload-artifact@v3 with: @@ -111,3 +111,58 @@ jobs: test.html assets/ sim_build/ + + preview: + name: Preview results on GitHub Actions + runs-on: ubuntu-latest + needs: tests + concurrency: + group: gh-pages + + steps: + - name: Get PR metadata + uses: 8BitJonny/gh-get-current-pr@2.2.0 + if: github.event_name == 'pull_request' + with: + sha: ${{ github.event.pull_request.head.sha }} + id: PR + + - name: Downloads results artifact + uses: actions/download-artifact@v3 + with: + name: results + path: ./results + + - name: Download current release + uses: actions/checkout@v3 + with: + ref: gh-pages + path: ./public + + - name: Prepare results for publishing + run: | + rm -r ./results/sim_build + cp ./results/test.html ./public/verification/index.html + mkdir -p ./public/verification + cp -r ./results/* ./public/verification + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + if: ${{ github.ref == 'refs/heads/main' }} + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./public + + # prepare metadata and upload artifacts for multi branch deployment + - name: Move deployment to the correct preview directory + if: github.event_name == 'pull_request' + run: | + mkdir ./preview + mv ./public/verification ./preview/${{ steps.PR.outputs.number }} + + - name: Upload preview artifacts + uses: actions/upload-artifact@v3 + if: github.event_name == 'pull_request' + with: + name: pr_deployment + path: ./preview/