From 97f2dbb57129b69bb0f7b94ba641c9e77efd321d Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:40:09 -0400 Subject: [PATCH] Revamp Workflows for Optimal Productivity (#2112) --- .github/actions/build_setup/action.yml | 15 ++- .github/json/config-latest.json | 22 ++++ .github/json/config.json | 35 ++++++ .github/workflows/auto-build.yml | 66 +++++----- .github/workflows/build-on-push.yml | 19 ++- .github/workflows/changelog.yml | 30 ----- .github/workflows/clean.yml | 4 - .github/workflows/format-java.yml | 11 +- .github/workflows/manage-pr-labels.yml | 16 +-- .github/workflows/publish-on-release.yml | 51 ++++++++ .github/workflows/publish.yml | 142 ++++++++++++++++++++++ .github/workflows/sync.yml | 25 ++++ .github/workflows/update-gradle-cache.yml | 8 +- gradle/scripts/resources.gradle | 2 +- src/main/templates/META-INF/mods.toml | 11 ++ 15 files changed, 351 insertions(+), 106 deletions(-) create mode 100644 .github/json/config-latest.json create mode 100644 .github/json/config.json delete mode 100644 .github/workflows/changelog.yml create mode 100644 .github/workflows/publish-on-release.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/sync.yml diff --git a/.github/actions/build_setup/action.yml b/.github/actions/build_setup/action.yml index 40e38cd7df..a19adcdf6a 100644 --- a/.github/actions/build_setup/action.yml +++ b/.github/actions/build_setup/action.yml @@ -6,20 +6,23 @@ inputs: description: If cache should be updated required: false default: 'false' + ref: + description: 'Ref to checkout' + required: false runs: using: 'composite' - steps: - uses: actions/checkout@v4 with: - submodules: true - - - name: Set up JDK 17 + ref: ${{ inputs.ref || github.ref }} + - name: Set up JDK uses: actions/setup-java@v4 + env: + REF: ${{ inputs.ref || github.ref }} with: - distribution: adopt - java-version: 17 + distribution: temurin + java-version: ${{ contains(env.REF, '1.20.1') && '17' || '21' }} - name: Validate Gradle wrapper uses: gradle/actions/wrapper-validation@v3 diff --git a/.github/json/config-latest.json b/.github/json/config-latest.json new file mode 100644 index 0000000000..39ed43ea07 --- /dev/null +++ b/.github/json/config-latest.json @@ -0,0 +1,22 @@ +{ + "categories": [ + { + "title": "### Added", + "labels": ["type: feature"] + }, + { + "title": "### Fixed", + "labels": ["type: bugfix"] + }, + { + "title": "### Changed", + "labels": ["type: refactor", "type: translation"] + } + ], + "sort": "ASC", + "template": "## Changes\n#{{CHANGELOG}}", + "pr_template": "- #{{TITLE}} by #{{AUTHOR}} in [##{{NUMBER}}](#{{URL}})", + "ignore_labels": ["ignore changelog"], + "max_pull_requests": 1000, + "max_back_track_time_days": 90 +} diff --git a/.github/json/config.json b/.github/json/config.json new file mode 100644 index 0000000000..f1ba8dfe99 --- /dev/null +++ b/.github/json/config.json @@ -0,0 +1,35 @@ +{ + "categories": [ + { + "title": "### Added", + "labels": ["type: feature"] + }, + { + "title": "### Fixed", + "labels": ["type: bugfix"] + }, + { + "title": "### Changed", + "labels": ["type: refactor", "type: translation"] + } + ], + "sort": "ASC", + "template": "## Version [#{{TO_TAG}}](#{{RELEASE_DIFF}})\n#{{CHANGELOG}} ", + "pr_template": "- #{{TITLE}} by #{{AUTHOR}} in [##{{NUMBER}}](#{{URL}})", + "empty_template": "- No changes", + "ignore_labels": ["ignore changelog"], + "tag_resolver": { + "method": "semver", + "filter": { + "pattern": "^(?!v?(1\\.20\\.1-)?[0-9\\.]+$).+$", + "flags": "gu" + }, + "transformer": { + "pattern": "v?([0-9\\.]+-)?([0-9\\.]+)", + "target": "$2" + } + }, + "max_pull_requests": 1000, + "max_back_track_time_days": 90, + "base_branches": ["1.20.1"] +} diff --git a/.github/workflows/auto-build.yml b/.github/workflows/auto-build.yml index fbd05675b6..af2231e3a3 100644 --- a/.github/workflows/auto-build.yml +++ b/.github/workflows/auto-build.yml @@ -1,12 +1,12 @@ -name: auto-build +name: Latest Build on: push: - branches: - - '1.20.1' + branches: ['1.20.1', '1.21'] + paths-ignore: ['.github/**', '**/*.md'] concurrency: - group: auto-build-${{ github.head_ref || github.ref }} + group: auto-build-${{ github.ref }} cancel-in-progress: true jobs: @@ -16,41 +16,45 @@ jobs: MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} MAVEN_USER: ${{ secrets.MAVEN_USER }} SNAPSHOT: true + GITHUB_TOKEN: ${{ github.token }} permissions: contents: write steps: - uses: actions/checkout@v4 - with: - submodules: true - - name: Setup Build uses: ./.github/actions/build_setup - + - name: Get Version + id: ver + run: echo "version=$(./gradlew -q printVersion)" >> $GITHUB_OUTPUT - name: Build run: ./gradlew build --build-cache - - name: Publish to Maven + if: github.repository_owner == 'GregTechCEu' run: ./gradlew publish --build-cache - - - name: Get Version - id: var - run: | - VER=$(./gradlew -q printVersion) - BUILD_VER=$VER-build_${{ github.run_number }} - for jar in ./build/libs/*; do mv "$jar" "${jar/${VER}-SNAPSHOT/${BUILD_VER}-SNAPSHOT}";done 2>/dev/null - echo "version=$BUILD_VER" >> $GITHUB_OUTPUT - - - name: Release - id: release - uses: Kir-Antipov/mc-publish@v3.3.0 + - name: Upload Artifacts + uses: actions/upload-artifact@v4 with: - github-tag: ${{ steps.var.outputs.version }} - github-token: ${{ secrets.GITHUB_TOKEN }} - files: | - build/libs/!(*-@(dev|dev-all|dev-slim|javadoc)).jar - - - name: Print Output - run: | - echo "Release tag: ${{ steps.release.outputs.github-tag }}" - echo "Release URL: ${{ steps.release.outputs.github-url }}" - echo "Released files: ${{ steps.release.outputs.github-files }}" + name: build-artifacts + path: build/libs/* + if-no-files-found: error + retention-days: 90 + - name: Changelog + id: changelog + uses: mikepenz/release-changelog-builder-action@v5 + with: + configuration: ./.github/json/config-latest.json + fromTag: latest-${{ github.ref_name }} + toTag: ${{ github.ref }} + fetchViaCommits: true + failOnError: false + - name: Release Latest + uses: andelf/nightly-release@46e2d5f80828ecc5c2c3c819eb31186a7cf2156c + with: + tag_name: latest-${{ github.ref_name }} + name: '${{ github.ref_name }}-${{ steps.ver.outputs.version}} SNAPSHOT $$' + prerelease: true + body: | + The latest build of GTM for Minecraft ${{ github.ref_name }}. + Please report any [issues](https://github.com/GregTechCEu/GregTech-Modern/issues). + ${{ steps.changelog.outputs.changelog }} + files: build/libs/*.jar \ No newline at end of file diff --git a/.github/workflows/build-on-push.yml b/.github/workflows/build-on-push.yml index cde92e010b..451fc40a64 100644 --- a/.github/workflows/build-on-push.yml +++ b/.github/workflows/build-on-push.yml @@ -4,16 +4,16 @@ on: pull_request: paths: ['**'] +# Cancel previous jobs if PR gets another push +concurrency: + group: PR-build-${{ github.ref }} + cancel-in-progress: true + jobs: build: runs-on: ubuntu-latest - env: - GITHUB_RUN_NUMBER: ${{ vars.GITHUB_RUN_NUMBER }} steps: - uses: actions/checkout@v4 - with: - submodules: true - - name: Check Path Filter uses: dorny/paths-filter@v3 id: filter @@ -21,23 +21,20 @@ jobs: filters: | code: - 'src/**' - - '**.gradle' + - '*.gradle' - 'gradle.properties' - - 'gradlew**' + - 'gradlew*' - 'gradle/**' - - name: Setup Build if: steps.filter.outputs.code == 'true' uses: ./.github/actions/build_setup - - name: Build if: steps.filter.outputs.code == 'true' run: ./gradlew assemble --build-cache - - name: Upload Artifact if: steps.filter.outputs.code == 'true' uses: actions/upload-artifact@v4.0.0 with: name: build output path: build/libs/* - retention-days: 30 + retention-days: 15 diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml deleted file mode 100644 index 674911db19..0000000000 --- a/.github/workflows/changelog.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Generate Changelog - -on: - workflow_dispatch: - inputs: - lastReleaseTag: - description: 'tag of the last full release.' - required: true - type: string - -jobs: - build: - runs-on: ubuntu-latest - env: - MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} - MAVEN_USER: ${{ secrets.MAVEN_USER }} - permissions: - contents: write - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - name: Update CHANGELOG - id: changelog - uses: requarks/changelog-action@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - fromTag: ${{ github.ref_name }} - toTag: ${{ inputs.lastReleaseTag }} diff --git a/.github/workflows/clean.yml b/.github/workflows/clean.yml index c18a35af0a..14745c05e7 100644 --- a/.github/workflows/clean.yml +++ b/.github/workflows/clean.yml @@ -10,13 +10,9 @@ jobs: contents: write steps: - uses: actions/checkout@v4 - with: - submodules: true - - name: Setup Build uses: ./.github/actions/build_setup with: update-cache: true - - name: Clean run: ./gradlew clean --build-cache diff --git a/.github/workflows/format-java.yml b/.github/workflows/format-java.yml index 80962a65c6..44ec187744 100644 --- a/.github/workflows/format-java.yml +++ b/.github/workflows/format-java.yml @@ -3,25 +3,24 @@ name: Java Formatting on: push: - branches: - - '1.20.1' + branches: ['1.20.1', '1.21'] paths: ['src/main/java/**', 'src/test/**'] pull_request: paths: ['**'] concurrency: - group: formatting-${{ github.head_ref || github.ref }} + group: formatting-${{ github.ref }} cancel-in-progress: true jobs: formatting: name: Formatting runs-on: ubuntu-latest - + permissions: + pull-requests: read steps: - name: Checkout Repository uses: actions/checkout@v4 - - name: Check Path Filter uses: dorny/paths-filter@v3 id: filter @@ -30,11 +29,9 @@ jobs: code: - 'src/main/java/**' - 'src/test/**' - - name: Setup Build if: steps.filter.outputs.code == 'true' uses: ./.github/actions/build_setup - - name: Run Spotless Formatting Check with Gradle if: steps.filter.outputs.code == 'true' run: ./gradlew spotlessCheck --warning-mode all --build-cache diff --git a/.github/workflows/manage-pr-labels.yml b/.github/workflows/manage-pr-labels.yml index f396fccdea..5757945724 100644 --- a/.github/workflows/manage-pr-labels.yml +++ b/.github/workflows/manage-pr-labels.yml @@ -1,33 +1,29 @@ # Manages labels on PRs before allowing merging name: Pull Request Labels +# Checks for label once PR has been reviewed on: - pull_request: - types: - - opened - - labeled - - unlabeled - - synchronize + pull_request_review: + types: [submitted] -# if a second commit is pushed quickly after the first, cancel the first one's build concurrency: group: pr-labels-${{ github.head_ref }} cancel-in-progress: true jobs: Labels: + name: On Approval + if: github.event.review.state == 'approved' runs-on: ubuntu-latest - permissions: pull-requests: read # needed to utilize required-labels - steps: - name: Check for Merge-Blocking Labels # blocks merge if present uses: mheap/github-action-required-labels@v5 with: mode: exactly count: 0 - labels: 'status: do not merge' + labels: 'do not merge' exit_type: failure - name: Check for Required Labels # require at least one of these labels diff --git a/.github/workflows/publish-on-release.yml b/.github/workflows/publish-on-release.yml new file mode 100644 index 0000000000..14bed3d65c --- /dev/null +++ b/.github/workflows/publish-on-release.yml @@ -0,0 +1,51 @@ +name: Publish on Release + +on: + release: + types: [released] + +# TODO: Make it so you can publish releases for each mc-ver individually + +jobs: + meta: + name: Metadata + runs-on: ubuntu-latest + outputs: + CHANGELOG: ${{ steps.changelog.outputs.changelog }} + permissions: + contents: write + pull-requests: write + steps: + - name: Generate changelog + id: changelog + env: + GITHUB_TOKEN: ${{ github.token }} + uses: mikepenz/release-changelog-builder-action@v5 + with: + configuration: ./.github/json/config.json + toTag: ${{ github.event.release.tag }} + ignorePreReleases: true + fetchViaCommits: true + failOnError: true + + publish-20: + name: 1.20.1 + needs: [ meta ] + secrets: inherit + uses: ./.github/workflows/publish.yml + with: + simulate: ${{ startsWith(github.event.release.name, 'simulate') || github.repository_owner != 'GregTechCEu' }} + branch: '1.20.1' + tag-name: ${{ github.event.release.tag }} + release-body: ${{ github.event.release.description }} + changelog-body: ${{ needs.meta.outputs.CHANGELOG }} + + publish-21: + name: 1.21.1 + needs: [ meta ] + secrets: inherit + uses: ./.github/workflows/publish.yml + with: + simulate: ${{ startsWith(github.event.release.name, 'simulate') || github.repository_owner != 'GregTechCEu' }} + branch: '1.21' + tag-name: ${{ github.event.release.tag }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000000..be5be01598 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,142 @@ +name: Publish Version + +on: + workflow_call: + inputs: + simulate: + required: false + type: boolean + branch: + description: 'Branch to checkout; 1.20.1 or 1.21' + required: true + type: string + tag-name: + description: 'Tag to upload to' + required: true + type: string + release-body: + description: 'Body for published release notes' + required: false + type: string + changelog-body: + description: 'Body of change notes to insert into CHANGELOG.md' + required: false + type: string + +jobs: + build: + name: Build and Publish to Maven + runs-on: ubuntu-latest + permissions: + contents: write + outputs: + ver: ${{ steps.ver.outputs.version }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} + - name: Setup Build + uses: ./.github/actions/build_setup + with: + ref: ${{ inputs.branch }} + - name: Get Version + id: ver + run: echo "version=$(./gradlew -q printVersion)" >> $GITHUB_OUTPUT + - name: Build + run: ./gradlew assemble --build-cache + - name: Upload Build Artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts-${{ inputs.branch }} + path: build/libs/* + if-no-files-found: error + retention-days: 3 + - name: Publish + if: ${{ !inputs.simulate }} + env: + MAVEN_USER: ${{ secrets.MAVEN_USER }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + run: ./gradlew publish --build-cache + + upload-release-artifacts: + name: Upload Artifacts + needs: build + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifacts-${{ inputs.branch }} + - name: Upload artifacts to release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ inputs.tag-name }} + files: ./!(*-@(dev|dev-all|dev-slim|javadoc)).jar + fail_on_unmatched_files: true + + publish-cf-modrinth: + name: Publish Mod + needs: build + if: ${{ !inputs.simulate }} + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifacts-${{ inputs.branch }} + - name: Publish Mod + env: + MC_VERSION: ${{ inputs.branch == '1.21' && '1.21.1' || '1.20.1' }} + LOADER: ${{ inputs.branch == '1.21' && 'neoforge' || 'forge' }} + JAVA: ${{ inputs.branch == '1.21' && '21' || '17' }} + uses: Kir-Antipov/mc-publish@v3.3.0 + with: + modrinth-id: 7tG215v7 + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + curseforge-id: 890405 + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + files: ./*.jar + name: 'GregTechCEu ${{ env.MC_VERSION }}-${{ needs.build.outputs.ver }}' + version: 'mc${{ env.MC_VERSION }}-${{ needs.build.outputs.ver }}' + version-type: beta + changelog: ${{ inputs.release-body }} + loaders: ${{ env.LOADER }} + java: ${{ env.JAVA }} + fail-mode: fail + + # After successful release, PR version bump and changelog + bump-version-and-changelog: + name: Bump Version and Build Changelog + needs: [ build, upload-release-artifacts, publish-cf-modrinth ] + if: ${{ always() && !failure() && !cancelled() }} + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} + - name: Bump Version + run: | + git config user.name 'github-actions[bot]' + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' + git switch -C gh/release-${{ inputs.branch }} + BUMPED=$(echo ${{ needs.build.outputs.ver }} | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.) + sed -i "s/= ${{ needs.build.outputs.ver }}/= ${BUMPED}/" gradle.properties + git commit -am "Bump version to ${BUMPED}" + - name: Prepend to CHANGELOG + if: inputs.changelog-body + run: | + { head -n 2 CHANGELOG.md; echo -e "${{ inputs.changelog-body }}"; tail -n +3 CHANGELOG.md; } > temp.md && mv temp.md CHANGELOG.md + git commit -am "Updated CHANGELOG" + - name: Push and PR + env: + GH_TOKEN: ${{ github.token }} + run: | + git push --force --set-upstream origin gh/release-${{ inputs.branch }} + gh pr create -B ${{ inputs.branch }} -H gh/release-${{ inputs.branch }} --title "RELEASE for ${{ inputs.branch }}" --body "Created by GH Workflow" --label "ignore changelog" diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 0000000000..633161fae6 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,25 @@ +name: Sync Github Folder + +on: + push: + branches: ['1.20.1'] + paths: ['.github/**'] + +jobs: + sync: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ github.token }} + steps: + - uses: actions/checkout@v4 + with: + ref: '1.21' + - run: | + git config user.name 'github-actions[bot]' + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' + git switch -C gh/workflow-sync + git fetch origin + git checkout origin/1.20.1 -- .github + git commit -am "Sync Workflows" + git push --force --set-upstream origin gh/workflow-sync + gh pr create -B 1.21 -H gh/workflow-sync --title "Sync Workflows with 1.20.1" --body "Created by GH Workflow" --label "ignore changelog" diff --git a/.github/workflows/update-gradle-cache.yml b/.github/workflows/update-gradle-cache.yml index 2c34a06f48..103920ce14 100644 --- a/.github/workflows/update-gradle-cache.yml +++ b/.github/workflows/update-gradle-cache.yml @@ -3,9 +3,8 @@ name: Update Gradle Cache on: push: - branches: - - '1.20.1' - paths: ['gradle/**', '**.gradle', 'gradle.properties', 'gradlew**', 'src/main/resources/accesstransformer.cfg'] + branches: ['1.20.1', '1.21'] + paths: ['gradle/**', '**/*.gradle', 'gradle.properties', 'gradlew*', 'src/main/resources/accesstransformer.cfg'] workflow_dispatch: concurrency: @@ -16,15 +15,12 @@ jobs: update-cache: name: Update Grade Cache runs-on: ubuntu-latest - steps: - name: Checkout Repository uses: actions/checkout@v4 - - name: Setup Build uses: ./.github/actions/build_setup with: update-cache: true - - name: Build Project with Gradle run: ./gradlew assemble --warning-mode all --build-cache diff --git a/gradle/scripts/resources.gradle b/gradle/scripts/resources.gradle index 77b7d60455..7ff46fe72c 100644 --- a/gradle/scripts/resources.gradle +++ b/gradle/scripts/resources.gradle @@ -12,7 +12,7 @@ def mod_issue_tracker = getConfig("mod_issue_tracker") task printVersion { doLast { - println libs.versions.minecraft.get() + "-" + mod_version + println mod_version } } diff --git a/src/main/templates/META-INF/mods.toml b/src/main/templates/META-INF/mods.toml index b6a9c1df9d..c77d25b4bf 100644 --- a/src/main/templates/META-INF/mods.toml +++ b/src/main/templates/META-INF/mods.toml @@ -30,16 +30,27 @@ side = "BOTH" [[dependencies.${mod_id}]] modId = "ldlib" mandatory = true +embedded = true versionRange = "[${ldlib_version},)" ordering = "AFTER" side = "BOTH" +[dependencies.${mod_id}.mc-publish] + ignore = false + modrinth = "ldlib" + curseforge = "ldlib" [[dependencies.${mod_id}]] modId = "configuration" mandatory = true +embedded = true versionRange = "[${configuration_version},)" ordering = "AFTER" side = "BOTH" +[dependencies.${mod_id}.mc-publish] + ignore = false + modrinth = "configuration" + curseforge = "configuration" + [[dependencies.${mod_id}]] modId = "kubejs"