Skip to content

Commit

Permalink
Download artifact by ID, it isn't available in the workflow_run
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Jun 24, 2023
1 parent a78cc51 commit a720fcf
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions .github/workflows/preview-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
runs-on: ubuntu-latest

steps:
# Kinda jank way to grab the PR and run ID
# However, not sure a better way
- name: Grab PR and run ID
# Kinda jank way to grab the PR and run ID and then download the artifact
# TODO: Move this code to our own mini-action
- name: Grab PR & run ID and download the artifact
uses: actions/github-script@v5
with:
script: |
Expand All @@ -38,21 +38,32 @@ jobs:
`\nWORKFLOW_PR_ID=${match[1]}` +
`\nWORKFLOW_RUN_ID=${context.payload.workflow_run.id}`
);
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
require('fs').writeFileSync(`${process.env.GITHUB_WORKSPACE}/preview.zip`, Buffer.from(download.data))
break;
}
}
# Download the artifact from the build workflow
- uses: actions/download-artifact@v3
with:
name: slimefun-${{ env.WORKFLOW_PR_ID }}
# Unzip the artifact
- name: Unzip
run: |
unzip preview.zip
rm preview.zip
mv 'Slimefun v4.9-UNOFFICIAL.jar' preview.jar
- name: Upload to preview service
run: |
curl -v -X POST \
-H 'Authorization: ${{ secrets.PUBLISH_TOKEN }}' \
-H "X-Checksum: $(sha256sum 'target/Slimefun v4.9-UNOFFICIAL.jar' | awk '{print $1}')" \
--data-binary '@target/Slimefun v4.9-UNOFFICIAL.jar' \
-H "X-Checksum: $(sha256sum 'preview.jar' | awk '{print $1}')" \
--data-binary '@preview.jar' \
https://preview-builds.walshy.dev/upload/Slimefun/${{ env.WORKFLOW_PR_ID }}/${{ env.WORKFLOW_RUN_ID }}
- name: Post comment
Expand Down

0 comments on commit a720fcf

Please sign in to comment.