-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3863 from J3fftw1/feature/preview-builds
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Preview builds | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Java CI"] | ||
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 run ID | ||
# However, not sure a better way | ||
- name: Grab PR and run ID | ||
uses: actions/github-script@v5 | ||
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 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}` | ||
); | ||
break; | ||
} | ||
} | ||
# Download the artifact from the build workflow | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: slimefun-${{ env.WORKFLOW_PR_ID }} | ||
|
||
- 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' \ | ||
https://preview-builds.walshy.dev/upload/Slimefun/${{ env.WORKFLOW_PR_ID }}/${{ env.WORKFLOW_RUN_ID }} | ||
- name: Post comment | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
number: ${{ env.WORKFLOW_PR_ID }} | ||
message: | | ||
### Slimefun preview build | ||
A Slimefun preview build is available for testing! | ||
https://preview-builds.walshy.dev/download/Slimefun/${{ env.WORKFLOW_PR_ID }}/${{ env.WORKFLOW_RUN_ID }} | ||
> **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! |