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

82 lines
2.8 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:
workflows: ["Java CI"]
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:
# 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
2023-06-24 10:40:22 +00:00
uses: actions/github-script@v5
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) {
// Extract the PR number from the artifact name
const match = /^slimefun-(\d+)$/.exec(artifact.name);
if (match) {
require("fs").appendFileSync(
process.env.GITHUB_ENV,
`\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))
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
mv 'Slimefun v4.9-UNOFFICIAL.jar' preview.jar
2023-06-21 20:34:37 +00:00
- name: Upload to preview service
run: |
2023-06-24 10:10:51 +00:00
curl -v -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-06-24 10:40:22 +00:00
https://preview-builds.walshy.dev/upload/Slimefun/${{ env.WORKFLOW_PR_ID }}/${{ env.WORKFLOW_RUN_ID }}
2023-06-21 20:34:37 +00:00
- name: Post comment
uses: marocchino/sticky-pull-request-comment@v2
with:
2023-06-24 11:09:25 +00:00
number: ${{ env.WORKFLOW_PR_ID }}
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-06-21 20:34:37 +00:00
2023-06-24 10:40:22 +00:00
https://preview-builds.walshy.dev/download/Slimefun/${{ env.WORKFLOW_PR_ID }}/${{ env.WORKFLOW_RUN_ID }}
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!