-
Notifications
You must be signed in to change notification settings - Fork 5
221 lines (210 loc) · 8.58 KB
/
publish-new-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# By default, GitHub stores build logs and artifacts of the workflow itself for 90 days, which can be customized.
# GitHub automatically creates a GITHUB_TOKEN secret to use in your workflow.
# We can use the it to authenticate in a workflow run like this: ${{ secrets.GITHUB_TOKEN }}.
# refer to https://docs.github.com/en/actions/reference/authentication-in-a-workflow
name: Publish a new release of the library
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
on:
push:
tags:
- v*
# FIXME: setting environment variables here makes them available for all the jobs and actions
env:
RELEASE_STORE_FILE_PATH: ${{ secrets.RELEASE_STORE_FILE_PATH }}
RELEASE_STORE_FILE_CONTENT_BASE_64: ${{ secrets.RELEASE_STORE_FILE_CONTENT_BASE_64 }}
RELEASE_KEY_ALIAS: ${{ secrets.RELEASE_KEY_ALIAS }}
RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }}
RELEASE_STORE_PASSWORD: ${{ secrets.RELEASE_STORE_PASSWORD }}
jobs:
run-unit-tests:
name: Run all unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Run the tests
# Note that we are executing the task on the top-level project (instead of e.g. :piechart:test)
run: ./gradlew test --stacktrace
- name: Upload the test report
uses: actions/upload-artifact@v2
with:
name: unit-test-report
path: |
piechart/build/reports/tests/testReleaseUnitTest/
test/build/reports/tests/testReleaseUnitTest/
run-instrumentation-tests:
name: Run all instrumentation tests
# Should be macos (https://github.com/marketplace/actions/android-emulator-runner)
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
# JUnit 5 tests are skipped on API 25 or lower (https://github.com/mannodermaus/android-junit5)
api-level: [ 29, 30, 31 ]
target: [ default, google_apis ]
arch: [ x86_64 ]
exclude:
# {API 30, default} failed, so exclude this combination
- api-level: 30
target: default
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Run the tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
arch: ${{ matrix.arch }}
profile: Nexus 6
# Note that executing the task on the top-level project may fail in some environments
script: ./gradlew :piechart:connectedCheck --stacktrace
disable-animations: false
- name: Upload the test report
if: always() # Run even if the previous steps failed
uses: actions/upload-artifact@v2
with:
name: instrumentation-test-report
path: |
piechart/build/reports/androidTests/connected/
test/build/reports/androidTests/connected/
generate-code-coverage:
name: Create test coverage report
runs-on: macos-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Run the tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 31
target: google_apis
arch: x86_64
profile: Nexus 6
script: ./gradlew :piechart:connectedCheck :piechart:test --stacktrace
disable-animations: false
# - name: Generate code coverage
# run: ./gradlew :piechart:jacocoAndroidTestReport --stacktrace
# - name: Make sure coverage is adequate
# run: ./gradlew :piechart:jacocoAndroidCoverageVerification --stacktrace
- name: Upload the report
uses: actions/upload-artifact@v2
with:
name: code-coverage-report
path: piechart/build/reports/coverage/debug/
# NOTE: No need to send coverage report to Codcov because we just send coverage report of the main branch and it is sent by the test workflow
# Either this way...
# - uses: codecov/codecov-action@v1
# with:
# name: Release coverage report # optional
# directory: ./piechart/build/reports/coverage/debug/
# files: ./*.xml
# verbose: false # optional
# fail_ci_if_error: true # optional (default = false)
# Or this way...
# - name: Download the report
# uses: actions/download-artifact@v2
# with:
# name: code-coverage-report
# path: piechart/build/reports/coverage/debug/
# - name: Send the report to Codecov
# run: bash <(curl -s https://codecov.io/bash) -f "piechart/build/reports/coverage/debug/report.xml"
generate-lint:
name: Create lint report
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Run lint
run: ./gradlew lintRelease --stacktrace
- name: Upload the html report
uses: actions/upload-artifact@v2
with:
name: lint-report
path: piechart/build/reports/lint-results-release.html
merge-into-prod:
needs: [ run-unit-tests, run-instrumentation-tests ]
name: Rebase (fast forward) the prod branch onto the main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: emiliopedrollo/auto-merge@v1.2.0
with:
target_branch: 'prod'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-to-repositories:
needs: [ run-unit-tests, run-instrumentation-tests ]
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 }}
SIGNING_SECRET_KEY_RING_FILE_PATH: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE_PATH }}
GPG_KEY_CONTENTS: ${{ secrets.GPG_KEY_CONTENTS }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# GITHUB_ACTOR: automatically set by GitHub (https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables)
name: Publish the artifacts to GitHub Packages and Maven Central
runs-on: ubuntu-latest
# See https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
# and https://docs.github.com/en/actions/reference/authentication-in-a-workflow
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- name: Set up Java
uses: actions/setup-java@v2
with:
java-version: "11"
distribution: "adopt"
- name: Decode the private GPG key file stored in GitHub
run: echo $GPG_KEY_CONTENTS | base64 -di > $SIGNING_SECRET_KEY_RING_FILE_PATH
- name: Publish the package
run: ./gradlew :piechart:publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository :piechart:publishReleasePublicationToGitHubPackagesRepository
create-demo:
name: Generate the demo APK
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Set up Java
uses: actions/setup-java@v2
with:
java-version: "11"
distribution: "adopt"
- name: Decode the keystore file stored in GitHub
run: echo $RELEASE_STORE_FILE_CONTENT_BASE_64 | base64 -di > $RELEASE_STORE_FILE_PATH
- name: Build the APK
run: ./gradlew :demo:assembleRelease --stacktrace
- name: Upload the APK
uses: actions/upload-artifact@v2
with:
name: demo-app
path: test/build/outputs/apk/release/*.apk
create-github-release:
needs: [ publish-to-repositories, create-demo ]
name: Create a new release in the GitHub repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Refer to https://stackoverflow.com/a/69116750 for running Kotlin scripts
- name: Generate the changelog
run: kotlin scripts/generate-github-changelog.main.kts
- name: Download the APK uploaded by previous job
uses: actions/download-artifact@v2
with:
name: demo-app
- name: Rename the apk to something better
run: mv *.apk demo.apk
- name: Create the release
uses: softprops/action-gh-release@v1
with:
body_path: changelog.txt
files: demo.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}