-
Notifications
You must be signed in to change notification settings - Fork 13
145 lines (130 loc) · 4.53 KB
/
build.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
name: Android Build CI
on:
push:
branches:
- release
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.bump_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.branchName }}
- name: Cache Android SDK
uses: actions/cache@v2
with:
path: ~/.android
key: ${{ runner.os }}-sdk-${{ hashFiles('**/build.gradle') }}
restore-keys: ${{ runner.os }}-sdk-
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 1.8
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.1.2
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Bump version
id: bump_version
env:
GITHUB_TOKEN: ${{ secrets.JJ }}
commit: ${{ github.event.head_commit.message }}
run: |
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
old="$(git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1))"
echo ${old}
# Extract version components
major=$(echo "${old}" | awk -F. '{print $1}')
minor=$(echo "${old}" | awk -F. '{print $2}')
patch=$(echo "${old}" | awk -F. '{print $3}')
build=$(echo "${old}" | awk -F. '{print $4}')
build=$((build + 1))
# Check commit message for version bump keywords
echo "${commit}"
if echo "${commit}" | grep -q -w "major"; then
major=$((major + 1))
minor=0
patch=0
build=0
elif echo "${commit}" | grep -q -w "minor"; then
minor=$((minor + 1))
patch=0
build=0
elif echo "${commit}" | grep -q -w "patch"; then
patch=$((patch + 1))
build=0
fi
# Construct new version string
new_version="${major}.${minor}.${patch}.${build}"
# Output new version as an environment variable
echo "version=${new_version}" >> "$GITHUB_ENV"
echo "version=${new_version}" >> "$GITHUB_OUTPUT"
echo ${commit}
echo ${new_version}
- name: apk
env:
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
KEY_PATH: ${{ github.workspace }}/${{ secrets.KEY_PATH }}
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
BASE64_STRING: ${{ secrets.KEY_BASE64 }}
GSM: ${{ secrets.GSM }}
new: ${{ env.version }}
run: |
echo "${BASE64_STRING}" | base64 --decode > ${KEY_PATH}
echo "${GSM}" > "./google-services.json"
major=$(echo "${new}" | awk -F. '{print $1}')
minor=$(echo "${new}" | awk -F. '{print $2}')
patch=$(echo "${new}" | awk -F. '{print $3}')
build=$(echo "${new}" | awk -F. '{print $4}')
property_content="majorVersion=${major}\nminorVersion=${minor}\npatchVersion=${patch}\nbuildNumber=${build}"
echo ${property_content}
# Write the property file
echo -e "${property_content}" > version.properties
./gradlew :app:assembleRelease --scan
rm -f ${KEY_PATH}
# attaches the build apks in workflow run page
- uses: actions/upload-artifact@v3
with:
name: builds
path: ${{ github.workspace }}/app/build/outputs/apk/release/*.apk
# attaches the build report in workflow run page
- uses: actions/upload-artifact@v3
with:
name: ${{ github.workspace }}/build-reports
path: ${{ github.workspace }}/build/reports/
release:
name: Release APK
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Download APK from build
uses: actions/download-artifact@v1
with:
name: builds
- name: print file name
env:
ver: ${{ needs.build.outputs.version }}
run: |
echo ${ver}
cd builds
ls
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.JJ }}
with:
tag_name: ${{ needs.build.outputs.version }}
release_name: ${{ needs.build.outputs.version }}
draft: false
prerelease: false
files: ${{ github.workspace }}/builds/*.apk