Skip to content

Commit

Permalink
Publish unit test logs to GitHub Pages
Browse files Browse the repository at this point in the history
Signed-off-by: Rafal Kolucki <[email protected]>
  • Loading branch information
koluckirafal committed Apr 12, 2023
1 parent a82cfc1 commit 452d597
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 1 deletion.
55 changes: 55 additions & 0 deletions .github/workflows/verification-deploy.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
32 changes: 32 additions & 0 deletions .github/workflows/verification-remove.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
57 changes: 56 additions & 1 deletion .github/workflows/verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
$RV_ROOT/configs/veer.config
pytest verification/test.py -v --timeout=480 --html=test.html --html=$GITHUB_STEP_SUMMARY
- name: Pack artifacts
- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v3
with:
Expand All @@ -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/[email protected]
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
mv ./results/test.html ./results/index.html
mkdir -p ./public/verification
mv ./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/

0 comments on commit 452d597

Please sign in to comment.