From ff4c8b97d9304ad33ae0989a64e24fdbb694a16b Mon Sep 17 00:00:00 2001 From: Phillipp Glanz <6745190+TheMeinerLP@users.noreply.github.com> Date: Sat, 25 Jan 2025 13:30:59 +0100 Subject: [PATCH] chore: Rework workflows for github (#2628) * chore: Rework workflows for github * feat: Add publish workflow via PR * Trigger Build * feat: Add name and improve if conditions --- .github/old-workflows/check-pr-style.yml | 31 ---------- .github/old-workflows/codeql-analysis.yml | 67 --------------------- .github/workflows/build-pr.yml | 41 +++++++++++++ .github/workflows/build.yml | 37 ++++++++++++ .github/workflows/close_invalid_prs.yml | 1 + .github/workflows/javadoc.yml | 3 +- .github/workflows/pr.yml | 59 ------------------ .github/workflows/snapshot-deploy.yaml | 32 ---------- .github/workflows/trigger-jitpack-build.yml | 12 ---- 9 files changed, 80 insertions(+), 203 deletions(-) delete mode 100644 .github/old-workflows/check-pr-style.yml delete mode 100644 .github/old-workflows/codeql-analysis.yml create mode 100644 .github/workflows/build-pr.yml create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/pr.yml delete mode 100644 .github/workflows/snapshot-deploy.yaml delete mode 100644 .github/workflows/trigger-jitpack-build.yml diff --git a/.github/old-workflows/check-pr-style.yml b/.github/old-workflows/check-pr-style.yml deleted file mode 100644 index 9e0568f90..000000000 --- a/.github/old-workflows/check-pr-style.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Check PR code style - -on: - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 21 - uses: actions/setup-java@v1 - with: - java-version: 21 - - name: Run java checkstyle - uses: nikitasavinov/checkstyle-action@0.3.1 - with: - # Report level for reviewdog [info,warning,error] - level: info - # Reporter of reviewdog command [github-pr-check,github-pr-review] - reporter: github-pr-check - # Filtering for the reviewdog command [added,diff_context,file,nofilter]. - filter_mode: added - # Exit code for reviewdog when errors are found [true,false]. - fail_on_error: false - # Checkstyle config file - checkstyle_config: minestom_checks.xml - checkstyle_version: "8.42" diff --git a/.github/old-workflows/codeql-analysis.yml b/.github/old-workflows/codeql-analysis.yml deleted file mode 100644 index 2325a1cc2..000000000 --- a/.github/old-workflows/codeql-analysis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - schedule: - - cron: '27 19 * * 3' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml new file mode 100644 index 000000000..c62781790 --- /dev/null +++ b/.github/workflows/build-pr.yml @@ -0,0 +1,41 @@ +name: Build PR +on: [pull_request] +jobs: + build_pr: + name: Build PR + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v3 + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + - name: Cache Gradle packages + uses: actions/cache@v3 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Build on ${{ matrix.os }} + run: ./gradlew test + publish: + name: Publish PR + if: contains(github.event.pull_request.labels.*.name, 'Publish Pull Request') && github.repository_owner == 'Minestom' + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Publish Artifacts + env: + MINESTOM_VERSION: ${{ github.head_ref }}-${{ steps.vars.outputs.short_commit_hash }} + MINESTOM_CHANNEL: snapshot + run: | + ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository + echo "Version: ${SHORT_COMMIT_HASH}" >> $GITHUB_STEP_SUMMARY \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..5f7c40d31 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +name: Build +on: + push: + branches: + - master +jobs: + Build: + name: Build and Publish + # Run on all label events (won't be duplicated) or all push events or on PR syncs not from the same repo + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v3 + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + cache: gradle + java-version: 21 + - name: Cache Gradle packages + uses: actions/cache@v3 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Publish to Central via Build + if: github.repository_owner == 'Minestom' + run: | + ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository + echo "Version: ${SHORT_COMMIT_HASH}" >> $GITHUB_STEP_SUMMARY + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/close_invalid_prs.yml b/.github/workflows/close_invalid_prs.yml index 44c763b6d..bf9fa73d5 100644 --- a/.github/workflows/close_invalid_prs.yml +++ b/.github/workflows/close_invalid_prs.yml @@ -7,6 +7,7 @@ on: jobs: run: + name: Close invalid PRs if: | github.repository != github.event.pull_request.head.repo.full_name && ( diff --git a/.github/workflows/javadoc.yml b/.github/workflows/javadoc.yml index 92d41fb98..0508616b1 100644 --- a/.github/workflows/javadoc.yml +++ b/.github/workflows/javadoc.yml @@ -6,9 +6,8 @@ on: jobs: build: - runs-on: ubuntu-latest - + name: Build and deploy Javadoc steps: - uses: actions/checkout@v2 - name: Set up JDK 21 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index 548cb3921..000000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Build and test Minestom - -on: - pull_request: - branches: [ master ] - -jobs: - tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 21 - uses: actions/setup-java@v2 - with: - distribution: 'zulu' - java-version: 21 - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Setup gradle cache - uses: burrunan/gradle-cache-action@v1 - with: - save-generated-gradle-jars: false - save-local-build-cache: false - save-gradle-dependencies-cache: true - save-maven-dependencies-cache: true - # Ignore some of the paths when caching Maven Local repository - maven-local-ignore-paths: | - net/minestom/ - - name: Build Minestom - run: ./gradlew classes testClasses javadoc - - name: Run Minestom tests - run: ./gradlew test - publish: - runs-on: ubuntu-latest - if: github.event.pull_request.head.repo.full_name == github.repository - env: - SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} - GPG_PASSPHRASE: ${{ secrets.GPG_PASSWORD }} - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 21 - uses: actions/setup-java@v2 - with: - java-version: '21' - distribution: 'temurin' - - name: Set outputs - id: vars - run: | - export ACTUAL=${{ github.event.pull_request.head.sha }} - echo "short_commit_hash=${ACTUAL::10}" >> $GITHUB_OUTPUT - - name: Publish to Sonatype - env: - MINESTOM_VERSION: ${{ github.head_ref }}-${{ steps.vars.outputs.short_commit_hash }} - MINESTOM_CHANNEL: snapshot - run: | - ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository - echo "Version: ${SHORT_COMMIT_HASH}" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/snapshot-deploy.yaml b/.github/workflows/snapshot-deploy.yaml deleted file mode 100644 index cf032b8da..000000000 --- a/.github/workflows/snapshot-deploy.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: Gradle Publish to Maven Central - -on: - push: - branches: [ master ] - -jobs: - build: - runs-on: ubuntu-latest - env: - SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} - GPG_PASSPHRASE: ${{ secrets.GPG_PASSWORD }} - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 21 - uses: actions/setup-java@v2 - with: - java-version: '21' - distribution: 'temurin' - - name: Set outputs - id: vars - run: | - echo "short_commit_hash=${GITHUB_SHA::10}" >> $GITHUB_OUTPUT - - name: Publish to Sonatype - env: - MINESTOM_VERSION: ${{ steps.vars.outputs.short_commit_hash }} - MINESTOM_CHANNEL: release - run: | - ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository - echo "Version: ${SHORT_COMMIT_HASH}" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/trigger-jitpack-build.yml b/.github/workflows/trigger-jitpack-build.yml deleted file mode 100644 index 8366c4f6f..000000000 --- a/.github/workflows/trigger-jitpack-build.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Trigger Jitpack Build -on: - push: - branches: [ master ] - - workflow_dispatch: -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Trigger Jitpack Build - run: curl "https://jitpack.io/com/github/Minestom/Minestom/${GITHUB_SHA:0:10}/build.log"