Skip to content

Nightly Build

Nightly Build #17

Workflow file for this run

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