-
Notifications
You must be signed in to change notification settings - Fork 54
132 lines (114 loc) · 4.68 KB
/
github-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
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'app/**'
name: do-github-release
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
token: ${{secrets.ACTIONS_PAT}}
# Uses semantic commits to automate version bumping.
# No scope or "fix:" = PATCH, "feat:" or "minor:" = MINOR, "BREAKING CHANGE:", "major:", or fix/feat with appended "!" = MAJOR
# Additional details: https://www.conventionalcommits.org/en/v1.0.0/
- name: Increment version
run: |
#!/bin/bash
COMMIT_MSG=$(git log -1 --pretty=format:"%b" || git log -1 --pretty=format:"%B")
source version.properties
BUMP_TYPE="patchVersion"
buildNumber=${{ github.run_number }}
if [[ $COMMIT_MSG == *"BREAKING CHANGE"* || $COMMIT_MSG == *"!"* || $COMMIT_MSG == *"major:"* ]]; then
majorVersion=$((majorVersion + 1))
minorVersion=0
patchVersion=0
BUMP_TYPE="majorVersion"
elif [[ $COMMIT_MSG == *"feat:"* || $COMMIT_MSG == *"minor:"* ]]; then
minorVersion=$((minorVersion + 1))
patchVersion=0
BUMP_TYPE="minorVersion"
else
patchVersion=$((patchVersion + 1))
fi
echo "majorVersion=$majorVersion" > version.properties
echo "minorVersion=$minorVersion" >> version.properties
echo "patchVersion=$patchVersion" >> version.properties
echo "buildNumber=$buildNumber" >> version.properties
VERSION=$majorVersion.$minorVersion.$patchVersion.$buildNumber
RELEASE=$majorVersion.$minorVersion
echo "COMMIT_MSG=$COMMIT_MSG" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "RELEASE=$RELEASE" >> $GITHUB_ENV
echo "BUMP_TYPE=$BUMP_TYPE" >> $GITHUB_ENV
- name: Commit version changes
uses: EndBug/add-and-commit@v7
with:
add: 'version.properties'
message: Bump ${{ env.BUMP_TYPE }}
author_email: [email protected]
author_name: Git Action Bot
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build APK
run: ./gradlew app:assembleRelease
- name: Sign APK
uses: r0adkll/sign-android-release@v1
with:
releaseDirectory: app/build/outputs/apk/release
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
alias: ${{ secrets.ALIAS }}
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.KEY_PASSWORD }}
- name: Upload built APK
uses: actions/upload-artifact@v2
with:
name: Signed APK
path: app/build/outputs/
- name: Get matching release
uses: cardinalby/[email protected]
id: matching_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
releaseName: v${{ env.RELEASE }}
doNotFailIfNotFound: 'true'
- name: Delete matching release if exists
if: steps.matching_release.outputs.id != ''
run: |
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/${{ steps.matching_release.outputs.id}}"
# Updates the latest release if just a new patch, drafts a new prerelease if major or minor version has changed
- name: Make github release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
release_name: v${{ env.RELEASE }}
tag: ${{ env.VERSION }}
file: app/build/outputs/apk/release/app-release-unsigned-signed.apk
asset_name: Field-Book-v${{ env.RELEASE }}.apk
overwrite: ${{ env.BUMP_TYPE == 'patchVersion' }}
prerelease: ${{ env.BUMP_TYPE != 'patchVersion' }}
body: |
${{ steps.matching_release.outputs.body }}
${{ env.COMMIT_MSG }}
# - name: Release APK to Play Store
# uses: r0adkll/upload-google-play@v1
# with:
# serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
# packageName: com.fieldbook.tracker
# releaseFiles: app/build/outputs/apk/release/app-release-unsigned-signed.apk
# track: alpha