Skip to content

Preview builds

Preview builds #324

name: Preview builds
on:
workflow_run:
workflows: ["Pull Request"]
types:
- completed
permissions:
contents: read
pull-requests: write
jobs:
preview:
if: ${{ github.repository_owner == 'Slimefun' && github.event.workflow_run.conclusion == 'success' }}
name: Build and Publish the jar
runs-on: ubuntu-latest
steps:
# Kinda jank way to grab the PR and commit hash 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@v6
with:
script: |
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
for (const artifact of allArtifacts.data.artifacts) {
// Extract the PR number and commit hash from the artifact name
const match = /^slimefun-(\d+)-([a-f0-9]{8})$/.exec(artifact.name);
if (match) {
require("fs").appendFileSync(
process.env.GITHUB_ENV,
`\nPR_NUMBER=${match[1]}` +
`\nCOMMIT_HASH=${match[2]}`
);
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;
}
}
# Unzip the artifact
- name: Unzip
run: |
unzip preview.zip
rm preview.zip
mv 'Slimefun vPreview Build #${{ env.PR_NUMBER }}-${{ env.COMMIT_HASH }}.jar' preview.jar
- name: Upload to preview service
run: |
curl -X POST \
-H 'Authorization: ${{ secrets.PUBLISH_TOKEN }}' \
-H "X-Checksum: $(sha256sum 'preview.jar' | awk '{print $1}')" \
--data-binary '@preview.jar' \
https://preview-builds.walshy.dev/upload/Slimefun/${{ env.PR_NUMBER }}/${{ env.COMMIT_HASH }}
- name: Post comment
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ env.PR_NUMBER }}
message: |
### Slimefun preview build
A Slimefun preview build is available for testing!
Commit: ${{ env.COMMIT_HASH }}
https://preview-builds.walshy.dev/download/Slimefun/${{ env.PR_NUMBER }}/${{ env.COMMIT_HASH }}
> **Note**: This is not a supported build and is only here for the purposes of testing.
> Do not run this on a live server and do not report bugs anywhere but this PR!