Skip to content

Commit

Permalink
ci: add basic ci
Browse files Browse the repository at this point in the history
  • Loading branch information
darksaid98 committed Dec 21, 2024
1 parent 23dddc9 commit 3e8ff52
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/actions/gradle/action.yml
Original file line number Diff line number Diff line change
@@ -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@v4

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
add-job-summary: 'on-failure'
21 changes: 21 additions & 0 deletions .github/actions/jdk/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Setup JDK'
description: 'Set up JDK'

inputs:
java-version:
description: 'Java version'
required: false
default: '8'
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 }}
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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: 8

stage:
name: Stage
needs: test
if: ${{ github.event_name != 'pull_request' }}
uses: ./.github/workflows/stage.yml
with:
os: ubuntu-latest
java: 8
secrets: inherit

deploy:
name: Deploy
needs: stage
if: github.ref_type == 'tag'
uses: ./.github/workflows/deploy.yml
with:
os: ubuntu-latest
secrets: inherit
67 changes: 67 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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 }}
118 changes: 118 additions & 0 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
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: 8

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
shell: bash
run: |
echo "CUSTOM_VERSION=$(grep "^version=" ./gradle.properties | awk -F'=' '{print $2}')-SNAPSHOT-${{ github.run_number }}" >> $GITHUB_ENV
- name: Build with Gradle
run: ./gradlew build -PaltVer=${{ env.CUSTOM_VERSION }} -x test --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
shell: bash
run: |
sed -i -b 's/^version=.*/version=${{ github.ref_name }}/' ./gradle.properties
# 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 and publish
run: ./gradlew build publish -PaltVer=${{ env.CUSTOM_VERSION }} -x test --info
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
GPG_KEY: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
GPG_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}

- name: Generate Build Provenance Attestations
uses: actions/attest-build-provenance@v2
with:
subject-path: "${{ github.workspace }}/build/libs/*"

- name: Upload Snapshot
uses: actions/upload-artifact@v4
with:
name: Release
path: ${{ github.workspace }}/build/libs/
retention-days: 7
26 changes: 26 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -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"
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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: 8

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 test --info

- name: Publish Test Report
uses: mikepenz/action-junit-report@v5
if: success() || failure()
with:
require_tests: false
fail_on_failure: true
check_name: Test Report
report_paths: '**/build/test-results/**/TEST-*.xml'

0 comments on commit 3e8ff52

Please sign in to comment.