diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a5defad..d230683 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,11 @@ -# 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] +on: + push: + branches: + - master + pull_request: + branches: + - master jobs: build: @@ -12,19 +13,51 @@ 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/ + path: build/libs/*.jar + + - name: read gradle.properties release flags + id: release_props + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + run: | + SHOULD_RELEASE=$(grep -Po '^shouldRelease=.*' gradle.properties | cut -d= -f2 | xargs) + + if [ "$SHOULD_RELEASE" != "true" ]; then + echo "shouldRelease is false — skipping release" + exit 0 + fi + + MOD_VERSION=$(grep -Po '^modVersion=.*' gradle.properties | cut -d= -f2 | xargs) + + echo "SHOULD_RELEASE=$SHOULD_RELEASE" >> $GITHUB_OUTPUT + echo "MOD_VERSION=$MOD_VERSION" >> $GITHUB_OUTPUT + + - name: create GitHub release + if: steps.release_props.outputs.SHOULD_RELEASE == 'true' + uses: softprops/action-gh-release@v2 + with: + 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 }}