Skip to content

Commit

Permalink
feat: create a snapshot workflow (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
grablack committed Apr 11, 2024
1 parent 20644c8 commit 5bc02da
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 12 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/release-snapshots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Snapshot Release
on:
workflow_dispatch: {}
env:
SIGNING_KEY_FILE_PATH: /home/runner/secretKey.gpg

jobs:
lint:
uses: ./.github/workflows/lint.yml

test:
uses: ./.github/workflows/release-test.yml

build:
uses: ./.github/workflows/build.yml
secrets:
SIGNING_KEY_FILE: ${{ secrets.SIGNING_KEY_FILE }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}

# after build and unit tests are finished, publish all modules at once
# to help reduce the probability of failure when interacting with sonatype servers
release:
name: Snapshot Release
needs: [lint, test, build]
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
# pulls all commits (needed for semantic release to correctly version)
fetch-depth: '0'
persist-credentials: false

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'microsoft'

- name: Decode Signing Key
uses: ./.github/actions/decode_signing_key_action
with:
signing_key_file: ${{ secrets.SIGNING_KEY_FILE }}
signing_file_path: ${{ env.SIGNING_KEY_FILE_PATH }}

- name: Set snapshot environment variable
run: echo "USE_SNAPSHOT=true" >> $GITHUB_ENV

- name: Install Semantic Release Dependencies
run: npm install

- name: GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
SIGNING_KEY_FILE: ${{ env.SIGNING_KEY_FILE_PATH }}
run: npx semantic-release@21

- name: Publish to Maven
uses: ./.github/actions/publish_all_modules
with:
sonatype_user: ${{ secrets.SONATYPE_SDKS_NEXUS_USERNAME }}
sonatype_password: ${{ secrets.SONATYPE_SDKS_NEXUS_PASSWORD }}
signing_key_id: ${{ secrets.SIGNING_KEY_ID }}
signing_key_password: ${{ secrets.SIGNING_KEY_PASSWORD }}
signing_key_file: ${{ env.SIGNING_KEY_FILE_PATH }}
68 changes: 68 additions & 0 deletions .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Test Release
on: [workflow_dispatch, workflow_call]

concurrency:
group: test-${{ github.event.number }}
cancel-in-progress: true

jobs:
test_unit:
name: Unit Tests
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'microsoft'
cache: gradle

- name: Run Unit Tests
run: ./gradlew testReleaseUnitTest
continue-on-error: false

test_unit_coverage:
name: Unit Tests Coverage
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'microsoft'
cache: gradle

- name: Run Unit Tests Coverage
run: ./gradlew koverXmlReportDebug

test_instrumentation:
name: Instrumentation Tests
runs-on: macos-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'microsoft'
cache: gradle

- name: Run Instrumentation Tests
uses: ReactiveCircus/android-emulator-runner@v2
with:
api-level: 23
target: google_apis
arch: x86_64
script: ./gradlew connectedCheck --info
continue-on-error: true
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
uses: ./.github/workflows/lint.yml

test:
uses: ./.github/workflows/test.yml
uses: ./.github/workflows/release-test.yml

build:
uses: ./.github/workflows/build.yml
Expand Down Expand Up @@ -44,6 +44,9 @@ jobs:
signing_key_file: ${{ secrets.SIGNING_KEY_FILE }}
signing_file_path: ${{ env.SIGNING_KEY_FILE_PATH }}

- name: Set snapshot environment variable
run: echo "USE_SNAPSHOT=false" >> $GITHUB_ENV

- name: Install Semantic Release Dependencies
run: npm install

Expand Down
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import org.jmailen.gradle.kotlinter.tasks.FormatTask

buildscript {
ext.modules = [
// TODO: How are we changing the versionName in the gradle files during release?
"sdkVersionCode" : 10000,
"sdkVersionName" : "1.0.0-alpha.00-SNAPSHOT",
"sdkVersionName" : "1.0.0-alpha.03",
"androidMinSdkVersion": 23,
"androidTargetVersion": 34
]
Expand Down Expand Up @@ -61,8 +59,11 @@ tasks.register('changeReleaseVersion') {
doLast {
def topLevelGradleFile = file('./build.gradle')
def topLevelGradleFileText = topLevelGradleFile.getText('UTF-8')
def useSnapshot = System.getenv('USE_SNAPSHOT')
def snapshotParam = useSnapshot == "true" || useSnapshot == true ? "-SNAPSHOT" : ""

def updatedScript =
topLevelGradleFileText.replaceFirst(/("sdkVersionName"\s*: )".*",/, '$1"' + versionParam + '",')
topLevelGradleFileText.replaceFirst(/("sdkVersionName"\s*: )".*",/, '$1"' + versionParam + snapshotParam + '",')
topLevelGradleFile.write(updatedScript, 'UTF-8')
}
}
6 changes: 3 additions & 3 deletions gradle/gradle-publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ afterEvaluate {
}
}
repositories {
maven {
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
}
maven {
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ android {
defaultConfig {
minSdkVersion modules.androidMinSdkVersion
targetSdkVersion modules.androidTargetVersion

// TODO: Are versionCode and versionName needed for libraries here?
versionCode modules.sdkVersionCode
versionName modules.sdkVersionName
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
testInstrumentationRunnerArguments clearPackageData: 'true'
testInstrumentationRunnerArguments clearPackageData: 'true'
consumerProguardFiles 'consumer-rules.pro'

buildConfigField('String', 'INTEGRATION_TYPE', "\"NATIVE_ANDROID\"")
Expand Down

0 comments on commit 5bc02da

Please sign in to comment.