|
| 1 | +name: Run Label Action on PR Review Event |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["Dummy Workflow on review"] |
| 5 | + types: |
| 6 | + - completed |
| 7 | +permissions: |
| 8 | + pull-requests: write |
| 9 | + contents: write |
| 10 | + issues: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + run_on_workflow_a_success: |
| 14 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Run this on Dummy workflow success |
| 18 | + run: echo "Dummy Workflow on review completes successfully" |
| 19 | + download_context_artifact: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: 'Download artifact' |
| 23 | + uses: actions/github-script@v7 |
| 24 | + with: |
| 25 | + script: | |
| 26 | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 27 | + owner: context.repo.owner, |
| 28 | + repo: context.repo.repo, |
| 29 | + run_id: context.payload.workflow_run.id, |
| 30 | + }); |
| 31 | +
|
| 32 | + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { |
| 33 | + return artifact.name == "context.json" |
| 34 | + })[0]; |
| 35 | +
|
| 36 | + let download = await github.rest.actions.downloadArtifact({ |
| 37 | + owner: context.repo.owner, |
| 38 | + repo: context.repo.repo, |
| 39 | + artifact_id: matchArtifact.id, |
| 40 | + archive_format: 'zip', |
| 41 | + }); |
| 42 | +
|
| 43 | + let fs = require('fs'); |
| 44 | + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/context.zip`, Buffer.from(download.data)); |
| 45 | +
|
| 46 | + - name: 'Unzip artifact' |
| 47 | + run: unzip context.zip |
| 48 | + - name: 'Return Parsed JSON' |
| 49 | + uses: actions/github-script@v7 |
| 50 | + id: return-parsed-json |
| 51 | + with: |
| 52 | + script: | |
| 53 | + let fs = require('fs'); |
| 54 | + let data = fs.readFileSync('./context.json'); |
| 55 | + return JSON.parse(data); |
| 56 | + outputs: |
| 57 | + pr_num: ${{fromJSON(steps.return-parsed-json.outputs.result).pr_num}} |
| 58 | + event_action: ${{fromJSON(steps.return-parsed-json.outputs.result).event_action}} |
| 59 | + review_state: ${{fromJSON(steps.return-parsed-json.outputs.result).review_state}} |
| 60 | + event_name: ${{fromJSON(steps.return-parsed-json.outputs.result).event_name}} |
| 61 | + comment_body: ${{fromJSON(steps.return-parsed-json.outputs.result).comment_body}} |
| 62 | + review_comment_body: ${{fromJSON(steps.return-parsed-json.outputs.result).review_comment_body}} |
| 63 | + user_login: ${{fromJSON(steps.return-parsed-json.outputs.result).user_login}} |
| 64 | + action: ${{fromJSON(steps.return-parsed-json.outputs.result).action}} |
| 65 | + log_context_values: |
| 66 | + needs: |
| 67 | + - download_context_artifact |
| 68 | + runs-on: ubuntu-latest |
| 69 | + steps: |
| 70 | + - name: 'Set all Env Variable' |
| 71 | + run: | |
| 72 | + echo "GITHUB_PR_NUMBER=${{ needs.download_context_artifact.outputs.pr_num }}" >> "$GITHUB_ENV" |
| 73 | + echo "GITHUB_EVENT_ACTION=${{ needs.download_context_artifact.outputs.event_action }}" >> "$GITHUB_ENV" |
| 74 | + echo "GITHUB_EVENT_REVIEW_STATE=${{ needs.download_context_artifact.outputs.review_state }}" >> "$GITHUB_ENV" |
| 75 | + echo "GITHUB_EVENT_NAME=${{ needs.download_context_artifact.outputs.event_name }}" >> "$GITHUB_ENV" |
| 76 | + echo "COMMENT_BODY=${{ needs.download_context_artifact.outputs.comment_body }}" >> "$GITHUB_ENV" |
| 77 | + echo "REVIEW_COMMENT_BODY=${{ needs.download_context_artifact.outputs.review_comment_body }}" >> "$GITHUB_ENV" |
| 78 | + echo "GITHUB_USER_LOGIN=${{ needs.download_context_artifact.outputs.user_login }}" >> "$GITHUB_ENV" |
| 79 | + echo "ACTION=${{ needs.download_context_artifact.outputs.action }}" >> "$GITHUB_ENV" |
| 80 | + - uses: actions/checkout@v4 |
| 81 | + |
| 82 | + - name: Install uv |
| 83 | + uses: astral-sh/setup-uv@v5 |
| 84 | + - name: 'Run add-remove-labels action' |
| 85 | + env: |
| 86 | + GITHUB_TOKEN: ${{ secrets.OPENDATAHUB_TESTS_BOT_PAT }} |
| 87 | + GITHUB_EVENT_NAME: ${{ needs.download_context_artifact.outputs.event_name }} |
| 88 | + run: uv run python .github/workflows/scripts/pr_workflow.py |
0 commit comments