From d73ae4fe6d561efd1cb79301e0e85d4e9af22e65 Mon Sep 17 00:00:00 2001 From: ikkz Date: Wed, 20 Nov 2024 16:54:51 +0800 Subject: [PATCH] feat: release workflow --- .github/workflows/release.yml | 34 ++++++++++++++++++++++++++++++++++ .gitignore | 1 + package.json | 2 +- release.py | 8 +++++++- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e89ad3c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Releases + +on: + push: + tags: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Install pnpm + uses: pnpm/action-setup@v4 + - name: Use Node.js 22 + uses: actions/setup-node@v4 + with: + node-version: 22.x + cache: 'pnpm' + - run: pnpm install + - run: node cli.js + + - name: Install uv + uses: astral-sh/setup-uv@v3 + with: + version: '0.4.27' + - name: Release + run: uv run --frozen release.py + - uses: ncipollo/release-action@v1.14.0 + with: + artifacts: 'release/*.apkg' + artifactErrorsFailBuild: true diff --git a/.gitignore b/.gitignore index 017d3be..edec81f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ lerna-debug.log* node_modules dist +release dist-ssr *.local diff --git a/package.json b/package.json index 830f01a..f138b93 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "anki-templates", "type": "module", - "version": "1.0.6", + "version": "1.0.7", "description": "", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/release.py b/release.py index b7af577..d99fa83 100644 --- a/release.py +++ b/release.py @@ -1,5 +1,6 @@ import genanki import json +import os with open("./templates.json") as file: templates_config = json.load(file) @@ -40,8 +41,13 @@ def gen_apkg(id: str, locale: str): ), ) deck.add_note(note) - genanki.Package(deck).write_to_file(f"{folder}/release.apkg") + genanki.Package(deck).write_to_file( + f"release/{template['name']} Template [{locale}].apkg" + ) + + +os.makedirs("release", exist_ok=True) for id in templates_config.keys(): for locale in ["zh", "en"]: