-
Notifications
You must be signed in to change notification settings - Fork 54
162 lines (139 loc) · 5.89 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
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
on:
schedule:
- cron: "0 20 * * *"
workflow_dispatch:
name: do-github-release
jobs:
check-app-changes:
runs-on: ubuntu-latest
outputs:
app_changed: ${{ steps.check_app_changes.outputs.app_changed }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
token: ${{secrets.ACTIONS_PAT}}
fetch-depth: 0
- name: Check if app directory changed
id: check_app_changes
run: |
LAST_RELEASE_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "LAST_RELEASE_TAG was $LAST_RELEASE_TAG"
LAST_RELEASE_COMMIT=$(git rev-list -n 1 $LAST_RELEASE_TAG)
echo "LAST_RELEASE_COMMIT was $LAST_RELEASE_COMMIT"
changed_files=$(git diff-tree --no-commit-id --name-only $LAST_RELEASE_COMMIT $GITHUB_SHA | grep '^app' || echo "none")
echo "Changed app files: $changed_files"
if [ "$changed_files" != "none" ]; then
echo "App directory has changed since the last release."
echo "app_changed=true" >> "$GITHUB_OUTPUT"
else
echo "App directory hasn't changed since the last release."
echo "app_changed=false" >> "$GITHUB_OUTPUT"
fi
build-and-release:
runs-on: ubuntu-latest
needs: check-app-changes
if: ${{ needs.check-app-changes.outputs.app_changed == 'true' }}
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: git-action-bot@example.com
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/git-get-release-action@1.2.4
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