-
Notifications
You must be signed in to change notification settings - Fork 1
235 lines (204 loc) · 8.63 KB
/
update-json.yml
File metadata and controls
235 lines (204 loc) · 8.63 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: Generate Update JSON
on:
workflow_dispatch:
inputs:
tag:
description: 'The release tag to generate update JSON for (e.g. v0.1.0)'
required: true
type: string
jobs:
create-update:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false
- name: Install Tauri CLI
run: pnpm add -D @tauri-apps/cli
- name: Install jq
run: sudo apt-get install jq
- name: Download release assets
uses: actions/github-script@v7
with:
script: |
const version = '${{ inputs.tag }}'.replace(/^v/, '');
const artifacts = [
'litepost_aarch64.app.tar.gz',
'litepost_x64.app.tar.gz',
`litepost_${version}_amd64.AppImage`,
`litepost_${version}_x64-setup.exe`
];
const tag = '${{ inputs.tag }}';
const owner = context.repo.owner;
const repo = context.repo.repo;
// Get all releases including drafts
const releases = await github.rest.repos.listReleases({
owner,
repo,
per_page: 100
});
// Find the release by tag, including drafts
const release = releases.data.find(r => r.tag_name === tag);
if (!release) {
throw new Error('Release not found');
}
const fs = require('fs');
const path = require('path');
if (!fs.existsSync('artifacts')) {
fs.mkdirSync('artifacts');
}
for (const asset of release.assets) {
if (artifacts.includes(asset.name)) {
// Download using the GitHub API
const response = await github.rest.repos.getReleaseAsset({
owner,
repo,
asset_id: asset.id,
headers: {
accept: 'application/octet-stream'
}
});
fs.writeFileSync(
path.join('artifacts', asset.name),
Buffer.from(response.data)
);
}
}
- name: Generate signatures and updater JSON
env:
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Extract version from tag (remove 'v' prefix)
VERSION="${{ inputs.tag }}"
VERSION=${VERSION#v}
echo "Using version: $VERSION"
echo "Artifact directory contents:"
ls -la artifacts/
# Sign artifacts and collect signatures
declare -A signatures
# Function to handle signing and capture both stdout and stderr
sign_artifact() {
local file=$1
local platform=$2
echo "Attempting to sign $file for $platform..."
echo "Current directory: $(pwd)"
echo "File exists: $(test -f "$file" && echo "yes" || echo "no")"
echo "File size: $(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null || echo "unknown")"
echo "TAURI_KEY_PASSWORD is set: $(test -n "$TAURI_KEY_PASSWORD" && echo "yes" || echo "no")"
# Capture both stdout and stderr
if ! output=$(pnpm tauri signer sign -p "$TAURI_KEY_PASSWORD" "$file" 2>&1); then
echo "Error during signing:"
echo "$output"
return 1
fi
# Extract signature - now handling multiline output
local sig=$(echo "$output" | awk '/Public signature:/{getline; print}' || echo "")
if [ -z "$sig" ]; then
echo "Failed to extract signature from output:"
echo "$output"
return 1
fi
signatures[$platform]="$sig"
echo "$platform signing completed (signature ${#sig} chars)"
return 0
}
# Sign each artifact and extract signature from output
if [ -f "artifacts/litepost_x64.app.tar.gz" ]; then
sign_artifact "artifacts/litepost_x64.app.tar.gz" "darwin-x86_64" || echo "Failed to sign macOS x64 artifact"
fi
if [ -f "artifacts/litepost_aarch64.app.tar.gz" ]; then
sign_artifact "artifacts/litepost_aarch64.app.tar.gz" "darwin-aarch64" || echo "Failed to sign macOS aarch64 artifact"
fi
if [ -f "artifacts/litepost_${VERSION}_amd64.AppImage" ]; then
sign_artifact "artifacts/litepost_${VERSION}_amd64.AppImage" "linux-x86_64" || echo "Failed to sign Linux artifact"
fi
if [ -f "artifacts/litepost_${VERSION}_x64-setup.exe" ]; then
sign_artifact "artifacts/litepost_${VERSION}_x64-setup.exe" "windows-x86_64" || echo "Failed to sign Windows artifact"
fi
echo "Collected signatures (lengths):"
for key in "${!signatures[@]}"; do
echo "$key: ${#signatures[$key]} characters"
echo "First 50 chars of signature: ${signatures[$key]:0:50}..."
done
# Create latest.json with collected signatures
echo '{
"version": "${{ inputs.tag }}",
"notes": "See the assets to download this version and install.",
"pub_date": "'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'",
"platforms": {
"darwin-x86_64": {
"signature": "'${signatures["darwin-x86_64"]}'",
"url": "https://github.com/LykosAI/LitePost/releases/download/${{ inputs.tag }}/litepost_x64.app.tar.gz"
},
"darwin-aarch64": {
"signature": "'${signatures["darwin-aarch64"]}'",
"url": "https://github.com/LykosAI/LitePost/releases/download/${{ inputs.tag }}/litepost_aarch64.app.tar.gz"
},
"linux-x86_64": {
"signature": "'${signatures["linux-x86_64"]}'",
"url": "https://github.com/LykosAI/LitePost/releases/download/${{ inputs.tag }}/litepost_'${VERSION}'_amd64.AppImage"
},
"windows-x86_64": {
"signature": "'${signatures["windows-x86_64"]}'",
"url": "https://github.com/LykosAI/LitePost/releases/download/${{ inputs.tag }}/litepost_'${VERSION}'_x64-setup.exe"
}
}
}' > latest.json
- name: Upload latest.json
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const tag = '${{ inputs.tag }}';
const owner = context.repo.owner;
const repo = context.repo.repo;
// Get all releases including drafts
const releases = await github.rest.repos.listReleases({
owner,
repo,
per_page: 100
});
// Find the release by tag, including drafts
const release = releases.data.find(r => r.tag_name === tag);
if (!release) {
throw new Error('Release not found');
}
// Delete existing latest.json if it exists
for (const asset of release.assets) {
if (asset.name === 'latest.json') {
await github.rest.repos.deleteReleaseAsset({
owner,
repo,
asset_id: asset.id
});
break;
}
}
// Upload new latest.json
const contentType = 'application/json';
const content = await fs.promises.readFile('latest.json');
await github.rest.repos.uploadReleaseAsset({
owner,
repo,
release_id: release.id,
name: 'latest.json',
data: content,
headers: {
'content-type': contentType,
'content-length': content.length
}
});