-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI workflow that publishes GH Releases
Releases are published by setting `draft=false` We need to set the `title` too, because modpublisher will have set a build-specific title (e.g. `[Fabric] Freecam 1.2.3 for MC 1.20.4`).
- Loading branch information
1 parent
c59ffc0
commit a8332f4
Showing
1 changed file
with
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# This CI workflow marks the draft release as "published". | ||
# If there is no draft yet the run will fail (and can be re-run later) | ||
name: Publish GitHub Release | ||
|
||
on: | ||
push: | ||
# Only release tags on the main branch | ||
branches: | ||
- 'main' | ||
tags: | ||
- 'v*' # e.g. v1.2.3 | ||
- '!v*\+mc*' # exclude tags handled by publish.yaml | ||
|
||
# Only allow running one build job at a time to optimise cache hits | ||
concurrency: | ||
group: builds | ||
|
||
# Grant permission to create/update releases | ||
permissions: | ||
contents: write | ||
|
||
env: | ||
TAG: ${{ github.ref_name }} | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- name: Check release exists | ||
run: | | ||
# Lookup a release using this tag: | ||
# Print stdout to `response` and stderr to `errors` | ||
if gh api /repos/{owner}/{repo}/releases/tags/"$TAG" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
1> response 2> errors | ||
then | ||
# API request returned OK, double check the response's tag_name | ||
if [[ "$(jq '.tag_name' < response)" == "$TAG" ]]; then | ||
# Found a release: | ||
echo "Found a release with a tag_name matching \"$TAG\"" | ||
else | ||
echo "Error: response returned the wrong tag!" >& 2 | ||
cat response >& 2 | ||
exit 2 | ||
fi | ||
else | ||
# Double check we got a "Not Found" response | ||
msg="$(jq '.message' < response)" | ||
if [[ "$msg" == "Not Found" ]]; then | ||
echo "Release not found for \"$TAG\"" | ||
exit 1 | ||
else | ||
echo "Error getting GitHub Release:" >& 2 | ||
[[ -n "$msg" ]] && echo "Error: $msg" | ||
cat errors >& 2 | ||
exit 2 | ||
fi | ||
fi | ||
# Publish the release by setting draft=false | ||
# Also ensure the release title is correct | ||
- name: Publish release | ||
run: | | ||
gh release edit "$TAG" \ | ||
--title="Freecam ${TAG#v}" \ | ||
--draft="false" |