Skip to content

Commit

Permalink
Merge pull request #159 from greenhat616/feat-nightly
Browse files Browse the repository at this point in the history
feat: nightly build with updater
  • Loading branch information
keiko233 authored Dec 15, 2023
2 parents fddb447 + 6a554b6 commit 66d9341
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 4 deletions.
65 changes: 62 additions & 3 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Pnpm install and check
run: |
pnpm i
pnpm check
pnpm check && pnpm prepare:nightly
- name: Tauri build
uses: tauri-apps/tauri-action@v0
Expand All @@ -93,7 +93,7 @@ jobs:
releaseDraft: false
prerelease: true
tauriScript: pnpm
args: -f default-meta
args: -f default-meta nightly -c ./backend/tauri/tauri.nightly.conf.json

- name: Portable Bundle (Windows Only)
if: matrix.os == 'windows-latest'
Expand All @@ -119,5 +119,64 @@ jobs:
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
run: |
pnpm build --target aarch64-apple-darwin
pnpm build:nightly --target aarch64-apple-darwin
pnpm upload:osx-aarch64
update_tag:
name: Update tag
runs-on: ubuntu-latest
needs: [release]
if: startsWith(github.repository, 'keiko233')
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: dev # Dev branch
- name: Set Env
run: |
echo "BUILDTIME=$(TZ=Asia/Shanghai date)" >> $GITHUB_ENV
shell: bash
- name: Update Tag
uses: richardsimko/[email protected]
with:
tag_name: pre-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
cat > release.txt << 'EOF'
## Clash Nyanpasu Nightly Build
Release created at ${{ env.BUILDTIME }}.
Daily build of Clash Nyanpasu Dev branch.
[See the development log here](https://t.me/keikolog/462)
EOF
- name: Update Release
uses: ncipollo/release-action@v1
with:
name: Clash Nyanpasu Dev
tag: pre-release
bodyFile: release.txt
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
updater:
name: Update Nigthly Updater
runs-on: ubuntu-latest
needs: [release, update_tag]
if: startsWith(github.repository, 'keiko233')
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: dev # Dev branch
- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8
run_install: false

- name: Pnpm install
run: pnpm i
- name: Update Updater
run: pnpm updater:nightly
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
1 change: 1 addition & 0 deletions backend/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ default = ["custom-protocol"]
custom-protocol = ["tauri/custom-protocol"]
verge-dev = []
default-meta = []
nightly = []
93 changes: 93 additions & 0 deletions backend/tauri/tauri.nightly.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"package": {
"productName": "Clash Nyanpasu",
"version": "1.4.2"
},
"build": {
"distDir": "../../dist",
"devPath": "http://localhost:3000/",
"beforeDevCommand": "pnpm run web:dev",
"beforeBuildCommand": "pnpm run web:build"
},
"tauri": {
"systemTray": {
"iconPath": "icons/win-tray-icon.png",
"iconAsTemplate": true
},
"bundle": {
"active": true,
"targets": "all",
"identifier": "moe.elaina.clash.nyanpasu",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/[email protected]",
"icons/icon-new.icns",
"icons/icon.ico"
],
"resources": ["resources"],
"externalBin": [
"sidecar/clash",
"sidecar/mihomo",
"sidecar/mihomo-alpha",
"sidecar/clash-rs"
],
"copyright": "© 2022 zzzgydi All Rights Reserved",
"category": "DeveloperTool",
"shortDescription": "Clash Nyanpasu! (∠・ω< )⌒☆",
"longDescription": "Clash Nyanpasu! (∠・ω< )⌒☆",
"deb": {
"depends": ["openssl"]
},
"macOS": {
"frameworks": [],
"minimumSystemVersion": "",
"exceptionDomain": "",
"signingIdentity": null,
"entitlements": null
},
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": "",
"wix": {
"language": ["zh-CN", "en-US", "ru-RU"]
}
}
},
"updater": {
"active": true,
"endpoints": [
"https://mirror.ghproxy.com/https://github.com/keiko233/clash-nyanpasu/releases/download/updater/update-nightly-proxy.json",
"https://ghproxy.com/https://github.com/keiko233/clash-nyanpasu/releases/download/updater/update-nightly-proxy.json",
"https://github.com/keiko233/clash-nyanpasu/releases/download/updater/update-nightly.json"
],
"dialog": false,
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDlBMUM0NjMxREZCNDRGMjYKUldRbVQ3VGZNVVljbW43N0FlWjA4UkNrbTgxSWxSSXJQcExXNkZjUTlTQkIyYkJzL0tsSWF2d0cK"
},
"allowlist": {
"shell": {
"all": true
},
"window": {
"all": true
},
"process": {
"all": true
},
"globalShortcut": {
"all": true
},
"notification": {
"all": true
},
"os": {
"all": true
}
},
"windows": [],
"security": {
"csp": "script-src 'unsafe-eval' 'self'; default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; img-src data: 'self';"
}
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dev": "tauri dev -f default-meta -c ./backend/tauri/tauri.conf.json",
"dev:diff": "tauri dev -f verge-dev -c ./backend/tauri/tauri.conf.json",
"build": "tauri build -f default-meta -c ./backend/tauri/tauri.conf.json",
"build:nightly": "tauri build -f default-meta nightly -c ./backend/tauri/tauri.nightly.conf.json",
"tauri": "tauri",
"web:dev": "vite",
"web:build": "tsc --noEmit && vite build",
Expand All @@ -24,12 +25,14 @@
"fmt:prettier": "prettier --write .",
"check": "tsx scripts/check.ts",
"updater": "tsx scripts/updater.ts",
"updater:nightly": "tsx scripts/updater-nightly.ts",
"publish": "tsx scripts/publish.ts",
"portable": "tsx scripts/portable.ts",
"upload:osx-aarch64": "tsx scripts/osx-aarch64-upload.ts",
"generate:manifest": "run-p generate:manifest:*",
"generate:manifest:latest-version": "tsx scripts/generate-latest-version.ts",
"prepare": "husky install"
"prepare": "husky install",
"prepare:nightly": "tsx scripts/prepare-nightly.ts"
},
"prettier": {
"plugins": [
Expand Down
35 changes: 35 additions & 0 deletions scripts/prepare-nightly.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { execSync } from "child_process";
import fs from "fs-extra";
import path from "node:path";
import { TAURI_APP_DIR, cwd } from "./utils/env";
import { consola } from "./utils/logger";

const TAURI_DEV_APP_CONF_PATH = path.join(
TAURI_APP_DIR,
"tauri.nightly.conf.json",
);
const PACKAGE_JSON_PATH = path.join(cwd, "package.json");

async function main() {
const tauriConf = await fs.readJSON(TAURI_DEV_APP_CONF_PATH);
const packageJson = await fs.readJSON(PACKAGE_JSON_PATH);
consola.debug("Get current git short hash");
const GIT_SHORT_HASH = execSync("git rev-parse --short HEAD")
.toString()
.trim();
consola.debug(`Current git short hash: ${GIT_SHORT_HASH}`);

const version = `${tauriConf.package.version}-alpha+${GIT_SHORT_HASH}`;
// 1. update tauri version
consola.debug("Write tauri version to tauri.nightly.conf.json");
tauriConf.package.version = version;
await fs.writeJSON(TAURI_DEV_APP_CONF_PATH, tauriConf, { spaces: 2 });
consola.debug("tauri.nightly.conf.json updated");
// 2. update package version
consola.debug("Write tauri version to package.json");
packageJson.version = version;
await fs.writeJSON(PACKAGE_JSON_PATH, packageJson, { spaces: 2 });
consola.debug("package.json updated");
}

main();
10 changes: 10 additions & 0 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import { TAURI_APP_DIR, cwd } from "./utils/env";
import { consola } from "./utils/logger";

const TAURI_APP_CONF_PATH = path.join(TAURI_APP_DIR, "tauri.conf.json");
const TAURI_NIGHTLY_APP_CONF_PATH = path.join(
TAURI_APP_DIR,
"tauri.nightly.conf.json",
);
const PACKAGE_JSON_PATH = path.join(cwd, "package.json");

// publish
async function resolvePublish() {
const flag = process.argv[2] ?? "patch";
const tauriJson = await fs.readJSON(TAURI_APP_CONF_PATH);
const tauriNightlyJson = await fs.readJSON(TAURI_NIGHTLY_APP_CONF_PATH);

let [a, b, c] = packageJson.version.split(".").map(Number);

Expand All @@ -28,8 +33,10 @@ async function resolvePublish() {
} else throw new Error(`invalid flag "${flag}"`);

const nextVersion = `${a}.${b}.${c}`;
const nextNightlyVersion = `${a}.${b}.${c + 1}`;
packageJson.version = nextVersion;
tauriJson.package.version = nextVersion;
tauriNightlyJson.package.version = nextNightlyVersion;

// 发布更新前先写更新日志
const nextTag = `v${nextVersion}`;
Expand All @@ -41,6 +48,9 @@ async function resolvePublish() {
await fs.writeJSON(TAURI_APP_CONF_PATH, tauriJson, {
spaces: 2,
});
await fs.writeJSON(TAURI_NIGHTLY_APP_CONF_PATH, tauriNightlyJson, {
spaces: 2,
});

execSync("git add ./package.json");
execSync(`git add ${TAURI_APP_CONF_PATH}`);
Expand Down
Loading

0 comments on commit 66d9341

Please sign in to comment.