1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00
Slimefun4/.github/workflows/preview-builds.yml

83 lines
2.9 KiB
YAML
Raw Normal View History

2023-06-21 20:34:37 +00:00
name: Preview builds
on:
2023-06-24 10:40:22 +00:00
workflow_run:
2023-07-07 07:47:41 +00:00
workflows: ["Pull Request"]
2023-06-24 10:40:22 +00:00
types:
- completed
2023-06-21 20:34:37 +00:00
permissions:
2023-06-24 11:09:25 +00:00
contents: read
2023-06-21 20:34:37 +00:00
pull-requests: write
jobs:
preview:
2023-06-24 10:40:22 +00:00
if: ${{ github.repository_owner == 'Slimefun' && github.event.workflow_run.conclusion == 'success' }}
2023-06-21 20:34:37 +00:00
name: Build and Publish the jar
runs-on: ubuntu-latest
steps:
2023-07-07 07:47:41 +00:00
# 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@v7
2023-06-21 20:34:37 +00:00
with:
2023-06-24 10:40:22 +00:00
script: |
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
2023-06-21 20:34:37 +00:00
2023-06-24 10:40:22 +00:00
for (const artifact of allArtifacts.data.artifacts) {
2023-07-07 07:47:41 +00:00
// Extract the PR number and commit hash from the artifact name
const match = /^slimefun-(\d+)-([a-f0-9]{8})$/.exec(artifact.name);
2023-06-24 10:40:22 +00:00
if (match) {
require("fs").appendFileSync(
process.env.GITHUB_ENV,
2023-07-07 07:47:41 +00:00
`\nPR_NUMBER=${match[1]}` +
`\nCOMMIT_HASH=${match[2]}`
2023-06-24 10:40:22 +00:00
);
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))
2023-06-24 10:40:22 +00:00
break;
}
}
2023-06-21 20:34:37 +00:00
# Unzip the artifact
- name: Unzip
run: |
unzip preview.zip
rm preview.zip
2023-07-07 08:36:42 +00:00
mv 'Slimefun vPreview Build #${{ env.PR_NUMBER }}-${{ env.COMMIT_HASH }}.jar' preview.jar
2023-06-21 20:34:37 +00:00
- name: Upload to preview service
run: |
curl -X POST \
2023-06-21 20:34:37 +00:00
-H 'Authorization: ${{ secrets.PUBLISH_TOKEN }}' \
-H "X-Checksum: $(sha256sum 'preview.jar' | awk '{print $1}')" \
--data-binary '@preview.jar' \
2023-07-07 07:47:41 +00:00
https://preview-builds.walshy.dev/upload/Slimefun/${{ env.PR_NUMBER }}/${{ env.COMMIT_HASH }}
2023-06-21 20:34:37 +00:00
- name: Post comment
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ env.PR_NUMBER }}
2023-06-21 20:34:37 +00:00
message: |
2023-06-24 11:09:25 +00:00
### Slimefun preview build
A Slimefun preview build is available for testing!
2023-07-07 07:47:41 +00:00
Commit: ${{ env.COMMIT_HASH }}
2023-06-21 20:34:37 +00:00
https://preview-builds.walshy.dev/download/Slimefun/${{ env.PR_NUMBER }}/${{ env.COMMIT_HASH }}
2023-06-21 20:34:37 +00:00
2023-06-24 11:09:25 +00:00
> **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!