Skip to content

Commit

Permalink
ci: refactor release workflows
Browse files Browse the repository at this point in the history
- Adds snapshots
- Adds test workflow
  • Loading branch information
darksaid98 committed May 29, 2024
1 parent c63e639 commit b68b023
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 104 deletions.
89 changes: 0 additions & 89 deletions .github/workflows/release.yml

This file was deleted.

95 changes: 95 additions & 0 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Release

on:
workflow_dispatch:

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
release:
name: Build
needs: [tests]
strategy:
matrix:
os: [ubuntu-latest]
java: [17]
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

# 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
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: ${{ steps.version.outputs.version-with-prefix }}
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:
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 }}
draft: false
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: [17]
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
44 changes: 44 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Tests

on:
workflow_dispatch:
workflow_call:

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

jobs:
test-build:
name: Build
strategy:
matrix:
os: [ubuntu-latest]
java: [17]
runs-on: ${{ matrix.os }}
steps:
# Checkout repository
- name: Checkout Repository
uses: actions/checkout@v4

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

# Setup Gradle & Verify wrapper
- 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

# Build with Gradle
- name: Build with Gradle
run: ./gradlew clean build -PcustomVersion=${{ steps.version.outputs.version }}-SNAPSHOT-${{ github.run_number }} --info
35 changes: 20 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,38 @@ dependencies {
}

tasks {
test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}

compileJava {
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything

// Set the release flag. This configures what version bytecode the compiler will emit, as well as what JDK APIs are usable.
// See https://openjdk.java.net/jeps/247 for more information.
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
options.compilerArgs.addAll(arrayListOf("-Xlint:all", "-Xlint:-processing", "-Xdiags:verbose"))
}

javadoc {
isFailOnError = false
val options = options as StandardJavadocDocletOptions
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything
options.encoding = Charsets.UTF_8.name()
options.overview = "src/main/javadoc/overview.html"
options.isDocFilesSubDirs = true
options.tags("apiNote:a:API Note:", "implNote:a:Implementation Note:", "implSpec:a:Implementation Requirements:")
options.use()
}

processResources {
filteringCharset = Charsets.UTF_8.name() // We want UTF-8 for everything
filteringCharset = Charsets.UTF_8.name()
}

test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
}

publishing {
publications {
create<MavenPublication>("maven") {
groupId = "com.github.milkdrinkers"
groupId = "${rootProject.group}"
artifactId = "customblockdata"
version = "${rootProject.version}"

Expand Down Expand Up @@ -120,13 +117,21 @@ publishing {

repositories {
maven {
name = "milkdrinkers"
name = "releases"
url = uri("https://maven.athyrium.eu/releases")
credentials {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_PASSWORD")
}
}
maven {
name = "snapshots"
url = uri("https://maven.athyrium.eu/snapshots")
credentials {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_PASSWORD")
}
}
}
}

Expand Down

0 comments on commit b68b023

Please sign in to comment.