diff --git a/.github/workflows/gradle.build.yaml b/.github/workflows/gradle.build.yaml index 49303e8..2747de2 100644 --- a/.github/workflows/gradle.build.yaml +++ b/.github/workflows/gradle.build.yaml @@ -23,11 +23,33 @@ permissions: contents: read jobs: + generate-build-information: + name: "Generate build information" + runs-on: ubuntu-latest + outputs: + branch_suffix: ${{ steps.computeBranchSuffix.outputs.branch_suffix }} + steps: + - id: computeBranchSuffix + name: "🔢 Compute branch suffix" + run: | + gitRef="${{ github.ref }}" + branchName=$(echo "${gitRef/refs\/heads\//}") + echo "Branch name: $branchName" + + cleanedBranchName=$(echo $branchName | sed 's/[^a-zA-Z0-9]/-/g') + echo "Cleaned branch name: $cleanedBranchName" + + echo "branch_suffix=$cleanedBranchName" >> "$GITHUB_OUTPUT" + compute-version: + needs: [ "generate-build-information" ] uses: ./.github/workflows/gradle.version.yaml + with: + suffix: ${{ needs.generate-build-information.outputs.branch_suffix }} build: needs: [ "compute-version" ] + name: "🏗️ Build" runs-on: ubuntu-latest steps: - id: checkout @@ -46,18 +68,6 @@ jobs: gradle-version: wrapper cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} - - id: computeBranchSuffix - name: "🔢 Compute branch suffix" - run: | - gitRef="${{ github.ref }}" - branchName=$(echo "${gitRef/refs\/heads\//}") - echo "Branch name: $branchName" - - cleanedBranchName=$(echo $branchName | sed 's/[^a-zA-Z0-9]/-/g') - echo "Cleaned branch name: $cleanedBranchName" - - echo "branch_suffix=$cleanedBranchName" >> "$GITHUB_OUTPUT" - - id: build name: "🏗️ Build" - run: ./gradlew --build-cache ${{ inputs.gradle_tasks }} -PmodVersion=${{ needs.compute-version.outputs.version }} -PmodVersionSuffix=${{ steps.computeBranchSuffix.outputs.branch_suffix }} + run: ./gradlew --build-cache ${{ inputs.gradle_tasks }} -PmodVersion=${{ needs.compute-version.outputs.mod_version }} -PmodVersionSuffix=${{ needs.compute_version.outputs.suffix }} diff --git a/.github/workflows/gradle.prerelease.yaml b/.github/workflows/gradle.prerelease.yaml index 6c9f4c7..17ac73a 100644 --- a/.github/workflows/gradle.prerelease.yaml +++ b/.github/workflows/gradle.prerelease.yaml @@ -29,6 +29,8 @@ permissions: jobs: compute-version: uses: ./.github/workflows/gradle.version.yaml + with: + suffix: rc gradle: needs: [ "compute-version" ] @@ -55,7 +57,7 @@ jobs: - id: build name: "🏗️ Build" - run: ./gradlew --build-cache ${{ inputs.gradle_tasks }} -PmodVersion=${{ needs.compute-version.outputs.version }} -PmodVersionSuffix=rc + run: ./gradlew --build-cache ${{ inputs.gradle_tasks }} -PmodVersion=${{ needs.compute-version.outputs.mod_version }} -PmodVersionSuffix=${{ needs.compute-version.outputs.suffix }} env: GITHUB_TOKEN: ${{ github.token }} GITHUB_REPOSITORY: ${{ github.repository }} diff --git a/.github/workflows/gradle.publish.yaml b/.github/workflows/gradle.publish.yaml index 429022e..e843b9a 100644 --- a/.github/workflows/gradle.publish.yaml +++ b/.github/workflows/gradle.publish.yaml @@ -44,8 +44,29 @@ permissions: statuses: write jobs: + generate-release-information: + name: "Generate release information" + runs-on: ubuntu-latest + outputs: + release_version_suffix: ${{ steps.generateReleaseSuffix.outputs.release_version_suffix }} + steps: + - id: generateReleaseSuffix + name: "Generate release suffix" + run: | + release_version_suffix="alpha" + if [[ ${{ inputs.curse_release_type }} == release ]]; then + release_version_suffix="" + elif [[ ${{ inputs.curse_release_type }} == beta ]]; then + release_version_suffix="snapshot" + fi + echo "Release version suffix: ${release_version_suffix}" + echo "release_version_suffix=${release_version_suffix}" >> "$GITHUB_OUTPUT" + compute-version: + needs: [ "generate-release-information" ] uses: ./.github/workflows/gradle.version.yaml + with: + suffix: ${{ needs.generate-release-information.outputs.release_version_suffix }} notify-build-start: needs: [ "compute-version" ] @@ -57,7 +78,7 @@ jobs: with: webhook_url: ${{ secrets.DISCORD_WEBHOOK }} status: 'started' - version: "${{ needs.compute-version.outputs.version }}" + version: "${{ needs.compute-version.outputs.full_version }}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -67,7 +88,7 @@ jobs: authToken: ${{secrets.GITHUB_TOKEN}} context: 'Publishing' state: 'pending' - description: "Version: ${{ needs.compute-version.outputs.version }}" + description: ${{ needs.compute-version.outputs.release_text }} target_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} gradle: @@ -99,9 +120,9 @@ jobs: run: | git config --global user.name "GitHub Actions" git config --global user.email "maintainer+github@ldtteam.com" - git tag -a ${{ needs.compute-version.outputs.version }} -m "Version ${{ needs.compute-version.outputs.version }}" + git tag -a "${{ needs.compute-version.outputs.tag_version }}" -m "${{ needs.compute-version.outputs.release_text }}" - - id: generate-release-changelog + - id: generateReleaseChangelog name: "📝 Generate release changelog" uses: heinrichreimer/action-github-changelog-generator@v2.4 with: @@ -109,23 +130,13 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} stripGeneratorNotice: "true" onlyLastTag: true + dueTag: ${{ needs.compute-version.outputs.tag_version }} + excludeTagsRegex: ${{ needs.compute-version.outputs.tag_regex }} maxIssues: ${{ inputs.changelog_max_issues }} - - id: generate-release-suffix - name: "Generate release suffix" - run: | - release_version_suffix="alpha" - if [[ ${{ inputs.curse_release_type }} == release ]]; then - release_version_suffix="" - elif [[ ${{ inputs.curse_release_type }} == beta ]]; then - release_version_suffix="snapshot" - fi - echo "Release version suffix: ${release_version_suffix}" - echo "release_version_suffix=${release_version_suffix}" >> "$GITHUB_OUTPUT" - - id: publish name: "🚀 Publish" - run: ./gradlew --build-cache ${{ inputs.gradle_tasks }} -PmodVersion=${{ needs.compute-version.outputs.version }} -PmodVersionSuffix=${{ steps.generate-release-suffix.outputs.release_version_suffix }} + run: ./gradlew --build-cache ${{ inputs.gradle_tasks }} -PmodVersion=${{ needs.compute-version.outputs.mod_version }} -PmodVersionSuffix=${{ needs.compute-version.outputs.suffix }} env: LDTTeamJfrogUsername: ${{ secrets.MAVEN_USER }} LDTTeamJfrogPassword: ${{ secrets.MAVEN_PASSWORD }} @@ -138,14 +149,14 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ needs.compute-version.outputs.version }} - release_name: "Release ${{ needs.compute-version.outputs.version }}" + tag_name: ${{ needs.compute-version.outputs.tag_version }} + release_name: ${{ needs.compute-version.outputs.release_text }} body_path: changelog.md prerelease: ${{ inputs.curse_release_type != 'release' }} notify-build-end: - name: Build notifications (end) needs: [ "compute-version", "notify-build-start", "gradle" ] + name: "🔴 Build notifications (end)" if: ${{ always() }} runs-on: ubuntu-latest steps: @@ -154,7 +165,7 @@ jobs: with: webhook_url: ${{ secrets.DISCORD_WEBHOOK }} status: ${{ needs.gradle.result }} - version: "${{ needs.compute-version.outputs.version }}" + version: "${{ needs.compute-version.outputs.full_version }}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: neoforged/action-github-status@v1 @@ -163,5 +174,5 @@ jobs: authToken: ${{ secrets.GITHUB_TOKEN }} context: 'Publishing' state: ${{ needs.gradle.result }} - description: "Version: ${{ needs.compute-version.outputs.version }}" + description: ${{ needs.compute-version.outputs.release_text }} target_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} diff --git a/.github/workflows/gradle.version.yaml b/.github/workflows/gradle.version.yaml index 8f66cb6..e4dd783 100644 --- a/.github/workflows/gradle.version.yaml +++ b/.github/workflows/gradle.version.yaml @@ -2,10 +2,32 @@ name: Common Version Determination CI on: workflow_call: + inputs: + suffix: + description: "The release suffix" + type: string outputs: - version: - description: "The computed version" - value: ${{ jobs.compute-version.outputs.version }} + minecraft_version: + description: "The minecraft version" + value: ${{ jobs.compute-version.outputs.minecraft_version }} + mod_version: + description: "The mod version" + value: ${{ jobs.compute-version.outputs.mod_version }} + suffix: + description: "The input suffix" + value: ${{ inputs.suffix }} + full_version: + description: "The full version string" + value: ${{ jobs.compute-version.outputs.full_version }} + tag_version: + description: "The version that the tag should get" + value: ${{ jobs.compute-version.outputs.tag_version }} + tag_regex: + description: "The regex for matching identical version tags" + value: ${{ jobs.compute-version.outputs.tag_regex }} + release_text: + description: "The text for the release version" + value: ${{ jobs.compute-version.outputs.release_text }} permissions: contents: read @@ -14,21 +36,63 @@ jobs: compute-version: runs-on: ubuntu-latest outputs: - version: ${{ steps.version.outputs.version }} + minecraft_version: ${{ steps.generateMinecraftVersion.outputs.minecraft_version }} + mod_version: ${{ steps.generateModVersion.outputs.version }} + full_version: ${{ steps.generateFullVersion.outputs.full_version }} + tag_version: ${{ steps.generateTagVersion.outputs.tag_version }} + tag_regex: ${{ steps.generateTagRegex.outputs.tag_regex }} + release_text: ${{ steps.generateReleaseText.outputs.release_text }} steps: - id: checkout name: "📦 Checkout" uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1000 fetch-tags: true - - id: version - name: "🔢 Compute version" + - id: generateMinecraftVersion + name: "Generate Minecraft version" + run: | + cat gradle.properties | grep exactMinecraftVersion | cut -d "=" -f 2 > minecraft_version.txt + echo "Minecraft version: $(cat minecraft_version.txt)" + echo "minecraft_version=$(cat minecraft_version.txt)" >> "$GITHUB_OUTPUT" + + - id: generateModVersion + name: "Generate mod version" uses: PaulHatch/semantic-version@v5.4.0 with: - tag_prefix: "v" + tag_prefix: "v${{ steps.generateMinecraftVersion.outputs.minecraft_version }}-" search_commit_body: true debug: true bump_each_commit: true - version_format: "${major}.${minor}.${patch}" \ No newline at end of file + version_format: "${major}.${minor}.${patch}" + + - id: generateFullVersion + name: "Generate full version" + run: | + full_version="${{ steps.generateModVersion.outputs.version }}-${{ steps.generateMinecraftVersion.outputs.minecraft_version }}-${{ inputs.suffix }}" + echo "Full version: ${full_version}" + echo "full_version=${full_version}" >> "$GITHUB_OUTPUT" + + - id: generateTagVersion + name: "Generate tag version" + run: | + tag_version="v${{ steps.generateMinecraftVersion.outputs.minecraft_version }}-${{ steps.generateModVersion.outputs.version }}" + echo "Tag version: ${tag_version}" + echo "tag_version=${tag_version}" >> "$GITHUB_OUTPUT" + + - id: generateTagRegex + name: "Generate tag version regex" + run: | + echo -n "^(?!v" > tag_regex.txt + echo -n "${{ steps.generateMinecraftVersion.outputs.minecraft_version }}" | sed "s|\.|\\\\.|g" >> tag_regex.txt + echo -n ").+$" >> tag_regex.txt + echo "Tag version regex: $(cat tag_regex.txt)" + echo "tag_regex=$(cat tag_regex.txt)" >> "$GITHUB_ENV" + + - id: generateReleaseText + name: "Generate release text" + run: | + release_text="Version ${{ steps.generateModVersion.outputs.version }} for Minecraft ${{ steps.generateMinecraftVersion.outputs.minecraft_version }}" + echo "Release text: ${release_text}" + echo "release_text=${release_text}" >> "$GITHUB_OUTPUT" \ No newline at end of file