Skip to content

Commit 9ee4369

Browse files
authored
automated release (#62)
* setup gradle and properties * update gardle and library versions * fix broken tests and compile issues * remove unnecessary libs * update publish setup * replace nexus staging plugin with publish plugin * setup ci release * fix build issue * test auto snapshot * automate release and changelog * add RELEASING.md
1 parent 2bde3f0 commit 9ee4369

File tree

25 files changed

+329
-69
lines changed

25 files changed

+329
-69
lines changed

.github/workflows/release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
snapshot:
10+
runs-on: ubuntu-latest
11+
environment: deployment
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Get tag
15+
id: vars
16+
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
17+
- name: Verify tag
18+
run: |
19+
VERSION=$(grep VERSION_NAME gradle.properties | awk -F= '{ print $2 }' | sed "s/-SNAPSHOT//")
20+
if [ "${{ steps.vars.outputs.tag }}" != "v$VERSION" ]; then {
21+
echo "Tag ${{ steps.vars.outputs.tag }} does not match the package version ($VERSION)"
22+
exit 1
23+
} fi
24+
25+
- name: Grant execute permission for gradlew
26+
run: chmod +x gradlew
27+
- name: cache gradle dependencies
28+
uses: actions/cache@v2
29+
with:
30+
path: |
31+
~/.gradle/caches
32+
~/.gradle/wrapper
33+
key: ${{ runner.os }}-gradle-core-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
34+
restore-keys: |
35+
${{ runner.os }}-gradle-core-
36+
- name: Publush release to sonatype
37+
run: ./gradlew publishToSonatype -Prelease closeAndReleaseSonatypeStagingRepository
38+
env:
39+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
40+
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
41+
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.NEXUS_USERNAME }}
42+
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.NEXUS_PASSWORD }}
43+
SIGNING_PRIVATE_KEY_BASE64: ${{ secrets.SIGNING_PRIVATE_KEY_BASE64 }}
44+
45+
- name: create release
46+
run: |
47+
curl \
48+
-X POST \
49+
-H "Authorization: token $GITHUB_TOKEN" \
50+
https://api.github.com/repos/${{github.repository}}/releases \
51+
-d '{"tag_name": "${{ env.RELEASE_VERSION }}", "name": "${{ env.RELEASE_VERSION }}", "body": "Release of version ${{ env.RELEASE_VERSION }}", "draft": false, "prerelease": false, "generate_release_notes": true}'
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}

