forked from GCWing/BitFun
-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (161 loc) · 6.26 KB
/
nightly.yml
File metadata and controls
194 lines (161 loc) · 6.26 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
name: Nightly Build
on:
schedule:
# Weekdays at 02:00 UTC
- cron: "0 2 * * 1-5"
workflow_dispatch:
permissions:
contents: write
concurrency:
group: nightly
cancel-in-progress: true
env:
NIGHTLY_TAG: nightly
jobs:
# ── Check if there are new commits since last nightly ──────────────
check-changes:
name: Check for Changes
runs-on: ubuntu-latest
outputs:
should_build: ${{ steps.check.outputs.should_build }}
nightly_version: ${{ steps.check.outputs.nightly_version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for recent changes
id: check
shell: bash
run: |
set -euo pipefail
BASE_VERSION="$(jq -r '.version' package.json)"
DATE_SUFFIX="$(date -u '+%Y%m%d')"
SHORT_SHA="$(git rev-parse --short HEAD)"
NIGHTLY_VERSION="${BASE_VERSION}-nightly.${DATE_SUFFIX}+${SHORT_SHA}"
echo "nightly_version=$NIGHTLY_VERSION" >> "$GITHUB_OUTPUT"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "should_build=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# Check if any commits landed in the last 25 hours
LAST_COMMIT_TIME="$(git log -1 --format='%ct')"
NOW="$(date -u '+%s')"
HOURS_AGO=$(( (NOW - LAST_COMMIT_TIME) / 3600 ))
if [[ "$HOURS_AGO" -lt 25 ]]; then
echo "should_build=true" >> "$GITHUB_OUTPUT"
else
echo "No new commits in the last 25 hours, skipping nightly build."
echo "should_build=false" >> "$GITHUB_OUTPUT"
fi
# ── Patch version for nightly ──────────────────────────────────────
package:
name: Package (${{ matrix.platform.name }})
runs-on: ${{ matrix.platform.os }}
needs: check-changes
if: needs.check-changes.outputs.should_build == 'true'
env:
NODE_OPTIONS: --max-old-space-size=6144
strategy:
fail-fast: false
matrix:
platform:
- os: macos-15
name: macos-arm64
target: aarch64-apple-darwin
build_command: cd src/apps/desktop && npm exec -- tauri build --target aarch64-apple-darwin --bundles dmg
- os: macos-15-intel
name: macos-x64
target: x86_64-apple-darwin
build_command: npm run desktop:build:x86_64
- os: windows-latest
name: windows-x64
target: x86_64-pc-windows-msvc
build_command: npm run desktop:build:nsis
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}
- name: Cache Rust build
uses: swatinem/rust-cache@v2
with:
shared-key: "nightly-${{ matrix.platform.name }}"
- name: Install dependencies
run: npm ci
- name: Patch nightly version
shell: bash
env:
NIGHTLY_VERSION: ${{ needs.check-changes.outputs.nightly_version }}
run: |
set -euo pipefail
echo "Patching version to $NIGHTLY_VERSION"
# Patch package.json
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
pkg.version = process.env.NIGHTLY_VERSION.split('+')[0];
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
# Patch Cargo workspace version (semver: nightly suffix uses hyphen)
# Cargo.toml only accepts: MAJOR.MINOR.PATCH or MAJOR.MINOR.PATCH-PRE
CARGO_VERSION="$(echo "$NIGHTLY_VERSION" | sed 's/+.*//')"
sed -i.bak "s/^version = \".*\" # x-release-please-version/version = \"${CARGO_VERSION}\" # x-release-please-version/" Cargo.toml
rm -f Cargo.toml.bak
echo "package.json version: $(jq -r '.version' package.json)"
echo "Cargo.toml version: $(grep 'x-release-please-version' Cargo.toml)"
- name: Build desktop app
run: ${{ matrix.platform.build_command }}
- name: Upload bundles
uses: actions/upload-artifact@v4
with:
name: bitfun-nightly-${{ matrix.platform.name }}-bundle
if-no-files-found: error
retention-days: 7
path: |
target/*/release/bundle
target/release/bundle
src/apps/desktop/target/release/bundle
# ── Publish nightly pre-release ────────────────────────────────────
publish-nightly:
name: Publish Nightly
needs: [check-changes, package]
if: needs.check-changes.outputs.should_build == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download bundled artifacts
uses: actions/download-artifact@v4
with:
pattern: bitfun-nightly-*-bundle
path: release-assets
merge-multiple: true
- name: List release assets
run: |
echo "Nightly assets:"
find release-assets -type f | sort
- name: Delete previous nightly release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release delete "${{ env.NIGHTLY_TAG }}" --yes --cleanup-tag 2>/dev/null || true
- name: Create nightly release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.NIGHTLY_TAG }}
name: "Nightly Build (${{ needs.check-changes.outputs.nightly_version }})"
body: |
Automated nightly build from `main` branch.
**Version**: `${{ needs.check-changes.outputs.nightly_version }}`
**Commit**: ${{ github.sha }}
**Date**: ${{ github.event.head_commit.timestamp || github.event.repository.updated_at }}
> **Warning**: Nightly builds are untested and may be unstable.
prerelease: true
files: |
release-assets/**/*.dmg
release-assets/**/*setup.exe