-
Notifications
You must be signed in to change notification settings - Fork 2
160 lines (139 loc) · 4.63 KB
/
ci.yaml
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
name: Android CI
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
inputs:
tag_prefix:
description: "Tag prefix for the release"
required: false
default: "v"
permissions:
contents: write
packages: write
issues: write
deployments: write
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
issues: write
deployments: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up JDK 21 (Zulu)
uses: actions/setup-java@v2
with:
distribution: "zulu"
java-version: "21"
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set execute permission for gradlew
run: chmod +x ./gradlew
- name: Create local.properties
run: |
echo "PRODUCTION_MODE=${{ secrets.PRODUCTION_MODE }}" >> $GITHUB_WORKSPACE/local.properties
echo "API_URL=${{ secrets.API_URL }}" >> $GITHUB_WORKSPACE/local.properties
echo "API_URL_PROD=${{ secrets.API_URL_PROD }}" >> $GITHUB_WORKSPACE/local.properties
echo "ARTICLE_URL=${{ secrets.ARTICLE_URL }}" >> $GITHUB_WORKSPACE/local.properties
- name: Build with Gradle
run: ./gradlew assembleRelease
- name: List output directory
run: ls -R app/build/outputs/apk/release
- name: Upload APK
if: success()
uses: actions/upload-artifact@v2
with:
name: apk-files
path: app/build/outputs/apk/release/*.apk
release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
issues: write
deployments: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0 # Ensures full history is fetched
- name: Download APKs
uses: actions/download-artifact@v2
with:
name: apk-files
path: .
- name: Get latest tag
id: get_latest_tag
run: |
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "${{ github.event.inputs.tag_prefix }}0.0.0")
echo "latest_tag=$latest_tag" >> $GITHUB_ENV
shell: bash
- name: Generate new version
id: generate_version
run: |
latest_tag=${{ env.latest_tag }}
IFS='.' read -r -a version_parts <<< "${latest_tag#${{ github.event.inputs.tag_prefix }}}"
major=${version_parts[0]}
minor=${version_parts[1]}
patch=${version_parts[2]}
new_patch=$((patch + 1))
if [ $new_patch -ge 10 ]; then
new_minor=$((minor + 1))
new_patch=0
new_version="${{ github.event.inputs.tag_prefix }}$major.$new_minor.$new_patch"
else
new_version="${{ github.event.inputs.tag_prefix }}$major.$minor.$new_patch"
fi
echo "new_version=$new_version" >> $GITHUB_ENV
shell: bash
- name: Create new Git tag
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git tag ${{ env.new_version }}
git push origin ${{ env.new_version }}
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
shell: bash
- name: Get commit title
id: get_commit_title
run: |
COMMIT_TITLE=$(git log -1 --pretty=%s)
echo "COMMIT_TITLE=$(echo $COMMIT_TITLE | tr -d '\n' | tr -d '\r')" >> $GITHUB_ENV
shell: bash
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
with:
tag_name: ${{ env.new_version }}
release_name: Release ${{ env.new_version }}
body: ${{ env.COMMIT_TITLE }}
draft: false
prerelease: false
- name: Upload APK to Release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./app-release-unsigned.apk
asset_name: app-release-unsigned.apk
asset_content_type: application/vnd.android.package-archive
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}