Skip to content

Commit

Permalink
update ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ChurchTao committed Jan 19, 2023
1 parent 6917d92 commit d8f8b0c
Show file tree
Hide file tree
Showing 11 changed files with 515 additions and 115 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Release CI

on:
workflow_dispatch:
push:
tags:
- v**

env:
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: short

jobs:
release:
strategy:
matrix:
# os: [windows-latest, ubuntu-latest, macos-latest]
os: [macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri

- name: Install Node
uses: actions/setup-node@v1
with:
node-version: 16

- name: Install Dependencies (ubuntu only)
if: startsWith(matrix.os, 'ubuntu-')
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libappindicator3-dev librsvg2-dev patchelf
- name: Reconfigure git to use HTTP authentication
run: >
git config --global url."https://github.com/".insteadOf
ssh://git@github.com/
- name: Get yarn cache dir path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Yarn Cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Yarn install and check
run: |
yarn install --network-timeout 1000000
yarn run check
- name: Tauri build
uses: tauri-apps/tauri-action@v0
# enable cache even though failed
# continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
with:
tagName: v__VERSION__
releaseName: "Lanaya v__VERSION__"
releaseBody: "More new features are now supported."
releaseDraft: false
prerelease: true

# - name: Portable Bundle
# if: matrix.os == 'windows-latest'
# # rebuild with env settings
# run: |
# yarn build
# yarn run portable
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
# TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
# VITE_WIN_PORTABLE: 1

release-update:
needs: release
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Reconfigure git to use HTTP authentication
run: >
git config --global url."https://github.com/".insteadOf
ssh://git@github.com/
- name: Get yarn cache dir path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Yarn Cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Yarn install
run: yarn install

- name: Release updater file
run: yarn run updater
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90 changes: 0 additions & 90 deletions .github/workflows/release.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Updater CI

on: workflow_dispatch

jobs:
release-update:
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Reconfigure git to use HTTP authentication
run: >
git config --global url."https://github.com/".insteadOf
ssh://git@github.com/
- name: Get yarn cache dir path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Yarn Cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Yarn install
run: yarn install

- name: Release updater file
run: yarn run updater
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion UPDATE_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All changes will be documented in this file.

## v0.0.7
## v0.0.8

### Feature

Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "lanaya",
"private": true,
"version": "0.0.0",
"version": "0.0.7",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"updater": "tr updater",
"release": "tr release --git",
"tr": "tr",
"aarch": "node scripts/aarch.mjs",
"updater": "node scripts/updater.mjs",
"publish": "node scripts/publish.mjs",
"tauri": "tauri"
},
"dependencies": {
Expand All @@ -27,7 +27,6 @@
"devDependencies": {
"@actions/github": "^5.1.1",
"@tauri-apps/cli": "^1.2.3",
"@tauri-release/cli": "^0.2.3",
"@vitejs/plugin-vue": "^3.2.0",
"autoprefixer": "^10.4.13",
"node-fetch": "^3.3.0",
Expand Down
98 changes: 98 additions & 0 deletions scripts/aarch.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Build and upload assets for macOS(aarch)
*/
import fs from "fs-extra";
import path from "path";
import { exit } from "process";
import { createRequire } from "module";
import { getOctokit, context } from "@actions/github";

const require = createRequire(import.meta.url);

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");
}
if (!process.env.TAURI_KEY_PASSWORD) {
throw new Error("TAURI_KEY_PASSWORD is required");
}

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

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

const appPathList = [join("macos/Lanaya.app.tar.gz"), join("macos/Lanaya.app.tar.gz.sig")];

for (const appPath of appPathList) {
if (fs.pathExistsSync(appPath)) {
fs.removeSync(appPath);
}
}

fs.copyFileSync(join("macos/Lanaya.app.tar.gz"), appPathList[0]);
fs.copyFileSync(join("macos/Lanaya.app.tar.gz.sig"), appPathList[1]);

const options = { owner: context.repo.owner, repo: context.repo.repo };
const github = getOctokit(process.env.GITHUB_TOKEN);

const { data: release } = await github.rest.repos.getReleaseByTag({
...options,
tag: `v${version}`,
});

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

await uploadAssets(release.id, [join(`dmg/Lanaya_${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) {
const github = getOctokit(process.env.GITHUB_TOKEN);

// Determine content-length for header to upload asset
const contentLength = (filePath) => fs.statSync(filePath).size;

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);
}
}
}

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

0 comments on commit d8f8b0c

Please sign in to comment.