From 8576c5902e91ad97274ef4b366b85bea4551c572 Mon Sep 17 00:00:00 2001 From: StartsMercury <89975834+StartsMercury@users.noreply.github.com> Date: Sun, 20 Oct 2024 09:41:29 +0800 Subject: [PATCH] GH Actions: for commit and pull request Highly based on Sodium's at https://github.com/CaffeineMC/sodium-fabric/tree/dd25399c139004e863beb8a2195b9d80b847d95c/.github/workflows --- .github/workflows/CRMM_UPLOAD_RELEASE.yml | 44 ------------------ .github/workflows/build-commit.yml | 42 +++++++++++++++++ .github/workflows/build-pull-request.yml | 30 ++++++++++++ .github/workflows/build-release.yml | 56 +++++++++++++++++++++++ .github/workflows/build-tag.yml | 45 ++++++++++++++++++ .github/workflows/gradle-publish.ymlx | 42 ----------------- 6 files changed, 173 insertions(+), 86 deletions(-) delete mode 100644 .github/workflows/CRMM_UPLOAD_RELEASE.yml create mode 100644 .github/workflows/build-commit.yml create mode 100644 .github/workflows/build-pull-request.yml create mode 100644 .github/workflows/build-release.yml create mode 100644 .github/workflows/build-tag.yml delete mode 100644 .github/workflows/gradle-publish.ymlx diff --git a/.github/workflows/CRMM_UPLOAD_RELEASE.yml b/.github/workflows/CRMM_UPLOAD_RELEASE.yml deleted file mode 100644 index 386730e..0000000 --- a/.github/workflows/CRMM_UPLOAD_RELEASE.yml +++ /dev/null @@ -1,44 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle - -name: CRM Upload To Releases - -on: - release: - types: [created] - -jobs: - build: - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 - - - name: Build with Gradle - run: ./gradlew build - - # The USERNAME and TOKEN need to correspond to the credentials environment variables used in - # the publishing section of your build.gradle - - name: Publish to GitHub Packages - run: ./gradlew publishAllPublicationsToCRMReleasesRepository - env: - CRMReleasesUsername: ${{ secrets.CRM_GITHUB_USER }} - CRMReleasesPassword: ${{ secrets.CRM_GITHUB_PASS }} diff --git a/.github/workflows/build-commit.yml b/.github/workflows/build-commit.yml new file mode 100644 index 0000000..61a8522 --- /dev/null +++ b/.github/workflows/build-commit.yml @@ -0,0 +1,42 @@ +name: build-commit +on: [ push ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Extract Current Branch Name + shell: bash + # bash pattern expansion to grab the branch name without the slashes + run: ref="${GITHUB_REF#refs/heads/}" && echo "branch=${ref////-}" >> $GITHUB_OUTPUT + id: ref + + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 + + - name: Make Gradle Wrapper Executable + run: chmod +x ./gradlew + + - name: Setup JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + cache-read-only: false + + - name: Gradle Build + run: ./gradlew check build + + - name: Capture Build Artifacts + uses: actions/upload-artifact@v4 + with: + name: FluxApi-artifacts-${{ steps.ref.outputs.branch }} + path: build/libs/*.jar diff --git a/.github/workflows/build-pull-request.yml b/.github/workflows/build-pull-request.yml new file mode 100644 index 0000000..7dd7ed5 --- /dev/null +++ b/.github/workflows/build-pull-request.yml @@ -0,0 +1,30 @@ +name: build-pull-request +on: [ pull_request ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 + + - name: Make Gradle Wrapper Executable + run: chmod +x ./gradlew + + - name: Setup JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + cache-read-only: true + + - name: Gradle Build + run: ./gradlew check build diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..ce718d3 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,56 @@ +name: build-release +on: + release: + types: + - published + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Extract Current Branch Name + shell: bash + # bash pattern expansion to grab the branch name without the slashes + run: ref="${GITHUB_REF#refs/heads/}" && echo "branch=${ref////-}" >> $GITHUB_OUTPUT + id: ref + + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 + + - name: Make Gradle Wrapper Executable + run: chmod +x ./gradlew + + - name: Setup JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + cache-read-only: true + + - name: Gradle Build + run: ./gradlew check build + + - name: Capture Build Artifacts + uses: actions/upload-artifact@v4 + with: + name: FluxApi-artifacts-${{ steps.ref.outputs.branch }} + path: build/libs/*.jar + + # The USERNAME and TOKEN need to correspond to the credentials environment variables used in + # the publishing section of your build.gradle + - name: Publish to GitHub Packages + run: ./gradlew publishAllPublicationsToCRMReleasesRepository + env: + CRMReleasesUsername: ${{ secrets.CRM_GITHUB_USER }} + CRMReleasesPassword: ${{ secrets.CRM_GITHUB_PASS }} diff --git a/.github/workflows/build-tag.yml b/.github/workflows/build-tag.yml new file mode 100644 index 0000000..74b8b9b --- /dev/null +++ b/.github/workflows/build-tag.yml @@ -0,0 +1,45 @@ +name: build-tag +on: + push: + tags: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Extract Current Branch Name + shell: bash + # bash pattern expansion to grab the branch name without the slashes + run: ref="${GITHUB_REF#refs/heads/}" && echo "branch=${ref////-}" >> $GITHUB_OUTPUT + id: ref + + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 + + - name: Make Gradle Wrapper Executable + run: chmod +x ./gradlew + + - name: Setup JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + cache-read-only: true + + - name: Gradle Build + run: ./gradlew check build + + - name: Capture Build Artifacts + uses: actions/upload-artifact@v4 + with: + name: FluxApi-artifacts-${{ steps.ref.outputs.branch }} + path: build/libs/*.jar diff --git a/.github/workflows/gradle-publish.ymlx b/.github/workflows/gradle-publish.ymlx deleted file mode 100644 index 06eb05c..0000000 --- a/.github/workflows/gradle-publish.ymlx +++ /dev/null @@ -1,42 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle - -name: Gradle Package - -on: release - -jobs: - build: - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 - - - name: Build with Gradle - run: ./gradlew build - - # The USERNAME and TOKEN need to correspond to the credentials environment variables used in - # the publishing section of your build.gradle - - name: Publish to GitHub Packages - run: ./gradlew publishAllPublicationsToCRMReleasesRepository - env: - CRMReleasesUsername: ${{ secrets.CRM_GITHUB_USER }} - CRMReleasesPassword: ${{ secrets.CRM_GITHUB_PASS }}