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
This commit is contained in:
Phillipp Glanz 2025-01-25 13:30:59 +01:00 committed by GitHub
parent 96543a894f
commit ff4c8b97d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 80 additions and 203 deletions

View File

@ -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"

View File

@ -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

41
.github/workflows/build-pr.yml vendored Normal file
View File

@ -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

37
.github/workflows/build.yml vendored Normal file
View File

@ -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 }}

View File

@ -7,6 +7,7 @@ on:
jobs:
run:
name: Close invalid PRs
if: |
github.repository != github.event.pull_request.head.repo.full_name &&
(

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"