feat(ci): support nightly build (#256)

This commit is contained in:
Neko
2025-07-05 17:20:22 +08:00
committed by GitHub
parent 87c799c4ff
commit fd314058b6
8 changed files with 182 additions and 158 deletions
-90
View File
@@ -1,90 +0,0 @@
name: Build Tamagotchi
permissions:
contents: write
on:
workflow_dispatch:
inputs:
tag:
description: Attach to a specific tag/commit for the release
required: true
type: string
jobs:
build-tamagotchi:
name: Build Tamagotchi
strategy:
matrix:
include:
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
- os: windows-latest
target: x86_64-pc-windows-msvc
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Install Node.js 24.x
uses: actions/setup-node@v4
with:
cache: pnpm
node-version: 24.x
# registry-url required. Learn more at
# https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
registry-url: https://registry.npmjs.org
- name: Get Product Name (Windows Only)
if: matrix.os == 'windows-latest'
run: |
$productName = node -p 'require("./apps/stage-tamagotchi/src-tauri/tauri.conf.json").productName'
echo "PRODUCT_NAME=$productName" >> $env:GITHUB_ENV
- name: Get Product Name
if: matrix.os != 'windows-latest'
run: |
echo "PRODUCT_NAME=$(node -p 'require("./apps/stage-tamagotchi/src-tauri/tauri.conf.json").productName')" >> $GITHUB_ENV
- name: Install Rust Stable
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install system dependencies (Ubuntu Only)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'ubuntu-24.04-arm'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build Dependencies
run: pnpm run build:packages
- name: Build Application
run: cd apps/stage-tamagotchi && pnpm tauri build --target ${{ matrix.target }}
- name: Debug Environment
run: |
echo "PRODUCT_NAME: '${{ env.PRODUCT_NAME }}'"
- name: Rename Artifacts
run: node apps/stage-tamagotchi/scripts/rename-artifacts.js ${{ matrix.target }}
- name: Upload To GitHub Releases
uses: softprops/action-gh-release@v2
with:
files: bundle/${{ env.PRODUCT_NAME }}_*
append_body: true
tag_name: ${{ github.event.inputs.tag }}
+36 -3
View File
@@ -7,6 +7,14 @@ on:
release:
types:
- prereleased
workflow_dispatch:
inputs:
tag:
description: Attach to a specific tag/commit for the release (leave empty to auto-detect latest tag)
required: false
type: string
schedule:
- cron: '0 0 * * *'
jobs:
build-tamagotchi:
@@ -73,10 +81,35 @@ jobs:
- name: Build Application
run: cd apps/stage-tamagotchi && pnpm tauri build --target ${{ matrix.target }}
- name: Rename Artifacts
run: node apps/stage-tamagotchi/scripts/rename-artifacts.js ${{ matrix.target }}
- name: Rename Artifacts (Nightly)
if: ${{ github.event_name == 'schedule' }}
run: pnpm run -F @proj-airi/stage-tamagotchi rename-artifacts ${{ matrix.target }}
- name: Upload To GitHub Releases
- name: Rename Artifacts (Manual)
if: ${{ github.event_name == 'workflow_dispatch' }}
run: pnpm run -F @proj-airi/stage-tamagotchi rename-artifacts ${{ matrix.target }} --release --tag ${{ github.event.inputs.tag }} --auto-tag
- name: Rename Artifacts (Automatic)
if: ${{ github.event_name == 'release' }}
run: pnpm run -F @proj-airi/stage-tamagotchi rename-artifacts ${{ matrix.target }} --release
- name: Upload Artifacts
if: ${{ github.event_name == 'schedule' }}
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: bundle/${{ env.PRODUCT_NAME }}_*
- name: Upload To GitHub Releases (Manual)
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: softprops/action-gh-release@v2
with:
files: bundle/${{ env.PRODUCT_NAME }}_*
append_body: true
tag_name: ${{ github.event.inputs.tag }}
- name: Upload To GitHub Releases (Automatic)
if: ${{ github.event_name == 'release' }}
uses: softprops/action-gh-release@v2
with:
files: bundle/${{ env.PRODUCT_NAME }}_*
+4 -1
View File
@@ -13,7 +13,8 @@
"build": "vite build",
"preview": "vite preview",
"tauri": "tauri",
"build:unpack": "tauri build --no-bundle"
"build:unpack": "tauri build --no-bundle",
"rename-artifacts": "tsx scripts/rename-artifacts.ts"
},
"dependencies": {
"@formkit/auto-animate": "^0.8.2",
@@ -106,6 +107,8 @@
"@vue-macros/volar": "^3.0.0-beta.15",
"@vueuse/motion": "^3.0.3",
"@xsai-transformers/embed": "^0.0.7",
"cac": "^6.7.14",
"execa": "^9.6.0",
"less": "^4.3.0",
"unocss-preset-scrollbar": "^3.2.0",
"unplugin-vue-macros": "^2.14.5",
@@ -1,63 +0,0 @@
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const packageJson = require('../package.json')
const tauriConfigJson = require('../src-tauri/tauri.conf.json')
const version = packageJson.version
const target = process.argv[2]
const productName = tauriConfigJson.productName
const dirname = import.meta.dirname
console.log('version: ', version)
console.log('target: ', target)
if (!target) {
console.error('Target is required')
process.exit(1)
}
const srcPrefix = path.join(dirname, '..', '..', '..', 'target', target, 'release', 'bundle')
const bundlePrefix = path.join(dirname, '..', '..', '..', 'bundle')
fs.mkdirSync(bundlePrefix, { recursive: true })
switch (target) {
case 'x86_64-pc-windows-msvc':
fs.renameSync(
path.join(srcPrefix, 'nsis', `${productName}_${version}_x64-setup.exe`),
path.join(bundlePrefix, `${productName}_${version}_windows_amd64-setup.exe`),
)
break
case 'x86_64-unknown-linux-gnu':
fs.renameSync(
path.join(srcPrefix, 'appimage', `${productName}_${version}_amd64.AppImage`),
path.join(bundlePrefix, `${productName}_${version}_linux_amd64.AppImage`),
)
break
case 'aarch64-unknown-linux-gnu':
fs.renameSync(
path.join(srcPrefix, 'appimage', `${productName}_${version}_aarch64.AppImage`),
path.join(bundlePrefix, `${productName}_${version}_linux_arm64.AppImage`),
)
break
case 'aarch64-apple-darwin':
fs.renameSync(
path.join(srcPrefix, 'dmg', `${productName}_${version}_aarch64.dmg`),
path.join(bundlePrefix, `${productName}_${version}_macos_arm64.dmg`),
)
break
case 'x86_64-apple-darwin':
fs.renameSync(
path.join(srcPrefix, 'dmg', `${productName}_${version}_x64.dmg`),
path.join(bundlePrefix, `${productName}_${version}_macos_amd64.dmg`),
)
break
default:
console.error('Target is not supported')
process.exit(1)
}
@@ -0,0 +1,125 @@
import process from 'node:process'
import { mkdirSync, renameSync } from 'node:fs'
import { join } from 'node:path'
import { cac } from 'cac'
import { execa } from 'execa'
import packageJSON from '../package.json' assert { type: 'json' }
import tauriConfigJSON from '../src-tauri/tauri.conf.json' assert { type: 'json' }
const cli = cac('rename-artifact')
.option(
'--release',
'Rename with version from package.json',
{ default: false },
)
.option(
'--auto-tag',
'Automatically tag the release with the latest git ref',
{ default: false },
)
.option(
'--tag <tag>',
'Tag to use for the release',
{ default: '', type: [String] },
)
const args = cli.parse()
let version = packageJSON.version
const target = args.args[0]
const productName = tauriConfigJSON.productName
const dirname = import.meta.dirname
const argOptions = args.options as {
release: boolean
autoTag: boolean
tag: string[]
}
if (argOptions.release) {
// If --release is specified, use the version from package.json
version = packageJSON.version
if (argOptions.tag) {
if (argOptions.tag[0] !== 'true') {
// If --tag is specified, use the provided tag
version = String(argOptions.tag[0]).replace(/^v/, '').trim()
}
else {
version = ''
}
if (!version) {
if (argOptions.autoTag) {
// If --auto-tag is specified, fetch the latest git ref
const res = await execa('git', ['describe', '--tags', '--abbrev=0'])
version = String(res.stdout).replace(/^v/, '').trim()
}
else {
throw new Error('Tag cannot be empty when --release is specified')
}
}
}
}
else {
// Otherwise, fetch from the latest git ref
const res = await execa('git', ['log', '-1', '--pretty=format:"%H"'])
const date = new Date().toISOString().split('T')[0].replace(/-/g, '')
version = `nightly-${date}-${String(res.stdout.replace(/"/g, '')).trim().substring(0, 7)}`
}
console.log('version:', version)
console.log('target:', target)
console.log('productName:', productName)
console.log('dirname:', dirname)
if (!target) {
throw new Error('<Target> is required')
}
const srcPrefix = join(dirname, '..', '..', '..', 'target', target, 'release', 'bundle')
const bundlePrefix = join(dirname, '..', '..', '..', 'bundle')
console.log('srcPrefix:', srcPrefix)
console.log('bundlePrefix:', bundlePrefix)
mkdirSync(bundlePrefix, { recursive: true })
switch (target) {
case 'x86_64-pc-windows-msvc':
renameSync(
join(srcPrefix, 'nsis', `${productName}_${version}_x64-setup.exe`),
join(bundlePrefix, `${productName}_${version}_windows_amd64-setup.exe`),
)
break
case 'x86_64-unknown-linux-gnu':
renameSync(
join(srcPrefix, 'appimage', `${productName}_${version}_amd64.AppImage`),
join(bundlePrefix, `${productName}_${version}_linux_amd64.AppImage`),
)
break
case 'aarch64-unknown-linux-gnu':
renameSync(
join(srcPrefix, 'appimage', `${productName}_${version}_aarch64.AppImage`),
join(bundlePrefix, `${productName}_${version}_linux_arm64.AppImage`),
)
break
case 'aarch64-apple-darwin':
renameSync(
join(srcPrefix, 'dmg', `${productName}_${version}_aarch64.dmg`),
join(bundlePrefix, `${productName}_${version}_macos_arm64.dmg`),
)
break
case 'x86_64-apple-darwin':
renameSync(
join(srcPrefix, 'dmg', `${productName}_${version}_x64.dmg`),
join(bundlePrefix, `${productName}_${version}_macos_amd64.dmg`),
)
break
default:
console.error('Target is not supported')
process.exit(1)
}
+1
View File
@@ -156,6 +156,7 @@ words:
- pixi
- pixiv
- popmotion
- prereleased
- pretrained
- prismarine
- pthread
+1
View File
@@ -56,6 +56,7 @@
"smol-toml": "^1.4.0",
"taze": "^19.1.0",
"tsdown": "^0.12.9",
"tsx": "^4.20.3",
"turbo": "^2.5.4",
"typescript": "~5.8.3",
"unocss": "^66.3.2",
+15 -1
View File
@@ -130,6 +130,9 @@ importers:
tsdown:
specifier: ^0.12.9
version: 0.12.9(@arethetypeswrong/core@0.18.2)(typescript@5.8.3)(unplugin-lightningcss@0.4.1)(unplugin-unused@0.5.1)(vue-tsc@2.2.10(typescript@5.8.3))
tsx:
specifier: ^4.20.3
version: 4.20.3
turbo:
specifier: ^2.5.4
version: 2.5.4
@@ -529,6 +532,12 @@ importers:
'@xsai-transformers/embed':
specifier: ^0.0.7
version: 0.0.7(web-worker@1.5.0)
cac:
specifier: ^6.7.14
version: 6.7.14
execa:
specifier: ^9.6.0
version: 9.6.0
less:
specifier: ^4.3.0
version: 4.3.0
@@ -5869,6 +5878,9 @@ packages:
'@xsai/shared@0.3.0-beta.6':
resolution: {integrity: sha512-EeqkD4+ijKKbxr9Jy9kRnJOcPBErWL8TK2wOdxwhVQuh7VbrYQwaheGjOz9g5OWwM6A0vCje/+TyHz+tURhhqw==}
'@xsai/shared@0.3.0-beta.7':
resolution: {integrity: sha512-V2zLH7NKAzp5dT+4fxhed+05svN5vtyxvuLcY/E+K/A+XrAHQW1epRuqXBHwXWcjGoSVGWbhHYe8MzW0PT1t6Q==}
'@xsai/stream-text@0.3.0-beta.5':
resolution: {integrity: sha512-o0SxwzCA2F1zKcONZJX7qrk+PnKhzldV0jRqQ+NdBzaFLmg/clfqeENlbuwmfIrV5ck0BfPEMTo4gNBfxhsGSQ==}
@@ -17006,7 +17018,7 @@ snapshots:
'@xsai-ext/shared-providers@0.2.2':
dependencies:
'@xsai/shared': 0.3.0-beta.6
'@xsai/shared': 0.3.0-beta.7
'@xsai-ext/shared-providers@0.3.0-beta.6':
dependencies:
@@ -17075,6 +17087,8 @@ snapshots:
'@xsai/shared@0.3.0-beta.6': {}
'@xsai/shared@0.3.0-beta.7': {}
'@xsai/stream-text@0.3.0-beta.5':
dependencies:
'@xsai/shared-chat': 0.3.0-beta.5