WR Add Pull Request Instructions #197
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: WR Add Pull Request Instructions | |
on: | |
workflow_run: | |
workflows: ["Add Pull Request Instructions"] | |
types: [completed] | |
jobs: | |
Last-Workflow-Success: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Download artifact | |
uses: actions/github-script@v4 | |
with: | |
script: | | |
// Retrieve metadata about the artifacts of the last workflow | |
// https://octokit.github.io/rest.js/v18#actions-list-workflow-run-artifacts | |
const artifacts = await github.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.payload.workflow_run.id, | |
}); | |
const artifactData = artifacts.data.artifacts[0] | |
// Download artifact with GET API | |
// https://octokit.github.io/rest.js/v18#actions-download-artifact | |
var download = await github.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: artifactData.id, | |
archive_format: 'zip', | |
}); | |
const fs = require('fs'); | |
fs.writeFileSync('${{github.workspace}}/artifact.zip', Buffer.from(download.data)); | |
- run: unzip artifact.zip | |
- uses: actions/github-script@v4 | |
id: artifact | |
with: | |
script: | | |
// Retrieve pull request and issue number from downloaded artifact | |
const fs = require('fs') | |
const artifact = fs.readFileSync('artifact.txt') | |
const artifactJSON = JSON.parse(artifact); | |
return artifactJSON | |
- uses: actions/checkout@v4 | |
# Create the message to post | |
- name: Post Comment | |
uses: actions/github-script@v4 | |
with: | |
script: | | |
const artifact = ${{ steps.artifact.outputs.result }}; | |
const script = require('./github-actions/pr-instructions/post-comment.js') | |
script({g: github, c: context}, artifact) | |
Last-Workflow-Failure: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'failure' }} | |
steps: | |
- name: Failed Run | |
run: echo "The previous GitHub Action failed. Please check the logs for the previous action." |