Skip to content

Commit

Permalink
ci: remake workflows from scratch
Browse files Browse the repository at this point in the history
- Publishes release on dispatch
- Publishes snapshot or jar files on push
- Testing
  • Loading branch information
darksaid98 committed May 28, 2024
1 parent e3dc75d commit 9c9e97a
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 51 deletions.
44 changes: 19 additions & 25 deletions .github/workflows/release.yml → .github/workflows/releases.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,40 @@
name: Release

on:
push:
branches:
- 'main'
- 'master'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write
discussions: write
pull-requests: write

jobs:
tests:
name: Run Tests
name: Tests
uses: ./.github/workflows/tests.yml
secrets: inherit
with:
publish_snapshot: false
release:
name: Create Release
name: Build
needs: [tests]
strategy:
matrix:
os: [ubuntu-latest]
java: [8]
runs-on: ${{ matrix.os }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
needs: [tests]
steps:
# Checkout repository
- name: Checkout Repository
uses: actions/checkout@v4

# Setup JDK
# Build setup
- name: Setup JDK
uses: ./.github/actions/jdk
with:
java-version: ${{ matrix.java }}

# Setup Gradle & Verify wrapper
- name: Setup Gradle
uses: ./.github/actions/gradle

Expand All @@ -51,14 +44,14 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
default-bump: patch
# Build with Gradle & Publish to Maven repository
- name: Build with Gradle
run: ./gradlew clean build publishAllPublicationsToReleasesRepository -PcustomVersion=${{ steps.version.outputs.version }}

# Build and upload to Maven
- name: Build with Gradle & Publish to Maven
run: ./gradlew clean build publishAllPublicationsToReleasesRepository -PcustomVersion=${{ steps.version.outputs.version }} --info
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_NAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_SECRET }}

# Generate changelog
- name: Changelog
uses: ardalanamini/auto-changelog@v4
Expand Down Expand Up @@ -91,11 +84,12 @@ jobs:
- name: Create Release
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.version.outputs.version-with-prefix }}
tag_name: ${{ steps.version.outputs.version }}
generate_release_notes: false
body: ${{ steps.changelog.outputs.changelog }}
files: |
${{ github.workspace }}/build/libs/*
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ steps.version.outputs.version-with-prefix }}
draft: false
prerelease: ${{ contains(github.ref_name, '-RC-') }}
generate_release_notes: false
body: ${{ steps.changelog.outputs.changelog }}
prerelease: ${{ contains(github.ref_name, '-RC-') }}
67 changes: 67 additions & 0 deletions .github/workflows/snapshots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Snapshot

on:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write
discussions: write
pull-requests: write

jobs:
tests:
name: Tests
uses: ./.github/workflows/tests.yml
snapshot:
name: Build
needs: [tests]
strategy:
matrix:
os: [ubuntu-latest]
java: [8]
runs-on: ${{ matrix.os }}
steps:
# Checkout repository
- name: Checkout Repository
uses: actions/checkout@v4

# Build setup
- name: Setup JDK
uses: ./.github/actions/jdk
with:
java-version: ${{ matrix.java }}

- name: Setup Gradle
uses: ./.github/actions/gradle

# Makes the next semantic tag variable available for use in workflow
- uses: jveldboom/action-conventional-versioning@v1
id: version
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
default-bump: patch

# If on main branch, upload snapshot to maven
- name: Build with Gradle & Publish to Maven
if: contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)
run: ./gradlew clean build publishAllPublicationsToSnapshotsRepository -PcustomVersion=${{ steps.version.outputs.version }}-SNAPSHOT-${{ github.run_number }} --info
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_NAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_SECRET }}

# Else if, upload built jar from push
- name: Build with Gradle
if: contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) == false
run: ./gradlew clean build -PcustomVersion=${{ steps.version.outputs.version }}-SNAPSHOT-${{ github.run_number }} --info

- name: Upload build artifact
uses: actions/upload-artifact@v4
if: contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) == false
with:
name: Build ${{ steps.version.outputs.version-with-prefix }}-SNAPSHOT-${{ github.run_number }}
path: ${{ github.workspace }}/build/libs/
retention-days: 3
28 changes: 2 additions & 26 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
name: Run Tests
name: Tests

on:
push:
branches-ignore: # Tests are triggered from release workflow
- 'main'
- 'master'
workflow_dispatch:
workflow_call:
secrets:
MAVEN_NAME:
required: false
MAVEN_PASSWORD:
required: false
inputs:
publish_snapshot:
required: false
default: true
type: boolean

permissions:
contents: write
Expand All @@ -25,7 +11,7 @@ permissions:

jobs:
test-build:
name: Test Build
name: Build
strategy:
matrix:
os: [ubuntu-latest]
Expand Down Expand Up @@ -53,16 +39,6 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
default-bump: patch


# Build with Gradle
- name: Build with Gradle
if: ${{ inputs.publish_snapshot == false }}
run: ./gradlew clean build -PcustomVersion=${{ steps.version.outputs.version }}-SNAPSHOT-${{ github.run_number }} --info

# Build with Gradle
- name: Build with Gradle
if: ${{ inputs.publish_snapshot == true }}
run: ./gradlew clean build publishAllPublicationsToSnapshotsRepository -PcustomVersion=${{ steps.version.outputs.version }}-SNAPSHOT-${{ github.run_number }} --info
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_NAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_SECRET }}

0 comments on commit 9c9e97a

Please sign in to comment.