This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 279
91 lines (78 loc) · 4.25 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
name: Build, Deploy
on: [ push, pull_request ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "zulu"
cache: gradle
- name: Generate keystore.properties
if: ${{ github.event_name != 'pull_request' || github.ref_type == 'tag' }}
run: |
if [ -n "${{ secrets.RELEASEKEYPASSWORD }}" ]; then
echo ${{ secrets.KEYSTORE }} | base64 --decode > ${{ vars.RELEASE_KEYSTORE }}
echo keystore.file="${{ vars.RELEASE_KEYSTORE }}" >> keystore.properties
echo keystore.password="${{ secrets.RELEASESTOREPASSWORD }}" >> keystore.properties
echo keystore.key.alias="${{ vars.RELEASE_KEY_ALIAS }}" >> keystore.properties
echo keystore.key.password="${{ secrets.RELEASEKEYPASSWORD }}" >> keystore.properties
fi
- name: Setup Gradle
uses: gradle/gradle-build-action@v3
with:
gradle-home-cache-cleanup: true
cache-read-only: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/4.0-dev' }}
- name: Build with Gradle
run: ./gradlew assembleRelease
- name: Read Output Metadata
id: read_output_metadata
uses: juliangruber/read-file-action@v1
with:
path: ./app/build/outputs/apk/release/output-metadata.json
trim: true
- name: Upload Release Package
env:
version_code: ${{ fromJSON(steps.read_output_metadata.outputs.content).elements[0].versionCode }}
version_name: ${{ fromJSON(steps.read_output_metadata.outputs.content).elements[0].versionName }}
uses: actions/upload-artifact@v4
with:
name: "release-${{ env.version_name }}(${{ env.version_code }})"
path: ./app/build/outputs/apk/release
- name: Upload Mapping
uses: actions/upload-artifact@v4
with:
name: mapping
path: ./app/build/outputs/mapping/release
- name: Post to channel
if: contains(github.event.head_commit.message, '[skip post]') == false && github.event_name != 'pull_request'
env:
CHANNEL_ID: ${{ secrets.CHANNEL_DEV_ID }}
BOT_TOKEN: ${{ secrets.BOT_DEV_TOKEN }}
COMMIT_URL: ${{ github.event.head_commit.url }}
COMMIT_MESSAGE: |+
```
${{ github.event.head_commit.message }}
```
构建分支:[${{ github.ref }}](${{ github.server_url }}/${{ github.repository }}/tree/${{ github.ref_name }})
构建版本:[${{ github.sha }}]("$COMMIT_URL")
ACTION_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ -n "$BOT_TOKEN" ] && [ -n "$CHANNEL_ID" ]; then
export RELEASE=$(find ./app/build/outputs/apk/release -name "*.apk")
ESCAPED=`python3 -c 'import json,os,urllib.parse; msg = json.dumps(os.environ["COMMIT_MESSAGE"]); print(urllib.parse.quote(msg if len(msg) <= 1024 else json.dumps(os.environ["COMMIT_URL"])))'`
curl -v "https://api.telegram.org/bot${BOT_TOKEN}/sendMediaGroup?chat_id=${CHANNEL_ID}&media=%5B%7B%22type%22%3A%22document%22%2C%22media%22%3A%22attach%3A%2F%2Frelease%22%2C%22parse_mode%22%3A%22MarkdownV2%22%2C%22caption%22%3A${ESCAPED}%7D%5D&reply_markup=%7B%22inline_keyboard%22%3A%20%5B%5B%7B%22text%22%3A%20%22%E5%9C%A8+Github+%E4%B8%8A%E6%9F%A5%E7%9C%8B%22%2C%20%22url%22%3A%20${ACTION_URL}%7D%5D%5D%7D" -F release="@$RELEASE"
fi
- name: Upload Mapping to App Center
if: ${{ github.event_name != 'pull_request' || github.ref_type == 'tag' }}
env:
version_code: ${{ fromJSON(steps.read_output_metadata.outputs.content).elements[0].versionCode }}
version_name: ${{ fromJSON(steps.read_output_metadata.outputs.content).elements[0].versionName }}
uses: saurav-aggarwal/[email protected]
with:
token: ${{ secrets.APP_CENTER_TOKEN }}
command: appcenter crashes upload-mappings -c ${{ env.version_code }} -n ${{ env.version_name }} -m ./app/build/outputs/mapping/release/mapping.txt -a ${{ secrets.APP_CENTER_APP }}