Skip to content

Commit

Permalink
Github Actions - Link Artifacts in PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdCopter committed Feb 21, 2024
1 parent 123b796 commit 4e21381
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ jobs:
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
continue-on-error: true

- name: Make artifact name
id: make_artifactname
- name: set artifact name
id: set_artifactname
run: |
if [[ "${{ github.REPOSITORY }}" == "emuflight/EmuFlight" ]] ; then
ARTIFACT_NAME="EmuFlight-${{ env.VERSION }}-${{ github.run_number }}"
Expand Down
19 changes: 15 additions & 4 deletions .github/workflows/link-PR-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ jobs:
download:
runs-on: ubuntu-latest
steps:
- 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:
Expand All @@ -20,7 +31,7 @@ jobs:
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "PR_ARTIFACTS"
return artifact.name == `${ARTIFACT_NAME}`
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
Expand All @@ -29,18 +40,18 @@ jobs:
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/PR_ARTIFACTS.zip`, Buffer.from(download.data));
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${ARTIFACT_NAME}.zip`, Buffer.from(download.data));
- name: 'Unzip artifact'
run: unzip PR_ARTIFACTS.zip
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('./PR_ARTIFACTS'));
let issue_number = Number(fs.readFileSync(`./${ARTIFACT_NAME}`));
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down

0 comments on commit 4e21381

Please sign in to comment.