-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplifies the download of report to use job syntax #568
Changes from all commits
5170cdf
5807cdc
7d61833
48858af
ccdf74c
4ebee2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,59 +9,76 @@ on: | |
workflows: ["Workflow Unit tests"] | ||
types: [completed] | ||
|
||
permissions: | ||
# Needed to add and delete comments on a PRs | ||
pull-requests: write | ||
|
||
env: | ||
ARTIFACT_NAME: "report" | ||
|
||
jobs: | ||
filter-artifacts: | ||
name: Filter Artifacts | ||
setup-env: | ||
name: Setup environment | ||
runs-on: ubuntu-24.04 | ||
if: github.event.workflow_run.event == 'pull_request' | ||
outputs: | ||
artifacts: ${{ fromJson(steps.filter-artifacts.outputs.result) }} | ||
IS_PR: ${{ steps.call.outputs.IS_PR || steps.run.outputs.IS_PR }} | ||
ORG: ${{ steps.call.outputs.ORG || steps.run.outputs.ORG }} | ||
REPO: ${{ steps.call.outputs.REPO || steps.run.outputs.REPO }} | ||
RUN_ID: ${{ steps.call.outputs.RUN_ID || steps.run.outputs.RUN_ID }} | ||
REPO_FULL_NAME: ${{ steps.call.outputs.REPO_FULL_NAME || steps.run.outputs.REPO_FULL_NAME }} | ||
SHA: ${{ steps.call.outputs.SHA || steps.run.outputs.SHA }} | ||
steps: | ||
- uses: actions/checkout@v4.2.2 | ||
- id: filter-artifacts | ||
name: Filter test report artifacts | ||
uses: actions/github-script@v7.0.1 | ||
with: | ||
script: | | ||
const fs = require('fs'); | ||
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | ||
owner: context.payload.workflow_run.repository.owner.login, | ||
repo: context.payload.workflow_run.repository.name, | ||
run_id: ${{ github.event.workflow_run.id }}, | ||
}); | ||
const zips = artifacts.data.artifacts.flatMap(artifact => | ||
artifact.name.startsWith('${{ env.ARTIFACT_NAME }}-')? [artifact.name] : [] | ||
); | ||
return JSON.stringify(zips); | ||
- name: Workflow call setup from a Pull Request | ||
id: call | ||
if: github.event_name == 'pull_request' | ||
run: | | ||
echo "Setting up from a workflow call" | ||
echo "RUN_ID=${{ github.run_id }}" >> $GITHUB_OUTPUT | ||
REPO_FULL_NAME="${{ github.repository }}" | ||
parts=(${REPO_FULL_NAME//\// }) | ||
echo "ORG=${parts[0]}" >> $GITHUB_OUTPUT | ||
echo "REPO=${parts[1]}" >> $GITHUB_OUTPUT | ||
echo "SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT | ||
echo "IS_PR=${{ github.event_name == 'pull_request' }}" >> $GITHUB_OUTPUT | ||
- name: Workflow run setup | ||
id: run | ||
if: github.event_name == 'workflow_run' | ||
run: | | ||
echo "RUN_ID=${{ github.event.workflow_run.id }}" >> $GITHUB_OUTPUT | ||
echo "ORG=${{ github.event.workflow_run.organization.login }}" >> $GITHUB_OUTPUT | ||
echo "REPO=${{ github.event.workflow_run.repository.name }}" >> $GITHUB_OUTPUT | ||
echo "REPO_FULL_NAME=${{ github.event.workflow_run.repository.full_name }}" >> $GITHUB_OUTPUT | ||
echo "SHA=${{ github.event.workflow_run.head_sha }}" >> $GITHUB_OUTPUT | ||
echo "IS_PR=${{ github.event.workflow_run.event == 'pull_request' }}" >> $GITHUB_OUTPUT | ||
|
||
comment-on-prs: | ||
name: Comment on PRs | ||
runs-on: ubuntu-24.04 | ||
needs: filter-artifacts | ||
if: github.event.workflow_run.event == 'pull_request' && needs.filter-artifacts.outputs.artifacts != '[]' | ||
strategy: | ||
matrix: | ||
artifact: ${{fromJson(needs.filter-artifacts.outputs.artifacts)}} | ||
needs: setup-env | ||
if: ${{ needs.setup-env.outputs.IS_PR }} | ||
steps: | ||
- name: Download artifact | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v4.1.8 | ||
with: | ||
repository: ${{ github.event.workflow_run.repository.name }} | ||
run-id: ${{ github.event.workflow_run.id }} | ||
name: ${{ matrix.artifact }} | ||
repository: ${{ needs.setup-env.outputs.REPO_FULL_NAME }} | ||
run-id: ${{ needs.setup-env.outputs.RUN_ID }} | ||
pattern: "${{ env.ARTIFACT_NAME }}-*" | ||
- name: Comment on PR | ||
uses: actions/github-script@v7.0.1 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const fs = require('fs'); | ||
const comments = JSON.parse(fs.readFileSync('${{ env.ARTIFACT_NAME }}.json')); | ||
const owner = context.payload.workflow_run.repository.owner.login; | ||
const repo = context.payload.workflow_run.repository.name; | ||
const sha = context.payload.workflow_run.head_sha | ||
const artifact = '${{ env.ARTIFACT_NAME }}'; | ||
const owner = '${{ needs.setup-env.outputs.ORG }}'; | ||
const repo = '${{ needs.setup-env.outputs.REPO }}'; | ||
const sha = '${{ needs.setup-env.outputs.SHA }}'; | ||
const header = `## Test results for commit ${sha}\n\n`; | ||
const comments = fs.readdirSync('.') | ||
.filter(d => fs.statSync(d).isDirectory() && d.startsWith(`${artifact}-`)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. find any directory starting with |
||
.map(dir => `${dir}/${artifact}.json`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. within that directory find a |
||
.filter(fs.existsSync) | ||
.flatMap(filePath => JSON.parse(fs.readFileSync(filePath, 'utf8'))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the report contains a list of strings, so we need to use |
||
|
||
const pull = (await github.rest.pulls.list({ | ||
owner: owner, | ||
|
@@ -74,7 +91,7 @@ jobs: | |
owner: owner, | ||
repo: repo, | ||
issue_number: issue_number, | ||
header + body, | ||
body: (header + body), | ||
}); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat! we don't need this!!