Skip to content

Commit

Permalink
chore: test: fix missing env & upload to release
Browse files Browse the repository at this point in the history
  • Loading branch information
keiko233 committed Nov 25, 2023
1 parent b09331e commit eb5dddf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 51 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/macos-aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ jobs:
pnpm i
pnpm check --arch arm64 --sidecar-host aarch64-apple-darwin
- name: Tauri build (cmd)
- name: Tauri build with Upload (cmd)
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
run: |
pnpm build --target aarch64-apple-darwin
mv ./src-tauri/target/aarch64-apple-darwin/release/bundle/macos/Clash Nyanpasu.app ./src-tauri/target/aarch64-apple-darwin/release/bundle/macos/Clash Nyanpasu.aarch64.app
mv ./src-tauri/target/aarch64-apple-darwin/release/bundle/macos/Clash Nyanpasu.app.tar.gz ./src-tauri/target/aarch64-apple-darwin/release/bundle/macos/Clash Nyanpasu.aarch64.app.tar.gz
node scripts/osx-aarch64-upload.mjs
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"web:dev": "vite",
"web:build": "tsc && vite build",
"web:serve": "vite preview",
"aarch": "node scripts/aarch.mjs",
"check": "node scripts/check.mjs",
"updater": "node scripts/updater.mjs",
"publish": "node scripts/publish.mjs",
Expand Down
68 changes: 21 additions & 47 deletions scripts/aarch.mjs → scripts/osx-aarch64-upload.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
import fs from "fs-extra";
import path from "path";
import { exit } from "process";
import { execSync } from "child_process";
import { createRequire } from "module";
import { getOctokit, context } from "@actions/github";

Expand All @@ -15,9 +13,6 @@ async function resolve() {
if (!process.env.GITHUB_TOKEN) {
throw new Error("GITHUB_TOKEN is required");
}
if (!process.env.GITHUB_REPOSITORY) {
throw new Error("GITHUB_REPOSITORY is required");
}
if (!process.env.TAURI_PRIVATE_KEY) {
throw new Error("TAURI_PRIVATE_KEY is required");
}
Expand All @@ -27,15 +22,13 @@ async function resolve() {

const { version } = require("../package.json");

const buildCmd = `pnpm build -f default-meta`;

console.log(`[INFO]: Upload to tag "${tag}"`);
console.log(`[INFO]: Building app. "${buildCmd}"`);

execSync(buildCmd);

const cwd = process.cwd();
const bundlePath = path.join(cwd, "src-tauri/target/release/bundle");
const bundlePath = path.join(
cwd,
"src-tauri/target/aarch64-apple-darwin/release/bundle"
);
const join = (p) => path.join(bundlePath, p);

const appPathList = [
Expand All @@ -62,52 +55,33 @@ async function resolve() {

if (!release.id) throw new Error("failed to find the release");

await uploadAssets(release.id, [
await uploadAssets([
join(`dmg/Clash Nyanpasu_${version}_aarch64.dmg`),
...appPathList,
]);
}

// From tauri-apps/tauri-action
// https://github.com/tauri-apps/tauri-action/blob/dev/packages/action/src/upload-release-assets.ts
async function uploadAssets(releaseId, assets) {
async function uploadAssets(assets) {
const github = getOctokit(process.env.GITHUB_TOKEN);

// Determine content-length for header to upload asset
const contentLength = (filePath) => fs.statSync(filePath).size;
const options = { owner: context.repo.owner, repo: context.repo.repo };

for (const assetPath of assets) {
const headers = {
"content-type": "application/zip",
"content-length": contentLength(assetPath),
};

const ext = path.extname(assetPath);
const filename = path.basename(assetPath).replace(ext, "");
const assetName = path.dirname(assetPath).includes(`target${path.sep}debug`)
? `${filename}-debug${ext}`
: `${filename}${ext}`;

console.log(`[INFO]: Uploading ${assetName}...`);

try {
await github.rest.repos.uploadReleaseAsset({
headers,
name: assetName,
data: fs.readFileSync(assetPath),
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
});
} catch (error) {
console.log(error.message);
}
const { data: release } = await github.rest.repos.getReleaseByTag({
...options,
tag: process.env.TAG_NAME || `v${version}`,
});

console.log(release.name);

await github.rest.repos.uploadReleaseAsset({
...options,
release_id: release.id,
name: assetPath,
data: zip.toBuffer(),
});
}
}

if (process.platform === "darwin" && process.arch === "arm64") {
resolve();
} else {
console.error("invalid");
exit(1);
}
resolve();

0 comments on commit eb5dddf

Please sign in to comment.