Skip to content

Github Actions - Link Artifacts in PR comments #1

Github Actions - Link Artifacts in PR comments

Github Actions - Link Artifacts in PR comments #1

name: Link PR Artifacts
on:
workflow_run:
workflows: [Upload PR Artifacts]
types:
- completed
jobs:
download:
runs-on: ubuntu-latest
steps:

Check failure on line 12 in .github/workflows/link-PR-artifacts.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/link-PR-artifacts.yml

Invalid workflow file

You have an error in your yaml syntax on line 12
- name: set artifact name
id: set_artifactname
run: |
if [[ "${{ github.REPOSITORY }}" == "emuflight/EmuFlight" ]] ; then
ARTIFACT_NAME="EmuFlight-${{ env.VERSION }}-${{ github.run_number }}"
else
ARTIFACT_NAME="EmuFlight-${{ env.VERSION }}-${{ github.ACTOR }}-${{ github.run_number }}"
fi
echo "${ARTIFACT_NAME}"
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
- 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 == `${ARTIFACT_NAME}`
})[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}/${ARTIFACT_NAME}.zip`, Buffer.from(download.data));
- name: 'Unzip artifact'
run: unzip `${ARTIFACT_NAME}.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(`./${ARTIFACT_NAME}`));
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: "Compiled HEX from this Pull-Request. WARNING: No warranty or guarantee of any kind. Test/Fly at your own risk!"
});