Skip to content

Commit

Permalink
Adds publishing workflow to publish artifacts and create a github rel…
Browse files Browse the repository at this point in the history
…ease on tag
  • Loading branch information
mattsilber committed Dec 15, 2023
1 parent 09bafc6 commit 4b33677
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 46 deletions.
18 changes: 18 additions & 0 deletions .github/changelog_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"categories": [
{
"title": "## 🔨 Fixes and Improvements",
"labels": [
"bug",
"enhancement"
]
}
],
"ignore_labels": [],
"template": "${{CHANGELOG}}\n---\n${{UNCATEGORIZED}}",
"pr_template": "- ${{TITLE}} (PR: #${{NUMBER}})",
"empty_template": "- no changes",
"label_extractor": [],
"transformers": [],
"exclude_merge_branches": []
}
63 changes: 63 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Publish

on:
push:
tags:
- "*"

jobs:
unit_test:
name: Run Unit Tests
uses: ./.github/workflows/unit-test.yml

publish_to_maven_central:
name: Publish to Maven Central Repository
needs:
- unit_test
runs-on: ubuntu-latest
environment: production
timeout-minutes: 15
steps:
- uses: actions/[email protected]

- name: Publish to Maven Central Staging Repository
env:
LIBRARY_RELEASE_MODE: true
MAVEN_CENTRAL_USER: ${{ secrets.MAVEN_CENTRAL_USER }}
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
RELEASE_SIGNING_KEY_ID: ${{ secrets.RELEASE_SIGNING_KEY_ID }}
RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }}
RELEASE_SIGNING_KEY_PASSWORD: ${{ secrets.RELEASE_SIGNING_KEY_PASSWORD }}
run: ./gradlew scratchoff:publishReleasePublicationToMavenCentralRepository

create_release_for_tag:
name: Create Github Release
needs:
- publish_to_maven_central
runs-on: ubuntu-latest
timeout-minutes: 15
environment: production
steps:
- uses: actions/[email protected]

- name: Generate Github App Token for Release Creation Access
uses: tibdex/[email protected]
id: generate_release_token
with:
app_id: ${{ secrets.APP_RELEASES_APP_ID }}
private_key: ${{ secrets.APP_RELEASES_APP_PRIVATE_KEY }}

- name: Generate Changelog for Release Body
id: generate_changelog
uses: mikepenz/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
configuration: ".github/changelog_config.json"
toTag: ${{ github.sha }}

- name: Create Release For Tag
uses: ncipollo/[email protected]
with:
token: ${{ steps.generate_release_token.outputs.token }}
body: ${{ steps.generate_changelog.outputs.changelog }}
1 change: 1 addition & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
unit_test:
name: Run Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/[email protected]
Expand Down
7 changes: 7 additions & 0 deletions scratchoff/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ android {
returnDefaultValues = true
}
}

publishing {
singleVariant('release') {
withSourcesJar()
withJavadocJar()
}
}
}

dependencies {
Expand Down
56 changes: 10 additions & 46 deletions scratchoff/publishing.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
def localPropertiesFile = new File(project.rootProject.getRootDir(), 'local.properties')

if (!localPropertiesFile.exists()) {
return
}

Properties localProperties = new Properties()
localProperties.load(localPropertiesFile.newDataInputStream())

if (localProperties.getProperty("release_mode", "false") != "true") {
if (System.getenv("LIBRARY_RELEASE_MODE") != "true") {
return
}

Expand All @@ -33,36 +24,6 @@ ext {
mavGitUrl = "https://github.com/jackpocket/android_scratchoff.git"
mavScmConnection = "scm:git:git://github.com:jackpocket/android_scratchoff.git"
mavScmDeveloperConnection = "scm:git:ssh://github.com:jackpocket/android_scratchoff.git"

mavDeploymentRepo = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"

mavenCentralUsername = localProperties.getProperty("mavenCentralUsername")
mavenCentralPassword = localProperties.getProperty("mavenCentralPassword")
}

ext["signing.keyId"] = localProperties.getProperty("signing.keyId")
ext["signing.password"] = localProperties.getProperty("signing.password")
ext["signing.secretKeyRingFile"] = localProperties.getProperty("signing.secretKeyRingFile")

task sourcesJar(type: Jar) {
archiveClassifier.set('sources')
from android.sourceSets.main.java.srcDirs
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))

android.libraryVariants.all { variant ->
if (variant.name == 'release') {
owner.classpath += variant.javaCompileProvider.get().classpath
}
}
}

task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}

afterEvaluate {
Expand All @@ -71,9 +32,6 @@ afterEvaluate {
release(MavenPublication) {
from components.release

artifact sourcesJar
artifact javadocJar

groupId = mavPublishGroupId
artifactId = mavProjectName
version = mavLibraryVersion
Expand Down Expand Up @@ -109,17 +67,23 @@ afterEvaluate {
repositories {
maven {
name = 'mavenCentral'
url = mavDeploymentRepo
url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"

credentials {
username mavenCentralUsername
password mavenCentralPassword
username "${System.getenv("MAVEN_CENTRAL_USER")}"
password "${System.getenv("MAVEN_CENTRAL_PASSWORD")}"
}
}
}
}

signing {
useInMemoryPgpKeys(
System.getenv("RELEASE_SIGNING_KEY_ID"),
System.getenv("RELEASE_SIGNING_KEY"),
System.getenv("RELEASE_SIGNING_KEY_PASSWORD")
)

sign publishing.publications
}
}

0 comments on commit 4b33677

Please sign in to comment.