From 6834d0af4e4d6dffa2d7d615fd26074dcbbe1d82 Mon Sep 17 00:00:00 2001 From: darksaid98 Date: Tue, 19 Nov 2024 21:12:25 +0100 Subject: [PATCH] ci: setup using gradle --- .github/ISSUE_TEMPLATE/bug_report.md | 34 ++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++ .github/actions/gradle/action.yml | 17 +++ .github/actions/jdk/action.yml | 21 ++++ .github/dependabot.yml | 26 +++++ .github/workflows/ci.yml | 50 +++++++++ .github/workflows/deploy.yml | 67 ++++++++++++ .github/workflows/release.yml | 30 ------ .github/workflows/stage.yml | 124 ++++++++++++++++++++++ .github/workflows/stale.yml | 26 +++++ .github/workflows/test.yml | 38 +++++++ 11 files changed, 423 insertions(+), 30 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/actions/gradle/action.yml create mode 100644 .github/actions/jdk/action.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/stage.yml create mode 100644 .github/workflows/stale.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..66a0311 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,34 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Version information:** +- Vanilla version: [e.g. 1.20.2] +- Server version: [e.g. paper-123] +- Plugin version [e.g. 0.1.0] + +**Additional context** +``` +Add any other context about the problem here including console errors. +``` \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..6532412 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. \ No newline at end of file diff --git a/.github/actions/gradle/action.yml b/.github/actions/gradle/action.yml new file mode 100644 index 0000000..909cc6c --- /dev/null +++ b/.github/actions/gradle/action.yml @@ -0,0 +1,17 @@ +name: 'Setup Gradle' +description: 'Grant execute permissions, validate Gradle wrapper, setup Gradle wrapper' + +runs: + using: 'composite' + steps: + - name: Grant execute permissions for Gradle wrapper + run: chmod +x gradlew + shell: bash + + - name: Validate Gradle Wrapper Authenticity + uses: gradle/actions/wrapper-validation@v3 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + add-job-summary: 'on-failure' diff --git a/.github/actions/jdk/action.yml b/.github/actions/jdk/action.yml new file mode 100644 index 0000000..4349de3 --- /dev/null +++ b/.github/actions/jdk/action.yml @@ -0,0 +1,21 @@ +name: 'Setup JDK' +description: 'Set up JDK' + +inputs: + java-version: + description: 'Java version' + required: false + default: '17' + distribution: + description: 'JDK Distribution' + required: false + default: 'temurin' + +runs: + using: 'composite' + steps: + - name: Setup JDK + uses: actions/setup-java@v4 + with: + java-version: ${{ inputs.java-version }} + distribution: ${{ inputs.distribution }} diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..377a6ff --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,26 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + commit-message: + prefix: "ci:" + target-branch: "main" + - package-ecosystem: "gradle" + directory: "/" + schedule: + interval: "daily" + commit-message: + prefix: "build:" + target-branch: "main" + groups: + "org.flywaydb": + patterns: + - "org.flywaydb*" + "org.jooq": + patterns: + - "org.jooq*" + "net.kyori": + patterns: + - "net.kyori*" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4944649 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: CI/CD + +on: + push: + branches: + - "main" + - "master" + tags: + - "*.*.*" + pull_request: + branches: + - "*" + workflow_dispatch: + +permissions: + attestations: write + contents: write + id-token: write + checks: write + +concurrency: + group: ${{ format('{0}-{1}', github.job, github.ref) }} + cancel-in-progress: true + +jobs: + test: + name: Test + uses: ./.github/workflows/test.yml + with: + os: ubuntu-latest + java: 17 + + stage: + name: Stage + needs: test + if: ${{ github.event_name != 'pull_request' }} + uses: ./.github/workflows/stage.yml + with: + os: ubuntu-latest + java: 17 + secrets: inherit + + deploy: + name: Deploy + needs: stage + if: github.ref_type == 'tag' + uses: ./.github/workflows/deploy.yml + with: + os: ubuntu-latest + secrets: inherit diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..d970a22 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,67 @@ +name: Deploy + +on: + workflow_call: + inputs: + os: + description: "The os the workflow shold use" + required: false + type: string + default: ubuntu-latest + +permissions: + contents: write + +jobs: + deploy: + name: "Release" + runs-on: ${{ inputs.os }} + steps: + - name: Download Snapshot + uses: actions/download-artifact@v4 + with: + name: Release + run-id: ${{ github.event.workflow_run.id }} + path: "${{ github.workspace }}/tmp/" + + # Generate changelog + - name: Generate Changelog + uses: ardalanamini/auto-changelog@v4 + id: changelog + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + commit-types: | + feat: New Features + fix: Bug Fixes + build: Build System & Dependencies + perf: Performance Improvements + docs: Documentation + test: Tests + refactor: Refactors + chore: Chores + ci: CI + style: Code Style + revert: Reverts + default-commit-type: Other Changes + release-name: ${{ github.ref_name }} + mention-authors: true + mention-new-contributors: true + include-compare-link: true + include-pr-links: true + include-commit-links: true + semver: true + use-github-autolink: true + + # Create release + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + files: | + ${{ github.workspace }}/tmp/* + fail_on_unmatched_files: true + token: ${{ secrets.GITHUB_TOKEN }} + tag_name: ${{ github.ref_name }} + draft: false + prerelease: ${{ contains(github.ref_name, '-RC-') }} + generate_release_notes: false + body: ${{ steps.changelog.outputs.changelog }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index c733fad..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Build & Upload Release jar with Maven - -on: - release: - types: [ published ] - -jobs: - publish_build_files: - 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: '17' - cache: 'maven' - - - name: Build with Maven - run: mvn -B package --file pom.xml - - - name: Upload Release Assets - uses: AButler/upload-release-assets@v2.0 - with: - files: 'target/SiegeEngines-*.jar' - repo-token: ${{ secrets.GITHUB_TOKEN }} - release-tag: ${{ github.event.release.tag_name }} \ No newline at end of file diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml new file mode 100644 index 0000000..bda5ac0 --- /dev/null +++ b/.github/workflows/stage.yml @@ -0,0 +1,124 @@ +name: Stage + +on: + workflow_call: + inputs: + os: + description: "The os the workflow shold use" + required: false + type: string + default: ubuntu-latest + java: + description: "The Java version the workflow should use" + required: false + type: number + default: 17 + +permissions: + attestations: write + contents: write + id-token: write + +jobs: + stage-build-snapshot: + name: "Build Snapshot" + if: github.ref_type != 'tag' + runs-on: ${{ inputs.os }} + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup JDK + uses: ./.github/actions/jdk + with: + java-version: ${{ inputs.java }} + + - name: Setup Gradle + uses: ./.github/actions/gradle + + # Get version field in project properties file for snapshot version + - name: Get Project Version + uses: kurt-code/gha-properties@v0.0.2 + id: version + with: + operation: "read" + file-path: "./gradle.properties" + keys: "version" + + - name: Set Version Environment Variable + run: | + echo "CUSTOM_VERSION=${{ steps.version.outputs.version }}-SNAPSHOT-${{ github.run_number }}" >> $GITHUB_ENV + + - name: Build with Gradle + run: ./gradlew build -PaltVer=${{ env.CUSTOM_VERSION }} --info + + - name: Upload Snapshot + uses: actions/upload-artifact@v4 + with: + name: Snapshot-${{ github.run_number }} + path: ${{ github.workspace }}/build/libs/ + retention-days: 7 + + stage-version: + name: "Update Project Version" + runs-on: ${{ inputs.os }} + if: github.ref_type == 'tag' + steps: + # Checkout repository + - name: Checkout Repository + if: contains(github.ref_name, '-RC-') == false + uses: actions/checkout@v4 + + # Update version field in project properties file + - name: Update Gradle Project Version + if: contains(github.ref_name, '-RC-') == false + uses: kurt-code/gha-properties@v0.0.2 + with: + operation: "write" + file-path: "./gradle.properties" + key-value-pairs: '{"version": "${{ github.ref_name }}"}' + + # Commit and push updated version properties file + - name: Update repository + if: contains(github.ref_name, '-RC-') == false + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "chore: bump version to v${{ github.ref_name }}" + branch: ${{ github.event.repository.default_branch }} + + stage-build-release: + name: "Build Release" + needs: stage-version + runs-on: ${{ inputs.os }} + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup JDK + uses: ./.github/actions/jdk + with: + java-version: ${{ inputs.java }} + + - name: Setup Gradle + uses: ./.github/actions/gradle + + - name: Set Version Environment Variable + run: | + echo "CUSTOM_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + + - name: Build with Gradle + run: ./gradlew build -PaltVer=${{ env.CUSTOM_VERSION }} -x test --info + + - name: Generate Build Provenance Attestations + uses: actions/attest-build-provenance@v1 + with: + subject-path: "${{ github.workspace }}/build/libs/*" + + - name: Upload Snapshot + uses: actions/upload-artifact@v4 + with: + name: Release + path: | + ${{ github.workspace }}/build/libs/ + ${{ github.workspace }}/SiegeEngines-ResourcePack.zip + retention-days: 7 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..d66dd6f --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,26 @@ +name: "Close Stale Issues & PRs" +on: + schedule: + - cron: "30 1 * * *" + +permissions: + contents: read + issues: write + pull-requests: write + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v9 + with: + stale-issue-message: "This issue has been automatically marked as stale because it has been open for 60 days with no activity." + stale-pr-message: "This PR has been automatically marked as stale because it has been open for 60 days with no activity." + close-issue-message: "This issue was closed because it has been stalled for -1 days with no activity." + close-pr-message: "This PR was closed because it has been stalled for -1 days with no activity." + days-before-issue-stale: 60 + days-before-pr-stale: 60 + days-before-issue-close: -1 + days-before-pr-close: -1 + stale-issue-label: "stale" + stale-pr-label: "stale" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..50d72a8 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,38 @@ +name: Test + +on: + workflow_call: + inputs: + os: + description: "The os the workflow shold use" + required: false + type: string + default: ubuntu-latest + java: + description: "The Java version the workflow should use" + required: false + type: number + default: 17 + +permissions: + checks: write + contents: write + +jobs: + test-build: + name: "Run Tests" + runs-on: ${{ inputs.os }} + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup JDK + uses: ./.github/actions/jdk + with: + java-version: ${{ inputs.java }} + + - name: Setup Gradle + uses: ./.github/actions/gradle + + - name: Test with Gradle + run: ./gradlew build --info