From d042ea57b54b77f4d361fd4fd9dbdab6daab1aa2 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 19 Jan 2026 10:10:54 +0100 Subject: [PATCH 1/4] feat: Automatic releases --- .github/workflows/build.yml | 75 ++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a5defad..e51380b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,8 +1,3 @@ -# Automatically build the project and run any configured tests for every push -# and submitted pull request. This can help catch issues that only occur on -# certain platforms or Java versions, and provides a first line of defence -# against bad commits. - name: build on: [pull_request, push] @@ -12,19 +7,89 @@ jobs: steps: - name: checkout repository uses: actions/checkout@v4 + - name: validate gradle wrapper uses: gradle/actions/wrapper-validation@v4 + - name: setup jdk uses: actions/setup-java@v4 with: java-version: '21' distribution: 'microsoft' + - name: make gradle wrapper executable run: chmod +x ./gradlew + - name: build run: ./gradlew build + - name: capture build artifacts uses: actions/upload-artifact@v4 with: name: Artifacts path: build/libs/ + + release: + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + runs-on: ubuntu-24.04 + needs: build + permissions: + contents: write + steps: + - name: checkout repository + uses: actions/checkout@v4 + + - name: read modVersion from gradle.properties + id: props + uses: BrycensRanch/read-properties-action@v1 + with: + file: gradle.properties + property: modVersion + + - name: download build artifacts from build job + uses: actions/download-artifact@v4 + with: + name: Artifacts + path: dist + + - name: decide release type + tag + id: rel + env: + GH_TOKEN: ${{ github.token }} + MOD_VERSION: ${{ steps.props.outputs.value }} + REPO: ${{ github.repository }} + run: | + set -euo pipefail + + version_tag="v${MOD_VERSION}" + + # Get latest release tag (empty if none) + latest_tag="$(curl -sS -H "Authorization: Bearer $GH_TOKEN" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/${REPO}/releases/latest" \ + | jq -r '.tag_name // empty' || true)" + + prerelease=false + tag="$version_tag" + name="$version_tag" + + # If latest release already matches this version, make a beta pre-release + if [ "$latest_tag" = "$version_tag" ]; then + prerelease=true + tag="${version_tag}-beta.${GITHUB_RUN_NUMBER}" + name="${version_tag} beta ${GITHUB_RUN_NUMBER}" + fi + + echo "tag=$tag" >> "$GITHUB_OUTPUT" + echo "name=$name" >> "$GITHUB_OUTPUT" + echo "prerelease=$prerelease" >> "$GITHUB_OUTPUT" + + - name: create GitHub release + upload jars + uses: ncipollo/release-action@v1 + with: + tag: ${{ steps.rel.outputs.tag }} + name: ${{ steps.rel.outputs.name }} + prerelease: ${{ steps.rel.outputs.prerelease }} + artifacts: "dist/*" + allowUpdates: true + replacesArtifacts: true From 3741b820e7157bef8e715f0aaeed31211c20c636 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 19 Jan 2026 10:31:21 +0100 Subject: [PATCH 2/4] fix: improved counting logic for workflow --- .github/workflows/build.yml | 42 ++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e51380b..ec0ae8a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,7 +52,7 @@ jobs: name: Artifacts path: dist - - name: decide release type + tag + - name: decide release type + tag (version-scoped beta counter) id: rel env: GH_TOKEN: ${{ github.token }} @@ -63,27 +63,39 @@ jobs: version_tag="v${MOD_VERSION}" - # Get latest release tag (empty if none) - latest_tag="$(curl -sS -H "Authorization: Bearer $GH_TOKEN" \ + # List releases and extract tag_name values + tags="$(curl -sS -H "Authorization: Bearer $GH_TOKEN" \ -H "Accept: application/vnd.github+json" \ - "https://api.github.com/repos/${REPO}/releases/latest" \ - | jq -r '.tag_name // empty' || true)" - - prerelease=false - tag="$version_tag" - name="$version_tag" - - # If latest release already matches this version, make a beta pre-release - if [ "$latest_tag" = "$version_tag" ]; then + "https://api.github.com/repos/${REPO}/releases?per_page=100" \ + | jq -r '.[].tag_name' || true)" + + # If a full release with vX.Y.Z already exists -> create next beta for that version + if echo "$tags" | grep -qx "$version_tag"; then + # Count existing betas for this exact version: vX.Y.Z-beta.N + n="$(echo "$tags" \ + | grep -E "^${version_tag}-beta\.[0-9]+$" \ + | sed -E "s/^${version_tag}-beta\.//" \ + | sort -n \ + | tail -n 1 || true)" + + if [ -z "${n:-}" ]; then + next=1 + else + next=$((n + 1)) + fi + + tag="${version_tag}-beta.${next}" + name="${version_tag}-beta.${next}" prerelease=true - tag="${version_tag}-beta.${GITHUB_RUN_NUMBER}" - name="${version_tag} beta ${GITHUB_RUN_NUMBER}" + else + tag="$version_tag" + name="$version_tag" + prerelease=false fi echo "tag=$tag" >> "$GITHUB_OUTPUT" echo "name=$name" >> "$GITHUB_OUTPUT" echo "prerelease=$prerelease" >> "$GITHUB_OUTPUT" - - name: create GitHub release + upload jars uses: ncipollo/release-action@v1 with: From a673c727aa2bd0d5af4edd077cb13db8e39bfe10 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 19 Jan 2026 10:38:22 +0100 Subject: [PATCH 3/4] fix: made it so pr's no longer build twice (once for push, once for pr) --- .github/workflows/build.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ec0ae8a..60bda07 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,11 @@ name: build -on: [pull_request, push] +on: + push: + branches: + - master + pull_request: + branches: + - master jobs: build: From a99ac272859a2598452b88fdd6b38d5f7afa9bec Mon Sep 17 00:00:00 2001 From: Nathan <209938737+quiteboring@users.noreply.github.com> Date: Fri, 23 Jan 2026 13:41:30 -0500 Subject: [PATCH 4/4] feat: better github release --- .github/workflows/build.yml | 94 +++++++++---------------------------- 1 file changed, 22 insertions(+), 72 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 60bda07..d230683 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,81 +33,31 @@ jobs: uses: actions/upload-artifact@v4 with: name: Artifacts - path: build/libs/ - - release: - if: github.event_name == 'push' && github.ref == 'refs/heads/master' - runs-on: ubuntu-24.04 - needs: build - permissions: - contents: write - steps: - - name: checkout repository - uses: actions/checkout@v4 - - - name: read modVersion from gradle.properties - id: props - uses: BrycensRanch/read-properties-action@v1 - with: - file: gradle.properties - property: modVersion - - - name: download build artifacts from build job - uses: actions/download-artifact@v4 - with: - name: Artifacts - path: dist - - - name: decide release type + tag (version-scoped beta counter) - id: rel - env: - GH_TOKEN: ${{ github.token }} - MOD_VERSION: ${{ steps.props.outputs.value }} - REPO: ${{ github.repository }} + path: build/libs/*.jar + + - name: read gradle.properties release flags + id: release_props + if: github.event_name == 'push' && github.ref == 'refs/heads/master' run: | - set -euo pipefail - - version_tag="v${MOD_VERSION}" + SHOULD_RELEASE=$(grep -Po '^shouldRelease=.*' gradle.properties | cut -d= -f2 | xargs) - # List releases and extract tag_name values - tags="$(curl -sS -H "Authorization: Bearer $GH_TOKEN" \ - -H "Accept: application/vnd.github+json" \ - "https://api.github.com/repos/${REPO}/releases?per_page=100" \ - | jq -r '.[].tag_name' || true)" - - # If a full release with vX.Y.Z already exists -> create next beta for that version - if echo "$tags" | grep -qx "$version_tag"; then - # Count existing betas for this exact version: vX.Y.Z-beta.N - n="$(echo "$tags" \ - | grep -E "^${version_tag}-beta\.[0-9]+$" \ - | sed -E "s/^${version_tag}-beta\.//" \ - | sort -n \ - | tail -n 1 || true)" + if [ "$SHOULD_RELEASE" != "true" ]; then + echo "shouldRelease is false — skipping release" + exit 0 + fi - if [ -z "${n:-}" ]; then - next=1 - else - next=$((n + 1)) - fi + MOD_VERSION=$(grep -Po '^modVersion=.*' gradle.properties | cut -d= -f2 | xargs) - tag="${version_tag}-beta.${next}" - name="${version_tag}-beta.${next}" - prerelease=true - else - tag="$version_tag" - name="$version_tag" - prerelease=false - fi + echo "SHOULD_RELEASE=$SHOULD_RELEASE" >> $GITHUB_OUTPUT + echo "MOD_VERSION=$MOD_VERSION" >> $GITHUB_OUTPUT - echo "tag=$tag" >> "$GITHUB_OUTPUT" - echo "name=$name" >> "$GITHUB_OUTPUT" - echo "prerelease=$prerelease" >> "$GITHUB_OUTPUT" - - name: create GitHub release + upload jars - uses: ncipollo/release-action@v1 + - name: create GitHub release + if: steps.release_props.outputs.SHOULD_RELEASE == 'true' + uses: softprops/action-gh-release@v2 with: - tag: ${{ steps.rel.outputs.tag }} - name: ${{ steps.rel.outputs.name }} - prerelease: ${{ steps.rel.outputs.prerelease }} - artifacts: "dist/*" - allowUpdates: true - replacesArtifacts: true + tag_name: v${{ steps.release_props.outputs.MOD_VERSION }} + name: Cobalt ${{ steps.release_props.outputs.MOD_VERSION }} + files: build/libs/*.jar + body: ${{ github.event.head_commit.message }} + env: + GITHUB_TOKEN: ${{ github.token }}