Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release workflow fix #22

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: 'gradle'
directory: '/'
schedule:
interval: 'daily'
52 changes: 52 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ env:

on:
workflow_dispatch:
inputs:
release:
type: boolean
default: false
description: Whether to make a release
pull_request:
push:
paths-ignore:
Expand All @@ -19,3 +24,50 @@ jobs:
- name: Gradle Build and Test
run: |
./gradlew build test --info --stacktrace

- name: VERSION file changed
id: version-file-changed
uses: tj-actions/changed-files@v42
with:
files: VERSION

- name: Should make release?
if: |
github.ref == 'refs/heads/main' &&
((github.event.inputs.release && github.event_name == 'workflow_dispatch') ||
(github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.version-file-changed.outputs.any_changed == 'true'))
run: echo make_release=true >> "$GITHUB_ENV"

- name: Get version (release)
if: env.make_release
run: |
export VERSION="$(head VERSION)"
echo version="$VERSION" >> "$GITHUB_ENV"

- name: Release (GitHub)
if: env.make_release
id: github_release
uses: softprops/action-gh-release@v1
with:
name: ${{ env.version }}
tag_name: ${{ env.version }}

- name: Prepare PGP Keyring file
if: env.make_release
env:
GPG_KEY_CONTENTS: ${{ secrets.GPG_KEY_CONTENTS }}
run: |
echo "${GPG_KEY_CONTENTS}" | base64 -d > signing-key.gpg
shell: bash

- name: Publish to Maven Central
if: env.make_release
run: |
./gradlew publishReleasePublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository --info --stacktrace
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}

45 changes: 0 additions & 45 deletions .github/workflows/release.yml

This file was deleted.

5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Releases

To make a release, make a pull request that bumps the `VERSION` file.

The release workflow will run on merge.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.9.2
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.time.Duration

buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2' }
Expand Down Expand Up @@ -99,4 +101,8 @@ nexusPublishing {
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
transitionCheckOptions {
maxRetries = 120
delayBetween = Duration.ofSeconds(10)
}
}
13 changes: 2 additions & 11 deletions gradle/artifact-settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ ext {
}

def getVersionName() {
def cmd = "git describe --tag --abbrev=0"
def version = cmd.execute().text.trim()
def deducedVersion = isSnapshot() ? getSnapshotVersion(version) : getReleaseVersion(version)
def version = System.getenv('VERSION')
def deducedVersion = isSnapshot() ? getSnapshotVersion(version) : version
project.logger.info("Project version detected: ${deducedVersion}")
return deducedVersion
}
Expand All @@ -30,14 +29,6 @@ def isSnapshot() {
return snapshotProp ? snapshotProp.asBoolean() : false
}

private static def getReleaseVersion(String version) {
if (version && version.length() > 1) {
return version.substring(1)
} else {
return "Unknown"
}
}

private static def getSnapshotVersion(String version) {
def matcher = version =~ /^[v|V](\d+).(\d+)?.*/
def major = (matcher[0][1] as Integer)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ supportAnnotation = "1.0.0"
okhttp3Mockwebserver = "3.12.7"
gson = "2.8.6"

gradleNexus = "1.1.0"
gradleNexus = "1.3.0"

[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
Expand Down
25 changes: 5 additions & 20 deletions gradle/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.secretKeyRingFile"] = "${projectDir}/../signing-key.gpg"
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
p.each { name, value -> ext[name] = value }
} else {
// Use system environment variables
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
}
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
Loading