-
Notifications
You must be signed in to change notification settings - Fork 0
199 lines (176 loc) · 6.1 KB
/
CI_CD.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
name: Build, test and deploy
on:
push:
branches:
- "dev"
# - "main"
pull_request:
branches:
# - "dev"
- "main"
concurrency:
group: ${{ github.event_name }}
env:
CARGO_TERM_COLOR: always
jobs:
build_and_test_bot:
runs-on: ubuntu-latest
environment: ${{ github.event_name == 'pull_request' && 'main' || 'dev' }}
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Download the table
if: github.event_name == 'pull_request'
run: curl -L "docs.google.com/spreadsheets/d/${{ secrets.SHEET_ID }}/gviz/tq?tqx=out:csv&sheet=Ukrainian" -o table.csv
- name: Test and build release
if: github.event_name == 'pull_request'
env:
SHEET_ID: ${{ secrets.SHEET_ID }}
run: cargo test --release && cargo build --release
- name: Test and build debug
if: github.event_name == 'push'
env:
SHEET_ID: ${{ secrets.SHEET_ID }}
run: cargo test && cargo build
- name: Move binary
run: mv target/*/bot target
- uses: actions/upload-artifact@v3
with:
name: executable
path: target/bot
- uses: actions/upload-artifact@v3
if: github.event_name == 'pull_request'
with:
name: table
path: table.csv
build_flutter_apk:
runs-on: ubuntu-latest
defaults:
run:
working-directory: app
steps:
- uses: actions/checkout@v3
- uses: extractions/setup-just@v1
- uses: subosito/flutter-action@v2
with:
channel: "stable"
cache: true
- uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "11"
cache: "gradle"
- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-linux-android, armv7-linux-androideabi, x86_64-linux-android, i686-linux-android
- uses: Swatinem/rust-cache@v2
- uses: baptiste0928/cargo-install@v2
with:
crate: flutter_rust_bridge_codegen
- uses: baptiste0928/cargo-install@v2
with:
crate: cargo-ndk
- uses: baptiste0928/cargo-install@v2
with:
crate: cargo-expand
- run: just && flutter build apk --release
env:
SHEET_ID: ${{ secrets.SHEET_ID }}
# https://github.com/actions/upload-artifact/issues/294
- uses: actions/upload-artifact@v3
with:
name: apk
if-no-files-found: error
path: app/build/app/outputs/flutter-apk/app-release.apk
deploy:
runs-on: [self-hosted]
needs: [build_and_test_bot, build_flutter_apk]
environment: ${{ github.event_name == 'pull_request' && 'main' || 'dev' }}
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: executable
path: bin/bot
- uses: actions/download-artifact@v3
if: github.event_name == 'pull_request'
with:
name: table
- name: Restart bot
env:
TELOXIDE_TOKEN: ${{ secrets.TELOXIDE_TOKEN }}
run: |
docker build -t first_aid_bot:${{ github.event_name == 'pull_request' && 'main' || 'dev' }} .
docker compose -f docker-compose_${{ github.event_name == 'pull_request' && 'main' || 'dev' }}.yml -p ${{ github.event_name == 'pull_request' && 'main' || 'dev' }}_bot up -d
release:
runs-on: ubuntu-latest
needs: [build_and_test_bot, build_flutter_apk]
if: github.event_name == 'pull_request' && startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: table
- uses: actions/download-artifact@v3
with:
name: executable
- uses: actions/download-artifact@v3
with:
name: apk
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
generate_release_notes: true
files: |
app-release.apk
table.csv
first_aid_bot
notify:
runs-on: ubuntu-latest
needs: deploy
if: github.event_name == 'pull_request'
steps:
- uses: actions/download-artifact@v3
with:
name: table
- name: send telegram message on push
uses: appleboy/telegram-action@master
if: always() && github.event_name == 'pull_request' && !contains(needs.*.result, 'failure')
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
document: table.csv
message: |
${{ github.actor }} created commit:
Commit message: ${{ github.event.commits[0].message }}
See changes: https://github.com/${{ github.repository }}/actions/runs/${{github.sha}}
See error: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
Successfully deployed! 🙆
- name: send telegram message on push
uses: appleboy/telegram-action@master
if: always() && github.event_name == 'pull_request' && contains(needs.*.result, 'failure')
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
document: table.csv
message: |
${{ github.actor }} created commit:
Commit message: ${{ github.event.commits[0].message }}
See changes: https://github.com/${{ github.repository }}/actions/runs/${{github.sha}}
See error: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
The commit fails to build or tests have failed! 💣
# It should wait untill all checks will pass
auto-merge:
needs: [build_and_test_bot, build_flutter_apk]
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
pull-requests: write
contents: write
steps:
- uses: fastify/github-action-merge-dependabot@v3
with:
target: minor
github-token: "${{ secrets.GITHUB_TOKEN }}"