On Run Create Jira for Flaky Test #2
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: On Run Create Jira for Flaky Test | |
on: | |
workflow_run: | |
workflows: [On PR Open or Push Do Build and Test] | |
types: [completed] | |
jobs: | |
jiraForFlakyTest: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
name: Downloading Flaky test report | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install xmlstarlet tool | |
# xmlstarlet is needed by bin/jira/track_flaky_tests.sh | |
shell: bash | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y xmlstarlet | |
# Downloading flaky artifact containing | |
# zip file with flaky test reports and file | |
# containing PR target branch | |
- name: Download artifact | |
id: download-artifact | |
uses: actions/github-script@v7 | |
with: | |
result-encoding: string | |
script: | | |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.payload.workflow_run.id, | |
}); | |
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "flaky-test-report" | |
})[0]; | |
if (typeof matchArtifact == 'undefined') { | |
// No flaky test artifact found | |
return "No Flaky"; | |
} | |
let download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
let fs = require('fs'); | |
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/flaky-test-report.zip`, Buffer.from(download.data)); | |
return "Flaky Found"; | |
- if: steps.download-artifact.outputs.result == 'Flaky Found' | |
name: Unzip artifact | |
run: unzip flaky-test-report.zip | |
- if: steps.download-artifact.outputs.result == 'Flaky Found' | |
name: Create Jira | |
env: | |
TOKEN: ${{ secrets.JIRA_API_TOKEN }} | |
RUNNER_DEBUG: 1 | |
FLAKY_TEST_GLOB: "**/target/*-reports*/**/TEST-*FLAKY.xml" | |
PROJECT_KEY: "ISPN" | |
TYPE: "Bug" | |
JENKINS_JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow.id }}" | |
run: | | |
set +e | |
cat target-branch.txt | |
TARGET_BRANCH=$(cat target-branch.txt) bin/jira/track_flaky_tests.sh | |
true | |
- if: steps.download-artifact.outputs.result == 'Flaky Found' | |
name: Get event name | |
id: event_name | |
uses: juliangruber/read-file-action@v1 | |
with: | |
path: ./event-name.txt | |
- if: steps.download-artifact.outputs.result == 'Flaky Found' | |
name: Get PR number | |
id: pr_number | |
uses: juliangruber/read-file-action@v1 | |
with: | |
path: ./event-number.txt | |
- if: > | |
steps.download-artifact.outputs.result == 'Flaky Found' && | |
steps.event_name.outputs.content == 'pull_request' | |
name: Comment PR | |
uses: ./.github/actions/comment-pr-flaky-test | |
with: | |
pr_number: ${{ steps.pr_number.outputs.content }} | |