Skip to content

Commit

Permalink
Automate package publishing to Github packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ekigamba committed Oct 3, 2022
1 parent 51256b1 commit 3340360
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ name: Library Snapshot Release
on:
push:
tags:
- library v[0-9]+.[0-9]+.[0-9]+-SNAPSHOT
- library v[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+-SNAPSHOT
- library v[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+-[0-9a-zA-Z]+-SNAPSHOT
- library-v[0-9]+.[0-9]+.[0-9]+-SNAPSHOT
- library-v[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+-SNAPSHOT
- library-v[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+-[0-9a-zA-Z]+-SNAPSHOT
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GITHUB_USERNAME: ${{ github.actor }}
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
release:
Expand Down Expand Up @@ -41,6 +43,9 @@ jobs:
- name: Generate & upload library snapshot artifact AAR (Android Archive) file
run: ./gradlew :library:clean --stacktrace && ./gradlew :library:assembleRelease --stacktrace && ./gradlew :library:publishMavenJavaPublicationToMavenCentralRepository --stacktrace

- name: Generate & upload library snapshot artifact AAR (Android Archive) file to Github Packages
run: ./gradlew :library:publishMavenJavaPublicationToGithubPackagesRepository --stacktrace

- name: Github Release
uses: softprops/action-gh-release@v1
with:
Expand Down
44 changes: 35 additions & 9 deletions .github/workflows/utils.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: Library Snapshot Release
name: Utils Snapshot Release

on:
push:
tags:
- utils v[0-9]+.[0-9]+.[0-9]+-SNAPSHOT
- utils v[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+-SNAPSHOT
- utils v[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+-[0-9a-zA-Z]+-SNAPSHOT
- utils-v[0-9]+.[0-9]+.[0-9]+-SNAPSHOT
- utils-v[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+-SNAPSHOT
- utils-v[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+-[0-9a-zA-Z]+-SNAPSHOT
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GITHUB_USERNAME: ${{ github.actor }}
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
release:
Expand All @@ -31,16 +33,40 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 11


- name: Create local.properties file
run: touch local.properties && echo "mapbox.repo.token=${{ secrets.MAPBOX_SDK_REPO_TOKEN }}" >> local.properties

- name: Print Java version
run: java -version

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Run unit tests with Gradle
run: ./gradlew :utils:clean :utils:testDebugUnitTest --stacktrace

- name: Generate & upload library snapshot artifact AAR (Android Archive) file
- name: Git show commit count
run: git fetch origin master && git rev-list --first-parent --count origin/master

- name: Download Robolectric deps
run: chmod +x download-robolectric-deps.sh && ./download-robolectric-deps.sh

- name: Clean project
run: ./gradlew clean --stacktrace

- name: Build project skipping tests
run: ./gradlew build -x test --stacktrace

- name: Run Instrumented Tests manually
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 22
script: ./gradlew :utils:connectedDebug --stacktrace

- name: Generate & upload utils snapshot artifact AAR (Android Archive) file to Sonatype
run: ./gradlew :utils:clean --stacktrace && ./gradlew :utils:assembleRelease --stacktrace && ./gradlew :utils:publishMavenJavaPublicationToMavenCentralRepository --stacktrace

- name: Generate & upload utils snapshot artifact AAR (Android Archive) file to Github Packages
run: ./gradlew :utils:publishMavenJavaPublicationToGithubPackagesRepository --stacktrace

- name: Github Release
uses: softprops/action-gh-release@v1
with:
Expand Down
7 changes: 4 additions & 3 deletions publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def getOSSRHRepositoryUsername() {
}

def getGithubPublishUsername() {
return hasProperty('githubUsername') ? githubUsername: ""
return hasProperty('githubUsername') ? githubUsername : System.getenv("GITHUB_USERNAME") != null ? System.getenv("GITHUB_USERNAME") : ""
}

def getGithubPackagesAccessToken() {
return hasProperty('githubAccessToken') ? githubAccessToken: ""
return hasProperty('githubAccessToken') ? githubAccessToken : System.getenv("GITHUB_ACCESS_TOKEN") != null ? System.getenv("GITHUB_ACCESS_TOKEN") : ""
}

def getDate() {
Expand Down Expand Up @@ -163,10 +163,11 @@ publishing {
}

signing {
required !version.contains("SNAPSHOT")
sign(publishing.publications['mavenJava'])
}

artifacts {
archives sourceJar
archives javadocJar
}
}
2 changes: 1 addition & 1 deletion utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
apply plugin: 'jacoco'

version '0.9.0'
version '0.9.1-PUBT-SNAPSHOT'
project.version = this.version


Expand Down

0 comments on commit 3340360

Please sign in to comment.