diff --git a/.github/actions/build_setup/action.yml b/.github/actions/build_setup/action.yml new file mode 100644 index 00000000..7d53a2db --- /dev/null +++ b/.github/actions/build_setup/action.yml @@ -0,0 +1,30 @@ +name: Build Setup +description: Setup for standard Java builds + +inputs: + update-cache: + description: If cache should be updated + required: false + default: false + +runs: + using: 'composite' + + steps: + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 17 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + cache-write-only: ${{ inputs.update-cache }} + generate-job-summary: false + gradle-home-cache-includes: | + caches + caches/retro_futura_gradle + notifications + jdks + wrapper diff --git a/.github/workflows/format_java.yml b/.github/workflows/format_java.yml new file mode 100644 index 00000000..a838fb89 --- /dev/null +++ b/.github/workflows/format_java.yml @@ -0,0 +1,27 @@ +# Runs formatting requirements +name: Java Formatting + +on: + push: + branches: + - master + pull_request: + +concurrency: + group: formatting-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + formatting: + name: Formatting + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup Build + uses: ./.github/actions/build_setup + + - name: Run Spotless Formatting Check with Gradle + run: ./gradlew spotlessCheck --warning-mode all --build-cache diff --git a/.github/workflows/manage_pr_labels.yml b/.github/workflows/manage_pr_labels.yml new file mode 100644 index 00000000..7dcddd62 --- /dev/null +++ b/.github/workflows/manage_pr_labels.yml @@ -0,0 +1,39 @@ +# Manages labels on PRs before allowing merging +name: Pull Request Labels + +on: + pull_request: + types: + - opened + - labeled + - unlabeled + - synchronize + +# 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: + 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' + exit_type: failure + + - name: Check for Required Labels # require at least one of these labels + uses: mheap/github-action-required-labels@v5 + with: + mode: minimum + count: 1 + labels: 'type: feature, type: bug, type: refactor, type: translation, ignore changelog' + exit_type: failure diff --git a/.github/workflows/pr_artifact.yml b/.github/workflows/pr_artifact.yml deleted file mode 100644 index 32e72a65..00000000 --- a/.github/workflows/pr_artifact.yml +++ /dev/null @@ -1,77 +0,0 @@ -# Creates a built artifact jar for appropriately labeled Pull Requests -name: PR Artifact - -on: - pull_request: - types: - - labeled - - synchronize - -# if a second commit is pushed quickly after the first, cancel the first one's build -concurrency: - group: build-artifact-${{github.head_ref}} - cancel-in-progress: true - -env: - ARTIFACT_NAME: 'gcym-dev' - NOTIFICATION_BODY: | - This Pull Request has automatic artifact deployment enabled. Download the latest build [here](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}), and extract the contents. - -jobs: - Build_Artifact: - if: contains(github.event.pull_request.labels.*.name, format('deployment{0} artifact', ':')) - runs-on: ubuntu-latest - - permissions: - pull-requests: write # needed to make a comment - contents: read # needed to check out the repo if defining other permissions - - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - - name: Setup Java - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '8' - - - name: Build Project - uses: gradle/gradle-build-action@v2 - with: - arguments: 'build --build-cache --no-daemon ' # disable daemon since only one gradle operation will happen - generate-job-summary: false - gradle-home-cache-includes: | - caches - jdks - notifications - wrapper - - - name: Determine Artifact Name - id: artifact_name - run: | - FILE=(build/libs/*) - echo "artifact_name=${FILE[0]}" >> $GITHUB_OUTPUT - - - name: Publish Artifact - uses: actions/upload-artifact@v3 - with: - name: "${{env.ARTIFACT_NAME}}-${{github.head_ref}}-${{github.sha}}" - path: "${{steps.artifact_name.outputs.artifact_name}}" - if-no-files-found: error - - - name: Find Existing Comment - uses: peter-evans/find-comment@v2 - id: find-existing - with: - issue-number: ${{github.event.pull_request.number}} - comment-author: 'github-actions[bot]' - body-includes: 'Download the latest build [here]' - - - name: Create or Update Artifact Publish Notification - uses: peter-evans/create-or-update-comment@v2 - with: - issue-number: ${{github.event.pull_request.number}} - comment-id: ${{steps.find-existing.outputs.comment-id}} - edit-mode: replace - body: ${{env.NOTIFICATION_BODY}} diff --git a/.github/workflows/pr_labels.yml b/.github/workflows/pr_labels.yml deleted file mode 100644 index c9fc8ab2..00000000 --- a/.github/workflows/pr_labels.yml +++ /dev/null @@ -1,35 +0,0 @@ -# Manages labels on PRs before allowing merging -name: PR labels - -on: - pull_request: - types: [opened, labeled, unlabeled, synchronize] - -# 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: - runs-on: ubuntu-latest - - permissions: - pull-requests: read # needed to utilize required-labels - - steps: - - name: Merge-Blocking Labels # blocks merge if present - uses: mheap/github-action-required-labels@v3 - with: - mode: exactly - count: 0 - labels: "status: do not merge" - exit_type: failure - -# - name: Required Changelog Labels # require at least one of these labels -# uses: mheap/github-action-required-labels@v3 -# with: -# mode: minimum -# count: 1 -# labels: "type: feature, type: bug, type: refactor, type: translation, ignore changelog" -# exit_type: failure diff --git a/.github/workflows/pr_testing.yml b/.github/workflows/pr_testing.yml deleted file mode 100644 index c835e380..00000000 --- a/.github/workflows/pr_testing.yml +++ /dev/null @@ -1,37 +0,0 @@ -# Runs tests and other checks on Pull Requests -name: PR Testing - -on: - pull_request: - branches: - - master - -# if a second commit is pushed quickly after the first, cancel the first one's build -concurrency: - group: pr-testing-${{github.head_ref}} - cancel-in-progress: true - -jobs: - Test: - runs-on: ubuntu-latest - - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - - name: Setup Java - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '8' - - - name: Run Tests - uses: gradle/gradle-build-action@v2 - with: - arguments: 'test --build-cache --no-daemon' # disable daemon since only one gradle operation will happen - generate-job-summary: false - gradle-home-cache-includes: | - caches - jdks - notifications - wrapper diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 48138997..00000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,93 +0,0 @@ -# Publishes built jars to distribution platforms -name: Publish - -on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' # any semver tag, e.g. v1.2.3 - -env: - # link to the changelog with a format code for the version - CHANGELOG_LOCATION: "Changelog is available [here](https://github.com/${{github.repository}}/releases/tag/${{github.ref_name}})" - # type of release - RELEASE_TYPE: "beta" - -jobs: - Publish: - runs-on: ubuntu-latest - - permissions: - contents: write # needed to create GitHub releases - - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - - name: Check for Duplicate Tags - run: | - if git rev-parse -q --verify "refs/tags/${{ github.ref }}" >/dev/null; then - echo "Tag already exists. A version bump is required." - exit 1 - fi - - - name: Setup Java - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '8' - - - name: Build Project - uses: gradle/gradle-build-action@v2 - with: - arguments: 'build --build-cache --daemon' # use the daemon here so the rest of the process is faster - generate-job-summary: false - gradle-home-cache-includes: | - caches - jdks - notifications - wrapper - - - name: Publish to GitHub - uses: softprops/action-gh-release@v1 - with: - files: "build/libs/*.jar" - generate_release_notes: true - fail_on_unmatched_files: true - - - name: Publish to Maven - env: - MAVEN_USER: "${{ secrets.MAVEN_USER }}" - MAVEN_PASSWORD: "${{ secrets.MAVEN_PASSWORD }}" - run: ./gradlew publish - - - name: Publish to Curseforge - uses: gradle/gradle-build-action@v2 - env: - CURSEFORGE_API_KEY: "${{secrets.CURSEFORGE_API_KEY}}" - CURSEFORGE_PROJECT_ID: "${{secrets.CURSEFORGE_PROJECT_ID}}" - CHANGELOG_LOCATION: "${{env.CHANGELOG_LOCATION}}" - RELEASE_TYPE: "${{env.RELEASE_TYPE}}" - with: - arguments: 'curseforge --daemon' - generate-job-summary: false - gradle-home-cache-includes: | - caches - jdks - notifications - wrapper - - - name: Publish to Modrinth - uses: gradle/gradle-build-action@v2 - env: - MODRINTH_API_KEY: "${{secrets.MODRINTH_API_KEY}}" - MODRINTH_PROJECT_ID: "${{secrets.MODRINTH_PROJECT_ID}}" - CHANGELOG_LOCATION: "${{env.CHANGELOG_LOCATION}}" - RELEASE_TYPE: "${{env.RELEASE_TYPE}}" - with: - arguments: 'modrinth --daemon' - generate-job-summary: false - gradle-home-cache-includes: | - caches - jdks - notifications - wrapper diff --git a/.github/workflows/publish_project.yml b/.github/workflows/publish_project.yml new file mode 100644 index 00000000..28aa35e3 --- /dev/null +++ b/.github/workflows/publish_project.yml @@ -0,0 +1,64 @@ +# Publishes the project to GitHub Releases, CurseForge, and Modrinth +name: Publish Project + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' # any SemVer tag, e.g. v1.2.3 + +env: + # link to the changelog with a format code for the version + CHANGELOG_LOCATION: "Changelog is available [here](https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }})" + # type of release + RELEASE_TYPE: 'beta' + +concurrency: + group: publish-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + + permissions: + contents: write # needed to create GitHub releases + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup Build + uses: ./.github/actions/build_setup + + - name: Build Project + run: ./gradlew build --warning-mode all --build-cache + + - name: Publish to GitHub + uses: softprops/action-gh-release@v2 + with: + files: "build/libs/*.jar" + generate_release_notes: true + fail_on_unmatched_files: true + + - name: Publish to Maven + env: + MAVEN_USER: "${{ secrets.MAVEN_USER }}" + MAVEN_PASSWORD: "${{ secrets.MAVEN_PASSWORD }}" + run: ./gradlew publish + + - name: Publish to Curseforge + env: + CURSEFORGE_API_KEY: "${{ secrets.CURSEFORGE_API_KEY }}" + CURSEFORGE_PROJECT_ID: "${{ secrets.CURSEFORGE_PROJECT_ID }}" + CHANGELOG_LOCATION: "${{ env.CHANGELOG_LOCATION }}" + RELEASE_TYPE: "${{ env.RELEASE_TYPE }}" + run: ./gradlew curseforge --warning-mode all --build-cache + + - name: Publish to Modrinth + env: + MODRINTH_API_KEY: "${{ secrets.MODRINTH_API_KEY }}" + MODRINTH_PROJECT_ID: "${{ secrets.MODRINTH_PROJECT_ID }}" + CHANGELOG_LOCATION: "${{ env.CHANGELOG_LOCATION }}" + RELEASE_TYPE: "${{ env.RELEASE_TYPE }}" + run: ./gradlew modrinth --warning-mode all --build-cache diff --git a/.github/workflows/test_java.yml b/.github/workflows/test_java.yml new file mode 100644 index 00000000..5ee8e5d2 --- /dev/null +++ b/.github/workflows/test_java.yml @@ -0,0 +1,27 @@ +# Runs tests +name: Java Tests + +on: + push: + branches: + - master + pull_request: + +concurrency: + group: tests-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + test: + name: Tests + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup Build + uses: ./.github/actions/build_setup + + - name: Run Tests with Gradle + run: ./gradlew test --warning-mode all --build-cache diff --git a/.github/workflows/update_buildscript.yml b/.github/workflows/update_buildscript.yml index ff283349..1881daae 100644 --- a/.github/workflows/update_buildscript.yml +++ b/.github/workflows/update_buildscript.yml @@ -1,41 +1,33 @@ # Checks daily to see if the buildscript is in need of an update -name: Buildscript Updating +name: Update Buildscript on: workflow_dispatch: schedule: - - cron: "0 0 * * *" # "min hr day month year", so run once per day + - cron: '0 0 * * *' # "min hr day month year", so run once per day jobs: buildscript-update: runs-on: ubuntu-latest + # Avoid running this workflow on forks if: github.repository == 'GregTechCEu/gregicality-multiblocks' + permissions: contents: write pull-requests: write + steps: - - name: Checkout - uses: actions/checkout@v3 + - name: Checkout Repository + uses: actions/checkout@v4 - - name: Setup Java - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: '17' + - name: Setup Build + uses: ./.github/actions/build_setup - - name: Run script updater - uses: gradle/gradle-build-action@v2 - with: - arguments: 'updateBuildScript' - generate-job-summary: false - gradle-home-cache-includes: | - caches - jdks - notifications - wrapper + - name: Run Buildscript Updater + run: ./gradlew updateBuildScript --warning-mode all --build-cache - - name: Get new script version + - name: Get New Buildscript Version id: version-check run: | new_version=$(head -1 build.gradle | sed -r 's|//version: (.*)|\1|g') @@ -43,24 +35,19 @@ jobs: - name: Create Pull Request id: create-pull-request - uses: peter-evans/create-pull-request@v4 + uses: peter-evans/create-pull-request@v6 env: GITHUB_TOKEN: ${{ secrets.BUILDSCRIPT_UPDATER_TOKEN }} with: token: ${{ secrets.BUILDSCRIPT_UPDATER_TOKEN }} - committer: GitHub - author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> commit-message: 'update build script version to ${{ steps.version-check.outputs.NEW_VERSION }}' branch: gha-update-buildscript title: Update build script version to ${{ steps.version-check.outputs.NEW_VERSION }} body: This pull request is created by the buildscript-update workflow labels: ignore changelog - - name: Enable pull request auto-merge - id: pull-request-auto-merge + - name: Enable Pull-Request Auto-Merge if: steps.create-pull-request.outputs.pull-request-operation == 'created' - uses: peter-evans/enable-pull-request-automerge@v3 - with: - token: ${{ secrets.BUILDSCRIPT_UPDATER_TOKEN }} - pull-request-number: ${{ steps.create-pull-request.outputs.pull-request-number }} - merge-method: squash + run: gh pr merge --squash --auto "${{ steps.create-pull-request.outputs.pull-request-number }}" + env: + GH_TOKEN: ${{ secrets.BUILDSCRIPT_UPDATER_TOKEN }} diff --git a/.github/workflows/update_gradle_cache.yml b/.github/workflows/update_gradle_cache.yml index bdf19d83..ba93b167 100644 --- a/.github/workflows/update_gradle_cache.yml +++ b/.github/workflows/update_gradle_cache.yml @@ -1,39 +1,30 @@ -# Updates the Gradle Cache when relevant files change +# Updates the Gradle Cache when necessary name: Update Gradle Cache on: - workflow_dispatch: push: branches: - master - paths: - - "gradle**" # covers gradle folder, gradle.properties, gradlew - - "build.gradle*" - - "settings.gradle*" - - "src/main/resources/META-INF/*_at.cfg" # access transformers + paths: ['gradle/**', '**.gradle', 'gradle.properties', 'gradlew**', 'src/main/resources/*_at.cfg'] + workflow_dispatch: + +concurrency: + group: gradle-cache-${{ github.ref }} + cancel-in-progress: true jobs: - Update_Cache: + update-cache: + name: Update Grade Cache runs-on: ubuntu-latest steps: - name: Checkout Repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Setup Java - uses: actions/setup-java@v3 + - name: Setup Build + uses: ./.github/actions/build_setup with: - distribution: 'temurin' - java-version: '8' + update-cache: true - - name: Update Cache - uses: gradle/gradle-build-action@v2 - with: - arguments: 'test --build-cache --no-daemon' # disable daemon since only one gradle operation will happen - generate-job-summary: false - gradle-home-cache-includes: | - caches - jdks - notifications - wrapper - cache-write-only: true + - name: Build Project with Gradle + run: ./gradlew assemble --warning-mode all --build-cache diff --git a/.github/workflows/validate_gradle_wrapper.yml b/.github/workflows/validate_gradle_wrapper.yml index 6f7a9d4c..88242594 100644 --- a/.github/workflows/validate_gradle_wrapper.yml +++ b/.github/workflows/validate_gradle_wrapper.yml @@ -1,4 +1,4 @@ -# Validates the integrity of the Gradle wrapper +# Validates the integrity of the Gradle Wrapper name: Validate Gradle Wrapper on: @@ -13,9 +13,8 @@ on: paths: - 'gradle/**' -# if a second commit is pushed quickly after the first, cancel the first one's build concurrency: - group: gradle-wrapper-validation-${{github.head_ref}} + group: gradle-wrapper-validation-${{ github.head_ref || github.ref }} cancel-in-progress: true jobs: @@ -24,7 +23,7 @@ jobs: steps: - name: Checkout Repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Validate Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 + uses: gradle/actions/wrapper-validation