-
Notifications
You must be signed in to change notification settings - Fork 4
172 lines (164 loc) · 7.76 KB
/
release-tauri.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
160
161
162
163
164
165
166
167
168
169
170
171
172
name: 'publish tauri'
on:
workflow_dispatch:
push:
branches:
- release_tauri
env:
CUSTOM_RELEASE_ASSET_NAME: 'CeobeCanteen'
UBUNTU_PRODUCT_NAME: 'ceobe-canteen'
MACOS_PRODUCT_NAME: ''
jobs:
create-release:
permissions:
contents: write
runs-on: ubuntu-20.04
outputs:
release_id: ${{ steps.create-release.outputs.result }}
steps:
- uses: actions/checkout@v3
- name: setup node
uses: actions/setup-node@v3
with:
node-version: 16
- name: get version
run: echo "PACKAGE_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
- name: create release
id: create-release
uses: actions/github-script@v6
with:
script: |
const fs = require('fs')
const { data } = await github.rest.repos.createRelease({
tag_name: `tauri-v${process.env.PACKAGE_VERSION}-build.${{ github.run_number }}.${{ github.run_attempt }}`,
target_commitish: '${{ github.sha }}',
name: `CeobeCanteenDesktop v${process.env.PACKAGE_VERSION}`,
body: `小刻食堂桌面端 v${process.env.PACKAGE_VERSION} 发布了`,
prerelease: false,
draft: true, owner: context.repo.owner, repo: context.repo.repo,
})
return data.id
build-tauri:
needs: create-release
permissions:
contents: write
strategy:
fail-fast: true
matrix:
platform: [macos-latest, ubuntu-20.04, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- name: setup node
uses: actions/setup-node@v3
with:
node-version: 18
- name: install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-20.04'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: update tauri build config
uses: actions/github-script@v6
with:
script: |
let cfg = require('./src-tauri/tauri.conf.json');
cfg.package.version = require('./package.json').version;
if ('${{ matrix.platform }}'.startsWith('ubuntu')) {
// change product name for ubuntu
if (process.env.UBUNTU_PRODUCT_NAME) cfg.package.productName = process.env.UBUNTU_PRODUCT_NAME;
} else if ('${{ matrix.platform }}'.startsWith('macos')) {
// change product name for macos
if (process.env.MACOS_PRODUCT_NAME) cfg.package.productName = process.env.MACOS_PRODUCT_NAME;
// only work for release
if ('${{ github.ref_name }}'.startsWith('release')) {
// add sign for macos
const APPLE_CERTIFICATE = `${{ secrets.APPLE_CERTIFICATE }}`;
if (APPLE_CERTIFICATE.length > 8) {
core.exportVariable("APPLE_CERTIFICATE", APPLE_CERTIFICATE);
core.exportVariable("APPLE_CERTIFICATE_PASSWORD", `${{ secrets.APPLE_CERTIFICATE_PASSWORD }}`);
core.exportVariable("APPLE_SIGNING_IDENTITY", `${{ secrets.APPLE_SIGNING_IDENTITY }}`);
core.exportVariable("APPLE_ID", `${{ secrets.APPLE_ID }}`);
core.exportVariable("APPLE_PASSWORD", `${{ secrets.APPLE_PASSWORD }}`);
core.notice("符合签名条件", {title:"本次构建将会对MacOS目标进行签名"});
} else {
core.warning("未提供有效证书", {title:"本次构建将不会对MacOS目标进行签名"});
}
} else {
core.warning("当前构建源不是release分支", {title:"本次构建将不会对MacOS目标进行签名"});
}
} else if ('${{ matrix.platform }}'.startsWith('windows')) {
// change package version for windows
const versionMatch = cfg.package.version.match('^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){2}(0|6[0-5][0-5][0-3][0-5]|[1-5][0-9][0-9][0-9][0-9]|[1-9][0-9]{0,3})');
if (!versionMatch || !versionMatch[0]) {
throw new Error('package.json中的版本号无法提取成Windows所需版本号');
}
cfg.package.version = versionMatch[0];
}
require('fs').writeFileSync('./src-tauri/tauri.conf.json', JSON.stringify(cfg));
- name: install frontend dependencies
run: npm ci
- uses: tauri-apps/tauri-action@v0
id: tauri-action-build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: upload release
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARTIFACT_PATHS: ${{ steps.tauri-action-build.outputs.artifactPaths }}
with:
script: |
const fs = require('fs'), path = require('path');
const { productName, version: tauriVersion } = require('./src-tauri/tauri.conf.json').package;
const productVersion = require('./package.json').version;
const artifactPaths = JSON.parse(process.env.ARTIFACT_PATHS);
async function transformAssetName(assetPath) {
if (assetPath.endsWith('.app')) {
if (!fs.existsSync(`${assetPath}.tar.gz`)) require('child_process').execSync(`tar czf ${assetPath}.tar.gz -C "${path.dirname(assetPath)}" "${path.basename(assetPath)}"`, {stdio: 'inherit'});
assetPath += '.tar.gz';
}
const basename = path.basename(assetPath);
const extensions = ['.app.tar.gz.sig','.app.tar.gz','.dmg','.AppImage.tar.gz.sig','.AppImage.tar.gz','.AppImage','.deb','.msi.zip.sig','.msi.zip','.msi','.nsis.zip.sig','.nsis.zip','.exe'];
const ext = extensions.find(s => basename.includes(s)) || path.extname(assetPath);
const filename = basename.replace(`_${tauriVersion}`, '').replace(productName, `${process.env.CUSTOM_RELEASE_ASSET_NAME}_${productVersion}`).replace(ext, '');
let extraInfo = '';
if (assetPath.includes(`${path.sep}debug${path.sep}`)) extraInfo += '-debug';
if (ext === '.app.tar.gz.sig' || ext === '.app.tar.gz') {
const arch = assetPath.includes('universal-apple-darwin') ? 'universal' : (assetPath.includes('aarch64-apple-darwin') ? 'aarch64' : (process.arch === 'arm64' ? 'aarch64' : 'x64'));
extraInfo += `_${arch}`;
}
return { assetName: `${filename}${extraInfo}${ext}`, newAssetPath: assetPath };
}
for (assetPath of artifactPaths) {
const { assetName, newAssetPath } = await transformAssetName(assetPath);
console.log('uploading ' + newAssetPath + ' as ' + assetName);
await github.rest.repos.uploadReleaseAsset({
name: assetName,
data: fs.readFileSync(newAssetPath),
release_id: '${{ needs.create-release.outputs.release_id }}',
owner: context.repo.owner, repo: context.repo.repo,
});
}
publish-release:
permissions:
contents: write
runs-on: ubuntu-20.04
needs: [create-release, build-tauri]
steps:
- name: publish release
id: publish-release
uses: actions/github-script@v6
env:
release_id: ${{ needs.create-release.outputs.release_id }}
with:
script: |
github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: process.env.release_id,
draft: false,
prerelease: false
})