.github/workflows/snapshot.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Snapshot
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
snapshot:
9+
runs-on: ubuntu-latest
10+
environment: deployment
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Grant execute permission for gradlew
14+
run: chmod +x gradlew
15+
- name: cache gradle dependencies
16+
uses: actions/cache@v2
17+
with:
18+
path: |
19+
~/.gradle/caches
20+
~/.gradle/wrapper
21+
key: ${{ runner.os }}-gradle-core-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
22+
restore-keys: |
23+
${{ runner.os }}-gradle-core-
24+
- name: Publush snapshot to sonatype
25+
run: ./gradlew publishToSonatype
26+
env:
27+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
28+
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
29+
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.NEXUS_USERNAME }}
30+
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.NEXUS_PASSWORD }}
31+
SIGNING_PRIVATE_KEY_BASE64: ${{ secrets.SIGNING_PRIVATE_KEY_BASE64 }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Analytics-Kotlin
22
[![](https://jitpack.io/v/segmentio/analytics-kotlin.svg)](https://jitpack.io/#segmentio/analytics-kotlin)
33
[![](https://github.com/segmentio/analytics-kotlin/actions/workflows/build.yml/badge.svg)](https://github.com/segmentio/analytics-kotlin/actions)
4-
[![codecov](https://codecov.io/gh/segmentio/analytics-kotlin/branch/master/graph/badge.svg)](https://codecov.io/gh/segmentio/analytics-kotlin)
4+
[![codecov](https://codecov.io/gh/segmentio/analytics-kotlin/branch/main/graph/badge.svg?token=U5FDRBZOXO)](https://codecov.io/gh/segmentio/analytics-kotlin)
55
[![Known Vulnerabilities](https://snyk.io/test/github/segmentio/analytics-kotlin/badge.svg)](https://snyk.io/test/github/segmentio/analytics-kotlin)
66
[![](https://img.shields.io/github/license/segmentio/analytics-kotlin)](https://github.com/segmentio/analytics-kotlin/blob/main/LICENSE)
77

RELEASING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Releasing
2+
=========
3+
4+
1. Create a new branch called `release/X.Y.Z`
5+
2. `git checkout -b release/X.Y.Z`
6+
3. Change the version in `gradle.properties` to your desired release version
7+
4. `git commit -am "Create release X.Y.Z."` (where X.Y.Z is the new version)
8+
5. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version)
9+
6. Upgrade to next version by changing version in `gradle.properties`
10+
7. `git commit -am "Prepare snapshot X.Y.Z-SNAPSHOT"`
11+
8. `git push && git push --tags`
12+
9. Create a PR to merge the new branch into `main`
13+
10. The CI pipeline will recognize the tag and upload, close and promote the artifacts, and generate changelog automatically
14+
15+
Example (stable release)
16+
========
17+
1. Current VERSION_NAME in `gradle.properties` = 1.3.0
18+
2. `git checkout -b release/1.3.1`
19+
3. Change VERSION_NAME = 1.3.1 (next higher version)
20+
4. `git commit -am "Create release 1.3.1"`
21+
5. `git tag -a 1.3.1 -m "Version 1.3.1"`
22+
6. `git push && git push --tags`
23+
7. Change VERSION_NAME = 1.3.2 (next higher version)
24+
8. `git commit -am "Prepare snapshot 1.3.2-SNAPSHOT"`
25+
9. `git push && git push --tags`
26+
10. Merging PR main will create a snapshot release 1.3.2-SNAPSHOT and tag push will create stable release 1.3.1 with auto-generated changelog

android/build.gradle

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ plugins {
66
}
77

88
android {
9-
compileSdkVersion 30
10-
buildToolsVersion "30.0.3"
9+
compileSdkVersion 31
10+
buildToolsVersion "31.0.0"
1111

1212
defaultConfig {
1313
// Required when setting minSdkVersion to 20 or lower
1414
multiDexEnabled true
1515

1616
minSdkVersion 16
17-
targetSdkVersion 30
18-
versionCode 130
19-
versionName "1.3.0"
17+
targetSdkVersion 31
18+
versionCode VERSION_CODE.toInteger()
19+
versionName VERSION_NAME
2020

2121
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2222
consumerProguardFiles "consumer-rules.pro"
@@ -41,6 +41,12 @@ android {
4141
kotlinOptions {
4242
jvmTarget = '1.8'
4343
}
44+
testOptions {
45+
unitTests {
46+
includeAndroidResources = true
47+
}
48+
}
49+
4450
}
4551

4652
dependencies {
@@ -50,11 +56,9 @@ dependencies {
5056
api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
5157
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
5258
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
53-
implementation 'androidx.lifecycle:lifecycle-process:2.3.1'
54-
implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
59+
implementation 'androidx.lifecycle:lifecycle-process:2.4.0'
60+
implementation 'androidx.lifecycle:lifecycle-common-java8:2.4.0'
5561

56-
// STD LIBS
57-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
5862
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
5963

6064
// TESTING
@@ -73,9 +77,10 @@ dependencies {
7377
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.7.2'
7478

7579
// Add Roboelectric dependencies.
76-
testImplementation 'org.robolectric:robolectric:4.5'
80+
testImplementation 'org.robolectric:robolectric:4.7.3'
7781
testImplementation 'androidx.test:core:1.4.0'
7882
}
7983

80-
apply from: rootProject.file('gradle/jitpack-android.gradle')
84+
apply from: rootProject.file('gradle/artifacts-android.gradle')
85+
apply from: rootProject.file('gradle/mvn-publish.gradle')
8186
apply from: rootProject.file('gradle/codecov.gradle')

android/gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
POM_NAME=Segment Kotlin Analytics
2+
POM_ARTIFACT_ID=android
3+
POM_PACKAGING=aar

android/src/test/java/com/segment/analytics/kotlin/android/AndroidContextCollectorTests.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,23 @@ class AndroidContextCollectorTests {
5858
with(event.context) {
5959
assertTrue(this.containsKey("app"))
6060
this["app"]?.jsonObject?.let {
61-
assertEquals("org.robolectric.default", it["name"].asString())
61+
assertEquals("com.segment.analytics.test", it["name"].asString())
6262
assertEquals("undefined", it["version"].asString())
63-
assertEquals("org.robolectric.default", it["namespace"].asString())
63+
assertEquals("com.segment.analytics.test", it["namespace"].asString())
6464
assertEquals("0", it["build"].asString())
6565
}
6666
assertTrue(this.containsKey("device"))
6767
this["device"]?.jsonObject?.let {
6868
assertEquals("unknown", it["id"].asString())
69-
assertEquals("unknown", it["manufacturer"].asString())
69+
assertEquals("robolectric", it["manufacturer"].asString())
7070
assertEquals("robolectric", it["model"].asString())
7171
assertEquals("robolectric", it["name"].asString())
7272
assertEquals("android", it["type"].asString())
7373
}
7474
assertTrue(this.containsKey("os"))
7575
this["os"]?.jsonObject?.let {
7676
assertEquals("Android", it["name"].asString())
77-
assertEquals("4.1.2", it["version"].asString())
77+
assertEquals("12", it["version"].asString())
7878
}
7979
assertTrue(this.containsKey("screen"))
8080
this["screen"]?.jsonObject?.let {

android/src/test/java/com/segment/analytics/kotlin/android/AndroidLifecyclePluginTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ class AndroidLifecyclePluginTests {
275275
every { mockIntent.data } returns Uri.parse("app://track.com/open?utm_id=12345&gclid=abcd&nope=")
276276
val mockActivity = mockk<Activity>()
277277
every { mockActivity.intent } returns mockIntent
278+
every { mockActivity.referrer } returns null
278279
val mockBundle = mockk<Bundle>()
279280

280281
// Simulate activity startup

build.gradle

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = "1.5.31"
3+
ext.kotlin_version = "1.6.0"
44
ext.writeKey = "hAh3QxoRCsQsnyabTLMpWbpxoIN4O2mU"
55
repositories {
66
google()
7-
jcenter()
87
}
98
dependencies {
10-
classpath 'com.android.tools.build:gradle:4.2.2'
9+
classpath 'com.android.tools.build:gradle:7.0.4'
1110
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1211
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
1312

@@ -16,20 +15,17 @@ buildscript {
1615
// NOTE: Do not place your application dependencies here; they belong
1716
// in the individual module build.gradle files
1817
classpath 'com.google.gms:google-services:4.3.10'
19-
20-
// For jitpack publishing of android library
21-
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
2218
}
2319
}
2420

2521
plugins {
2622
id "io.snyk.gradle.plugin.snykplugin" version "0.4"
23+
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
2724
}
2825

2926
allprojects {
3027
repositories {
3128
google()
32-
jcenter()
3329
mavenCentral()
3430
maven { url 'https://jitpack.io' }
3531
maven { url "https://kotlin.bintray.com/kotlinx" }
@@ -48,4 +44,5 @@ task clean(type: Delete) {
4844
delete rootProject.buildDir
4945
}
5046

47+
apply from: rootProject.file('gradle/promote.gradle')
5148
apply from: rootProject.file('gradle/codecov.gradle')

core/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ test {
1414
}
1515

1616
dependencies {
17-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
1817
// MAIN DEPS
1918
api 'com.github.segmentio:sovran-kotlin:1.2.0'
2019
api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
@@ -29,5 +28,6 @@ dependencies {
2928
testImplementation "org.junit.jupiter:junit-jupiter"
3029
}
3130

32-
apply from: rootProject.file('gradle/jitpack-core.gradle')
31+
apply from: rootProject.file('gradle/artifacts-core.gradle')
32+
apply from: rootProject.file('gradle/mvn-publish.gradle')
3333
apply from: rootProject.file('gradle/codecov.gradle')

0 commit comments

Comments
 (0)