diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 81f2748..562d834 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,12 +11,14 @@ jobs: build: runs-on: ubuntu-latest permissions: - contents: read + contents: write packages: write steps: - name: Checkout Code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up JDK 21 uses: actions/setup-java@v4 @@ -29,6 +31,15 @@ jobs: chmod +x gradlew sed -i 's/\r$//' gradlew + # Added step to check project-iteration from gradle.properties + - name: Check Iteration + id: check_iteration + run: | + ITERATION=$(grep 'project-iteration=' gradle.properties | cut -d'=' -f2) + VERSION=$(grep 'project-version=' gradle.properties | cut -d'=' -f2) + echo "iteration=$ITERATION" >> $GITHUB_OUTPUT + echo "version=$VERSION" >> $GITHUB_OUTPUT + # 4a. Build (Test Only) # Run this ONLY for Pull Requests. - name: Build (Test Only) @@ -39,8 +50,10 @@ jobs: # 4b. Build & Publish (DEV) # Run this for 'push to master' (creates -DEV builds) + # Logic: Run if (push OR PR) AND NOT a tag AND iteration != 0 - name: Publish Dev Build - if: ${{ (github.event_name == 'push' || github.event_name == 'pull_request') && !startsWith(github.ref, 'refs/tags/') }} + id: publish_dev + if: ${{ (github.event_name == 'push' || github.event_name == 'pull_request') && !startsWith(github.ref, 'refs/tags/') && steps.check_iteration.outputs.iteration != '0' }} run: ./gradlew clean build publish env: BUILD_NUMBER: ${{ github.run_number }} @@ -48,16 +61,29 @@ jobs: USER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 4c. Build & Publish (RELEASE) - # Run this ONLY when a tag (v*) is pushed. + # Run ONLY when code is pushed/merged to master AND iteration != 0 + # UPDATED: Added requirement for step 4b (publish_dev) to finish successfully. - name: Publish Release - if: ${{ startsWith(github.ref, 'refs/tags/') }} + id: publish_release + if: ${{ steps.publish_dev.outcome == 'success' && github.event_name == 'push' && github.ref == 'refs/heads/master' && steps.check_iteration.outputs.iteration != '0' }} run: ./gradlew clean build publish env: - # We pass the tag name (e.g., v2026.0.0) to Gradle - RELEASE_VERSION: ${{ github.ref_name }} + # We pass the branch name (master) to Gradle + RELEASE_VERSION: ${{ steps.check_iteration.outputs.version }} USER_GITHUB_NAME: ${{ github.actor }} USER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # 4d. Auto Create Tag + # Automatically creates a git tag after successful 4c publish. + - name: Create Git Tag + if: ${{ steps.publish_release.outcome == 'success' }} + run: | + TAG_NAME="v${{ steps.check_iteration.outputs.version }}" + git tag $TAG_NAME + git push origin $TAG_NAME + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload Build Artifacts uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/build_monthly.yml b/.github/workflows/build_monthly.yml index 2698927..b04b812 100644 --- a/.github/workflows/build_monthly.yml +++ b/.github/workflows/build_monthly.yml @@ -57,8 +57,8 @@ jobs: # 1. Update Version (e.g., 2026.0.2) sed -i "s/^project-version=.*/project-version=$NEW_VERSION/" gradle.properties - # 2. Reset Iteration to 1 (So next dev build starts at 1) - sed -i "s/^project-iteration=.*/project-iteration=1/" gradle.properties + # 2. Reset Iteration to 0 (So next dev build starts at 0) + sed -i "s/^project-iteration=.*/project-iteration=0/" gradle.properties # Verify grep "project-version" gradle.properties diff --git a/gradle.properties b/gradle.properties index b60224e..95e1126 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,10 @@ git-org-repository=mcextension # --- Artifact Identity --- project-version=2026.0.2 -project-iteration=1 +project-iteration=2 project-group=io.github.mcengine project-artifact-id=mcextension project-artifact-name=MCExtension project-artifact-description=This project is a library designed to allow Minecraft plugins to load their own extensions. project-artifact-url=https://mcengine.github.io/mcextension-website +