Repository navigation
157 lines (154 loc) · 7.69 KB
/
Copy pathcommit_ci.yml
File metadata and controls
157 lines (154 loc) · 7.69 KB
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
name: Automatic Build on Commit
on:
workflow_dispatch:
push:
branches: [ master ]
paths-ignore:
- '**.md'
- '**.txt'
- '.github/**'
- '!.github/workflows/**'
permissions:
contents: read
actions: read
jobs:
build:
name: Build CI
if: ${{ success() }}
runs-on: ubuntu-latest
env:
APK_OUTPUT_PATH: 'app/build/outputs/apk'
TG_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TG_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Prepare Commit Changelog
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const branch = process.env.GITHUB_REF_NAME;
const sha = context.sha;
let previousSha;
// Failed builds must not hide changes from the next successful build.
for await (const { data } of github.paginate.iterator(github.rest.actions.listWorkflowRuns, {
owner, repo, workflow_id: 'commit_ci.yml', branch, status: 'success', per_page: 100
})) {
for (const run of data) {
if (run.run_number >= Number(process.env.GITHUB_RUN_NUMBER)) continue;
// Rewritten history may no longer contain an old CI commit.
const exists = await exec.getExecOutput('git', ['cat-file', '-e', `${run.head_sha}^{commit}`], {
ignoreReturnCode: true, silent: true
});
if (exists.exitCode !== 0) continue;
const ancestor = await exec.getExecOutput('git', ['merge-base', '--is-ancestor', run.head_sha, sha], {
ignoreReturnCode: true, silent: true
});
if (ancestor.exitCode === 0) {
previousSha = run.head_sha;
break;
}
if (ancestor.exitCode !== 1) throw new Error(`Cannot check CI commit ${run.head_sha}`);
}
if (previousSha) break;
}
// Without a successful ancestor build, include all reachable commits.
const range = previousSha ? `${previousSha}..${sha}` : sha;
const count = await exec.getExecOutput('git', ['rev-list', '--count', range], { silent: true });
const log = await exec.getExecOutput('git', ['log', '-7', '--format=%B', range], { silent: true });
const authorResult = await exec.getExecOutput('git', ['show', '-s', '--format=%an', sha], { silent: true });
const author = authorResult.stdout.trim();
const repoUrl = `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}`;
const commitUrl = `${repoUrl}/commit/${sha}`;
const changelogUrl = `${repoUrl}/${previousSha ? `compare/${previousSha}...${sha}` : `commits/${sha}`}`;
const label = previousSha ? `${previousSha.slice(0, 7)}...${sha.slice(0, 7)}` : sha.slice(0, 7);
const header = 'New push to GitHub!';
let body = log.stdout.trim().replace(/\n{2,}/g, '\n') || 'No new commits.';
const fullChangelog = Number(count.stdout.trim()) > 1;
const fullText = fullChangelog ? `Full Changelog: ${label}` : 'See commit detail here';
// Count visible text, including code-block newlines, without Markdown markup or link URLs.
const footer = `\n\nby ${author}\n${fullText}`;
const maxLength = 1024 - `${header}\n${footer}`.length;
if (body.length > maxLength)
body = body.slice(0, maxLength - 1).replace(/[\uD800-\uDBFF]$/, '') + '…';
const escapedBody = body.replace(/[\\`]/g, '\\$&');
const escapedAuthor = author.replace(/[\\`]/g, '\\$&');
let caption = `New push to GitHub\\!\n\`\`\`\n${escapedBody}\n\`\`\`by \`${escapedAuthor}\``;
if (fullChangelog)
caption += `\nFull Changelog: [${label.replace(/\./g, '\\.')}](${changelogUrl})`;
else
caption += `\nSee commit detail [here](${commitUrl})`;
core.exportVariable('ESCAPED', encodeURIComponent(JSON.stringify(caption)));
- name: Prepare GitHub Env
run: |
GITHUB_SHA=${{ github.sha }}
GITHUB_CI_COMMIT_ID=${GITHUB_SHA:0:7}
echo "GITHUB_CI_COMMIT_ID=$GITHUB_CI_COMMIT_ID" >> $GITHUB_ENV
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1
with:
cmake-version: '3.22.1'
- name: Prepare Java 21
uses: actions/setup-java@v4
with:
java-version: 21
java-package: jdk
distribution: 'temurin'
cache: 'gradle'
- name: Cache Gradle Dependencies
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
!~/.gradle/caches/build-cache-*
key: gradle-deps-core-${{ hashFiles('**/build.gradle.kts') }}
restore-keys: |
gradle-deps
- name: Cache Gradle Build
uses: actions/cache@v3
with:
path: |
~/.gradle/caches/build-cache-*
key: gradle-builds-core-${{ github.sha }}
restore-keys: |
gradle-builds
- name: Build with Gradle
run: |
./gradlew :app:assembleDebug
./gradlew :app:assembleRelease
echo "MODERN_DEBUG_APK_PATH=$(find ${{ env.APK_OUTPUT_PATH }}/modern/debug -name '*.apk')" >> $GITHUB_ENV
echo "MODERN_RELEASE_APK_PATH=$(find ${{ env.APK_OUTPUT_PATH }}/modern/release -name '*.apk')" >> $GITHUB_ENV
echo "LEGACY_DEBUG_APK_PATH=$(find ${{ env.APK_OUTPUT_PATH }}/legacy/debug -name '*.apk')" >> $GITHUB_ENV
echo "LEGACY_RELEASE_APK_PATH=$(find ${{ env.APK_OUTPUT_PATH }}/legacy/release -name '*.apk')" >> $GITHUB_ENV
- name: Upload Artifacts (Modern Debug)
uses: actions/upload-artifact@v4
with:
path: ${{ env.MODERN_DEBUG_APK_PATH }}
name: ColorOSNotifyIcon-modern-debug-${{ github.sha }}
- name: Upload Artifacts (Modern Release)
uses: actions/upload-artifact@v4
with:
path: ${{ env.MODERN_RELEASE_APK_PATH }}
name: ColorOSNotifyIcon-modern-release-${{ github.sha }}
- name: Upload Artifacts (Legacy Debug)
uses: actions/upload-artifact@v4
with:
path: ${{ env.LEGACY_DEBUG_APK_PATH }}
name: ColorOSNotifyIcon-legacy-debug-${{ github.sha }}
- name: Upload Artifacts (Legacy Release)
uses: actions/upload-artifact@v4
with:
path: ${{ env.LEGACY_RELEASE_APK_PATH }}
name: ColorOSNotifyIcon-legacy-release-${{ github.sha }}
- name: Post Artifacts to Telegram
run: |
# Telegram limits one request to 50MB, so debug and release APKs are sent separately
curl -v "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMediaGroup?chat_id=${TG_CHAT_ID}&media=%5B%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2Fmodern_debug%22%7D%2C%20%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2Flegacy_debug%22%7D%5D" \
-F modern_debug="@${{ env.MODERN_DEBUG_APK_PATH }}" \
-F legacy_debug="@${{ env.LEGACY_DEBUG_APK_PATH }}"
curl -v "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMediaGroup?chat_id=${TG_CHAT_ID}&media=%5B%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2Fmodern_release%22%7D%2C%20%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2Flegacy_release%22%2C%22parse_mode%22%3A%22MarkdownV2%22%2C%22caption%22%3A${ESCAPED}%7D%5D" \
-F modern_release="@${{ env.MODERN_RELEASE_APK_PATH }}" \
-F legacy_release="@${{ env.LEGACY_RELEASE_APK_PATH }}"