From 155f01e6320c9fb673db6ef77e1c3610e901d37a Mon Sep 17 00:00:00 2001 From: Thom van den Akker Date: Wed, 21 Aug 2024 22:20:23 +0200 Subject: [PATCH] Reuse version workflow --- .github/workflows/gradle.build.yaml | 12 ++++- .github/workflows/gradle.prerelease.yaml | 41 +--------------- .github/workflows/gradle.publish.yaml | 37 ++------------ .github/workflows/gradle.version.yaml | 61 ++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 73 deletions(-) create mode 100644 .github/workflows/gradle.version.yaml diff --git a/.github/workflows/gradle.build.yaml b/.github/workflows/gradle.build.yaml index 6f173c7..e1931a6 100644 --- a/.github/workflows/gradle.build.yaml +++ b/.github/workflows/gradle.build.yaml @@ -23,6 +23,14 @@ permissions: contents: read jobs: + compute-version: + name: Compute version + runs-on: ubuntu-latest + steps: + - uses: ldtteam/operapublicacreator/.github/workflows/gradle.version.yaml@${{ github.workflow_sha }} + with: + suffix: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || format('branch-{0}', steps.computeBranchSuffix.outputs.branch_suffix) }} + build: runs-on: ubuntu-latest steps: @@ -39,4 +47,6 @@ jobs: - id: build name: "🏗️ Build" - run: ./gradlew --build-cache ${{ inputs.gradle_tasks }} \ No newline at end of file + run: ./gradlew --build-cache ${{ inputs.gradle_tasks }} + env: + Version: "${{ needs.compute-version.outputs.version }}" \ No newline at end of file diff --git a/.github/workflows/gradle.prerelease.yaml b/.github/workflows/gradle.prerelease.yaml index 7bda61c..1197ab7 100644 --- a/.github/workflows/gradle.prerelease.yaml +++ b/.github/workflows/gradle.prerelease.yaml @@ -28,47 +28,10 @@ jobs: compute-version: name: Compute version runs-on: ubuntu-latest - outputs: - version: ${{ steps.version.outputs.version }} - version_tag: ${{ steps.version.outputs.version_tag }} - minecraft_version: ${{ steps.minecraftVersion.outputs.minecraft_version }} steps: - - id: checkout - name: "📦 Checkout" - uses: actions/checkout@v4 - with: - fetch-depth: 0 - fetch-tags: true - - - id: minecraftVersion - name: "📦 Extract 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: computeBranchSuffix - name: "🔢 Compute branch suffix" - if: github.event_name == 'push' - 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: version - name: "🔢 Compute version" - uses: PaulHatch/semantic-version@v5.4.0 + - uses: ldtteam/operapublicacreator/.github/workflows/gradle.version.yaml@${{ github.workflow_sha }} with: - tag_prefix: "v" - search_commit_body: true - debug: true - bump_each_commit: true - version_format: "${major}.${minor}.${patch}-${{ steps.minecraftVersion.outputs.minecraft_version }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || format('branch-{0}', steps.computeBranchSuffix.outputs.branch_suffix) }}" + suffix: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || format('branch-{0}', steps.computeBranchSuffix.outputs.branch_suffix) }} gradle: needs: [ "compute-version" ] # Make sure we now the version before starting to build diff --git a/.github/workflows/gradle.publish.yaml b/.github/workflows/gradle.publish.yaml index cbfd512..5ae2559 100644 --- a/.github/workflows/gradle.publish.yaml +++ b/.github/workflows/gradle.publish.yaml @@ -24,22 +24,17 @@ on: required: false type: number default: 100 - secrets: DISCORD_WEBHOOK: required: true - MAVEN_USER: required: true MAVEN_PASSWORD: required: true - CURSE_API_KEY: required: true - CROWDIN_API_KEY: required: true - GRADLE_ENCRYPTION_KEY: required: true @@ -51,37 +46,13 @@ jobs: compute-version: name: Compute version runs-on: ubuntu-latest - outputs: - version: ${{ steps.version.outputs.version }} - version_tag: ${{ steps.version.outputs.version_tag }} - minecraft_version: ${{ steps.minecraftVersion.outputs.minecraft_version }} steps: - - id: checkout - name: "📦 Checkout" - uses: actions/checkout@v4 - with: - fetch-depth: 0 - fetch-tags: true - - - id: minecraftVersion - name: "📦 Extract 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: version - name: "🔢 Compute version" - uses: PaulHatch/semantic-version@v5.4.0 + - uses: ldtteam/operapublicacreator/.github/workflows/gradle.version.yaml@${{ github.workflow_sha }} with: - tag_prefix: "v" - search_commit_body: true - debug: true - bump_each_commit: true - version_format: "${major}.${minor}.${patch}-${{ steps.minecraftVersion.outputs.minecraft_version }}-${{ inputs.curse_release_type }}" + suffix: ${{ inputs.curse_release_type }} notify-build-start: - needs: ["compute-version"] + needs: [ "compute-version" ] name: "🔴 Build notifications (start)" runs-on: ubuntu-latest steps: @@ -104,7 +75,7 @@ jobs: target_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} gradle: - needs: ["compute-version"] # Make sure we now the version before starting to build + needs: [ "compute-version" ] # Make sure we now the version before starting to build runs-on: ubuntu-latest steps: - id: checkout diff --git a/.github/workflows/gradle.version.yaml b/.github/workflows/gradle.version.yaml new file mode 100644 index 0000000..b6f5ff2 --- /dev/null +++ b/.github/workflows/gradle.version.yaml @@ -0,0 +1,61 @@ +name: Common Version Determination CI + +on: + workflow_call: + inputs: + suffix: + description: "The suffix to finish the version string with" + required: false + type: string + default: "" + outputs: + version: ${{ jobs.compute-version.outputs.version }} + minecraft_version: ${{ jobs.compute-version.outputs.minecraft_version }} + +permissions: + contents: read + +jobs: + compute-version: + name: Compute version + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + minecraft_version: ${{ steps.minecraftVersion.outputs.minecraft_version }} + steps: + - id: checkout + name: "📦 Checkout" + uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - id: minecraftVersion + name: "📦 Extract 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: computeBranchSuffix + name: "🔢 Compute branch suffix" + if: github.event_name == 'push' + 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: version + name: "🔢 Compute version" + uses: PaulHatch/semantic-version@v5.4.0 + with: + tag_prefix: "v" + search_commit_body: true + debug: true + bump_each_commit: true + version_format: "${major}.${minor}.${patch}-${{ steps.minecraftVersion.outputs.minecraft_version }}-${{ inputs.suffix }}" \ No newline at end of file