-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (132 loc) · 5.82 KB
/
main.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
name: Android CI
on:
workflow_dispatch:
push:
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get commit details
id: commit_info
run: |
echo $GITHUB_CONTEXT
echo ::set-output name=commit_count::$(git rev-list --count ${{ github.event.before }}..${{ github.event.after }} || echo null)
FILES_CHANGED="$(git diff-tree --no-commit-id --name-status --diff-filter=ADMR -r ${{ github.event.before }} ${{ github.event.after }} || echo null)"
FILES_CHANGED="${FILES_CHANGED//$'A\t'/[A]~ }"
FILES_CHANGED="${FILES_CHANGED//$'D\t'/[D]~ }"
FILES_CHANGED="${FILES_CHANGED//$'M\t'/[M]~ }"
FILES_CHANGED="${FILES_CHANGED//$'R\t'/[R]~ }"
FILES_CHANGED="${FILES_CHANGED//'%'/'%25'}"
FILES_CHANGED="${FILES_CHANGED//$'\n'/'%0A'}"
FILES_CHANGED="${FILES_CHANGED//$'\r'/'%0D'}"
echo ::set-output name=files_changed::$FILES_CHANGED
- name: Send a message about the latest commit
if: "!(github.event_name == 'workflow_dispatch')"
run: |
curl \
-d chat_id=${{ secrets.TELEGRAM_CHAT_ID }} \
-d disable_notification=true \
-d parse_mode=HTML \
-d text=\
"↗️ <b>PUSH</b>%0A\
<b>was made at:</b> ${{ github.repository }}%0A\
<b>by:</b> <u>${{ github.actor }}</u>%0A\
<b>commits pushed:</b> ${{ steps.commit_info.outputs.commit_count }}%0A\
<b>commit message:</b>%0A\
${{ github.event.head_commit.message }}%0A\
%0A\
<b>files changed:</b>%0A\
<pre>${{ steps.commit_info.outputs.files_changed }}</pre>%0A\
%0A\
<b>url:</b> https://github.com/${{ github.repository }}/commit/${{ github.sha }}" \
https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage
- name: set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Copy CI gradle.properties
run: |
mkdir -p ~/.gradle
cp .github/runner-files/ci-gradle.properties ~/.gradle/gradle.properties
- name: Extract debug.keystore
run: |
mkdir -p ~/.android
echo "${{ secrets.DEBUG_KEYSTORE }}" | base64 -d > ~/.android/debug.keystore
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Build debug apk
run: chmod +x gradlew && ./gradlew assembleDebug --stacktrace
- name: Delete previous continuous release
run: |
if git show-ref --tags | egrep -q "refs/tags/continuous"
then
release_query=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s \
https://api.github.com/repos/${{ github.repository }}/releases \
| jq '. | map(select(.tag_name == "continuous"))[0]')
curl -i -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -X DELETE \
https://api.github.com/repos/${{ github.repository }}/releases/assets/$(echo $release_query | jq .assets[0].id)
curl -i -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -X DELETE \
https://api.github.com/repos/${{ github.repository }}/releases/$(echo $release_query | jq .id)
git tag -d continuous
curl -i -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -X DELETE \
https://api.github.com/repos/${{ github.repository }}/git/refs/tags/continuous
sleep 1 #required else next action will fail
else
echo "tag not found"
fi
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: continuous
release_name: continuous-build-r${{ steps.commit_info.outputs.commit_count }}
draft: false
prerelease: true
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./app/build/outputs/apk/debug/app-debug.apk
asset_name: app-debug.apk
asset_content_type: application/zip
- name: Send a message about the release
run: |
curl \
-d chat_id=${{ secrets.TELEGRAM_CHAT_ID }} \
-d disable_notification=true \
-d parse_mode=HTML \
-d text=\
"📱 <b>Debug Apk released</b>%0A\
url: https://github.com/${{ github.repository }}/releases/tag/continuous" \
"https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage"
- name: Send apk to chat
if: contains(github.event.head_commit.message, 'tgapk') || github.event_name == 'workflow_dispatch'
run: |
curl \
-F chat_id=${{ secrets.TELEGRAM_CHAT_ID }} \
-F disable_notification=true \
-F parse_mode=HTML \
-F caption=\
"📱 <b>Debug Apk released</b>" \
-F document=@"./app/build/outputs/apk/debug/app-debug.apk" \
https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendDocument
- name: Send a message if build fails
if: failure()
run: |
curl \
-d chat_id=${{ secrets.TELEGRAM_CHAT_ID }} \
-d disable_notification=true \
-d parse_mode=HTML \
-d text=\
"❌ <b><u>BUILD FAILED!!!</u></b>%0A\
<b>job url:</b> https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
"https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage"