Publish End to End Tests Results #50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish End to End Tests Results | |
on: | |
workflow_run: | |
workflows: | |
- End to End Tests | |
types: | |
- completed | |
defaults: | |
run: | |
shell: bash -exuo pipefail {0} | |
concurrency: | |
cancel-in-progress: false | |
group: publish-e2e-results | |
jobs: | |
find-pr: | |
name: Find source pull request number | |
runs-on: ubuntu-22.04 | |
if: github.event.workflow_run.event == 'pull_request' | |
permissions: | |
actions: read | |
outputs: | |
number: ${{ steps.extract.outputs.pr }} | |
steps: | |
- name: Download metadata artifact | |
uses: actions/download-artifact@v4 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
name: metadata | |
run-id: ${{github.event.workflow_run.id }} | |
- name: Extract PR number | |
id: extract | |
run: echo "pr=$(jq '.pr.number' < workflow-metadata.json)" >> "$GITHUB_OUTPUT" | |
upload: | |
name: Publish | |
runs-on: ubuntu-22.04 | |
if: github.event.workflow_run.event == 'pull_request' && (github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure') | |
permissions: | |
actions: read | |
id-token: write | |
outputs: | |
failed: ${{ steps.extract-statistics.outputs.failed }} | |
flaky: ${{ steps.extract-statistics.outputs.flaky }} | |
skipped: ${{ steps.extract-statistics.outputs.skipped }} | |
passed: ${{ steps.extract-statistics.outputs.passed }} | |
tests: ${{ steps.extract-statistics.outputs.tests }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: Setup Google Cloud SDK | |
uses: google-github-actions/auth@v2 | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
workload_identity_provider: projects/${{ secrets.GCP_PROJECT_NUMBER }}/locations/global/workloadIdentityPools/github-actions/providers/github-oidc | |
- name: Download artifact | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id }}, | |
}); | |
var e2eArtifact = artifacts.data.artifacts.filter(artifact => artifact.name == "e2e-test-results")[0]; | |
var download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: e2eArtifact.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
if (!fs.existsSync('${{github.workspace}}/hack')) { | |
fs.mkdirSync('${{github.workspace}}/hack', { recursive: true }); | |
} | |
fs.writeFileSync('${{github.workspace}}/hack/e2e-test-results.zip', Buffer.from(download.data)); | |
- run: | | |
unzip e2e-test-results.zip | |
rm -f e2e-test-results.zip | |
working-directory: hack | |
- name: Upload artifact | |
uses: google-github-actions/upload-cloud-storage@v2 | |
with: | |
process_gcloudignore: 'false' | |
path: ./hack/ | |
parent: false | |
destination: arikkfir-static-website/github/greenstar/${{ github.event.workflow_run.id }}/${{ github.event.workflow_run.run_attempt }}/ | |
- name: Extract statistics | |
id: extract-statistics | |
run: | | |
echo "failed=$(jq '.summary.failed.value' < hack/index.json)" >> "$GITHUB_OUTPUT" | |
echo "flaky=$(jq '.summary.flaky.value' < hack/index.json)" >> "$GITHUB_OUTPUT" | |
echo "skipped=$(jq '.summary.skipped.value' < hack/index.json)" >> "$GITHUB_OUTPUT" | |
echo "passed=$(jq '.summary.passed.value' < hack/index.json)" >> "$GITHUB_OUTPUT" | |
echo "tests=$(jq '.summary.tests.value' < hack/index.json)" >> "$GITHUB_OUTPUT" | |
find-or-create-status-comment: | |
name: Find or create status comment | |
needs: [find-pr, upload] | |
runs-on: ubuntu-22.04 | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Comment on PR | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ needs.find-pr.outputs.number }} | |
body: | | |
### ${{ needs.upload.outputs.failed == '0' && ':rocket:' || ':bangbang:' }} End-to-end tests ${{ needs.upload.outputs.failed == '0' && 'passed' || 'failed' }}! | |
| Result | Count | | |
|--------------------------------|------------------------------------------| | |
| :x: **Failed** | [${{ needs.upload.outputs.failed }}][1] | | |
| :interrobang: **Flaky** | [${{ needs.upload.outputs.flaky }}][2] | | |
| :heavy_minus_sign: **Skipped** | [${{ needs.upload.outputs.skipped }}][3] | | |
| :white_check_mark: **Passed** | [${{ needs.upload.outputs.passed }}][4] | | |
| **Total** | [${{ needs.upload.outputs.tests }}][5] | | |
[1]: https://static.kfirs.com/github/greenstar/${{ github.event.workflow_run.id }}/${{ github.event.workflow_run.run_attempt }}/index.html#caseType=failed | |
[2]: https://static.kfirs.com/github/greenstar/${{ github.event.workflow_run.id }}/${{ github.event.workflow_run.run_attempt }}/index.html#caseType=flaky | |
[3]: https://static.kfirs.com/github/greenstar/${{ github.event.workflow_run.id }}/${{ github.event.workflow_run.run_attempt }}/index.html#caseType=skipped | |
[4]: https://static.kfirs.com/github/greenstar/${{ github.event.workflow_run.id }}/${{ github.event.workflow_run.run_attempt }}/index.html#caseType=passed | |
[5]: https://static.kfirs.com/github/greenstar/${{ github.event.workflow_run.id }}/${{ github.event.workflow_run.run_attempt }}/index.html |