Comment on the pull request #891
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: Comment on the pull request | |
on: | |
workflow_run: | |
workflows: ["Receive PR"] | |
types: | |
- completed | |
jobs: | |
upload: | |
runs-on: ubuntu-latest | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' | |
outputs: | |
PR_NR: ${{ steps.step1.outputs.test }} | |
steps: | |
- name: 'Download artifact' | |
uses: actions/github-script@v6 | |
with: | |
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 == "pr_number" | |
})[0]; | |
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}/pr_number.zip`, Buffer.from(download.data)); | |
- name: 'Unzip artifact' | |
run: unzip pr_number.zip | |
- name: 'Comment on PR' | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
let fs = require('fs'); | |
let issue_number = Number(fs.readFileSync('./pr_number')); | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: 'Thank you for the PR!' | |
}); | |
- id: step1 | |
run: echo "test=$(< ./pr_number)" >> "$GITHUB_OUTPUT" | |
push: | |
needs: upload | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: 'Trigger Workflow' | |
run: | | |
curl -s -X POST \ | |
--fail \ | |
-F token=${{ secrets.CB_PIPELINE }} \ | |
-F "ref=pt20" \ | |
-F "variables[PR]=${{ needs.upload.outputs.PR_NR }}" \ | |
https://codebase.helmholtz.cloud/api/v4/projects/7605/trigger/pipeline -o /dev/null |