-
Notifications
You must be signed in to change notification settings - Fork 1
209 lines (184 loc) · 7.01 KB
/
release.yml
File metadata and controls
209 lines (184 loc) · 7.01 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
name: Build & Release
on:
push:
tags:
- 'v*' # Full release (npm + Electron)
- 'npm-v*' # npm only
- 'electron-v*' # Electron only
workflow_dispatch:
inputs:
publish_npm:
description: 'Publish to npm'
required: true
type: boolean
default: false
npm_version:
description: 'npm version override (leave empty to use server/package.json)'
required: false
type: string
build_electron:
description: 'Build Electron installer & GitHub Release'
required: true
type: boolean
default: false
electron_version:
description: 'Electron version override (leave empty to use package.json)'
required: false
type: string
jobs:
# ── Determine what to build ────────────────────────────────
prepare:
runs-on: ubuntu-latest
outputs:
do_npm: ${{ steps.resolve.outputs.do_npm }}
do_electron: ${{ steps.resolve.outputs.do_electron }}
npm_version: ${{ steps.resolve.outputs.npm_version }}
electron_version: ${{ steps.resolve.outputs.electron_version }}
steps:
- uses: actions/checkout@v5
- id: resolve
shell: bash
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
TAG="${GITHUB_REF_NAME}"
if [[ "$TAG" == npm-v* ]]; then
echo "do_npm=true" >> $GITHUB_OUTPUT
echo "do_electron=false" >> $GITHUB_OUTPUT
echo "npm_version=${TAG#npm-v}" >> $GITHUB_OUTPUT
elif [[ "$TAG" == electron-v* ]]; then
echo "do_npm=false" >> $GITHUB_OUTPUT
echo "do_electron=true" >> $GITHUB_OUTPUT
echo "electron_version=${TAG#electron-v}" >> $GITHUB_OUTPUT
else
echo "do_npm=true" >> $GITHUB_OUTPUT
echo "do_electron=true" >> $GITHUB_OUTPUT
echo "npm_version=$(node -p "require('./server/package.json').version")" >> $GITHUB_OUTPUT
echo "electron_version=${TAG#v}" >> $GITHUB_OUTPUT
fi
else
echo "do_npm=${{ inputs.publish_npm }}" >> $GITHUB_OUTPUT
echo "do_electron=${{ inputs.build_electron }}" >> $GITHUB_OUTPUT
if [[ -n "${{ inputs.npm_version }}" ]]; then
echo "npm_version=${{ inputs.npm_version }}" >> $GITHUB_OUTPUT
else
echo "npm_version=$(node -p "require('./server/package.json').version")" >> $GITHUB_OUTPUT
fi
if [[ -n "${{ inputs.electron_version }}" ]]; then
echo "electron_version=${{ inputs.electron_version }}" >> $GITHUB_OUTPUT
else
echo "electron_version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
fi
fi
# ── Publish to npm (Trusted Publisher via OIDC) ────────────
publish-npm:
needs: prepare
if: needs.prepare.outputs.do_npm == 'true'
runs-on: ubuntu-latest
environment: npm-publish
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
registry-url: https://registry.npmjs.org
- run: npm ci
- name: Lint
run: npm run lint
- name: Test
run: npm test
- name: Build server
run: npm run build -w server
- name: Publish to npm
working-directory: server
run: |
npm version "${{ needs.prepare.outputs.npm_version }}" --no-git-tag-version --allow-same-version
npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# ── Build Electron + GitHub Release ────────────────────────
publish-electron:
needs: prepare
if: needs.prepare.outputs.do_electron == 'true'
runs-on: windows-latest
permissions:
contents: write
env:
ELECTRON_CACHE: ${{ github.workspace }}/.cache/electron
ELECTRON_BUILDER_CACHE: ${{ github.workspace }}/.cache/electron-builder
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
# Cache Electron binary (~90MB, avoids re-download each build)
- name: Cache Electron binary
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.cache/electron
key: electron-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
electron-${{ runner.os }}-
# Cache electron-builder tools (NSIS, nsis-resources, etc.)
- name: Cache electron-builder tools
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.cache/electron-builder
key: electron-builder-${{ runner.os }}-${{ hashFiles('electron-builder.yml') }}
restore-keys: |
electron-builder-${{ runner.os }}-
- run: npm ci
- name: Lint
run: npm run lint
- name: Test
run: npm test
- name: Build application
run: |
npm run build
npx tsc -p electron/tsconfig.json
- name: Sync Electron version
shell: bash
run: npm version "${{ needs.prepare.outputs.electron_version }}" --no-git-tag-version --allow-same-version
- name: Package Electron app
run: npx electron-builder --win --publish never
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Extract changelog
id: changelog
shell: bash
run: |
VERSION="${{ needs.prepare.outputs.electron_version }}"
# Extract the section for this version from CHANGELOG.md
BODY=$(awk "/^## \\[${VERSION}\\]/{found=1; next} /^## \\[/{if(found) exit} found{print}" CHANGELOG.md)
if [ -z "$BODY" ]; then
BODY="Release v${VERSION}"
fi
# Write to file to avoid escaping issues
echo "$BODY" > release_body.md
- name: Determine release tag
id: release_tag
shell: bash
run: |
# Use the original push tag if available (v* for full release),
# otherwise fall back to electron-v* prefix
if [[ "${{ github.ref_name }}" == v* ]]; then
echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
else
echo "tag=electron-v${{ needs.prepare.outputs.electron_version }}" >> $GITHUB_OUTPUT
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release_tag.outputs.tag }}
name: ChatCrystal v${{ needs.prepare.outputs.electron_version }}
body_path: release_body.md
draft: false
prerelease: ${{ contains(needs.prepare.outputs.electron_version, '-') }}
files: |
release/*.exe
release/*.yml
release/*.yaml