diff --git a/.autocorrectrc b/.autocorrectrc new file mode 100644 index 00000000..ca936bcd --- /dev/null +++ b/.autocorrectrc @@ -0,0 +1,3 @@ +# yaml-language-server: $schema=https://huacnlee.github.io/autocorrect/schema.json +textRules: + 哆啦A梦: 0 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..ff374d76 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +*.md linguist-vendored=false +*.md linguist-generated=false +*.md linguist-documentation=false +*.md linguist-detectable=true diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..f1c58023 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +/.github @Cryolitia diff --git a/.github/workflows/build-ebook.yaml b/.github/workflows/build-ebook.yaml new file mode 100644 index 00000000..28fb0e5c --- /dev/null +++ b/.github/workflows/build-ebook.yaml @@ -0,0 +1,43 @@ +name: Build ebook + +on: + workflow_dispatch: + workflow_call: + pull_request: + +concurrency: + group: ebook-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/flake-checker-action@main + + - name: Print flake metadata + run: nix flake metadata --accept-flake-config + + - name: Build + run: | + sed -e "s/BUILD_TIME/$(TZ=Asia/Shanghai date -Isecond)/" -e "s/COMMIT_SHA/${{ github.sha }}/" -i src/about.md + NIXPKGS_ALLOW_UNFREE=1 nix build .# --impure --accept-flake-config + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ebook + path: | + result/share/transky-book/book/epub/药娘的天空.epub + result/share/transky-book/book/mobi/药娘的天空.mobi + result/share/transky-book/book/typst-pdf/药娘的天空.pdf diff --git a/.github/workflows/build-web.yaml b/.github/workflows/build-web.yaml new file mode 100644 index 00000000..4e51bc59 --- /dev/null +++ b/.github/workflows/build-web.yaml @@ -0,0 +1,44 @@ +name: Build website + +on: + workflow_dispatch: + workflow_call: + pull_request: + +concurrency: + group: web-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup pnpm + uses: pnpm/action-setup@v3 + with: + version: latest + run_install: true + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + cache: pnpm + node-version: current + + - name: Build + env: + NODE_OPTIONS: --max_old_space_size=4096 + run: | + sed -e "s/BUILD_TIME/$(TZ=Asia/Shanghai date -Isecond)/" -e "s/COMMIT_SHA/${{ github.sha }}/" -i src/about.md + pnpm run build + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: website + path: src/.vitepress/dist/ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index d10ee9d6..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Build and deploy - -on: - push: - paths: - - ".github/**" - - "src/**" - - "package-lock.json" - - "package.json" - -permissions: - pages: write - id-token: write - -concurrency: - group: "pages" - cancel-in-progress: true - -jobs: - build: - name: Build and deploy - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Pages - uses: actions/configure-pages@v4 - - name: Setup Node.js environment - uses: actions/setup-node@v4 - with: - node-version: current - - name: Build - run: | - npm i - npm run docs:build - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: "src/.vitepress/dist/" - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 00000000..c43c0c84 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,27 @@ +name: Lint + +on: + pull_request: + +permissions: + pull-requests: write + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: AutoCorrect + uses: huacnlee/autocorrect-action@main + + - name: Report ReviewDog + if: failure() + uses: huacnlee/autocorrect-action@main + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + reviewdog: true diff --git a/.github/workflows/publish-cloudflare.yaml b/.github/workflows/publish-cloudflare.yaml new file mode 100644 index 00000000..33c077cd --- /dev/null +++ b/.github/workflows/publish-cloudflare.yaml @@ -0,0 +1,43 @@ +name: Publish website to cloudflare + +on: + workflow_dispatch: + push: + branches: + - "main" + paths: + - ".github/workflows/build-web.yaml" + - ".github/workflows/publish-cloudflare.yaml" + - ".vitepress/**" + - "src/**" + - "package.json" + - "pnpm-lock.yaml" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + uses: ./.github/workflows/build-web.yaml + + publish: + needs: build + runs-on: ubuntu-latest + environment: cloudflare-pages + steps: + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: website + path: website + + - name: Publish to Cloudflare Pages + uses: cloudflare/pages-action@v1 + if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' + with: + apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_PAGES_ACCOUNT }} + projectName: transky-book + directory: website + wranglerVersion: 3 diff --git a/.github/workflows/publish-release.yaml b/.github/workflows/publish-release.yaml new file mode 100644 index 00000000..f9510ece --- /dev/null +++ b/.github/workflows/publish-release.yaml @@ -0,0 +1,66 @@ +name: Publish ebook to release + +on: + workflow_dispatch: + push: + branches: + - "main" + - "stable" + paths: + - ".github/workflows/build-ebook.yaml" + - ".github/workflows/publish-release.yaml" + - ".releaserc" + - "src/**" + - "theme/**" + - "book.toml" + - "package.json" + - "pnpm-lock.yaml" + - "flake.nix" + - "flake.lock" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: write + id-token: write + +jobs: + build: + uses: ./.github/workflows/build-ebook.yaml + + publish: + permissions: + contents: write + needs: build + if: ${{ !(github.event_name == 'push' && contains(github.event.head_commit.message, '[skip release]')) }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup pnpm + uses: pnpm/action-setup@v3 + with: + version: latest + run_install: true + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + cache: pnpm + node-version: current + + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: ebook + path: ebook + + - name: Release ebook + env: + GITHUB_TOKEN: ${{ github.token }} + run: pnpm exec semantic-release diff --git a/.github/workflows/update-flake.yaml b/.github/workflows/update-flake.yaml new file mode 100644 index 00000000..3e17499c --- /dev/null +++ b/.github/workflows/update-flake.yaml @@ -0,0 +1,55 @@ +name: "Update flake" + +on: + workflow_dispatch: + push: + branches: + - "main" + paths: + - ".github/workflows/update-flake.yaml" + schedule: + - cron: '31 2 * * 5' + +permissions: + contents: write + +jobs: + sync-flake: + runs-on: ubuntu-latest + environment: flake + steps: + - uses: DeterminateSystems/nix-installer-action@main + + - name: Generate a token + id: generate-token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ vars.TRIGGER_APP_ID }} + private-key: ${{ secrets.TRIGGER_APP_SECRET }} + + - name: Checkout + uses: actions/checkout@v4 + with: + show-progress: false + token: ${{ steps.generate-token.outputs.token }} + + - name: Setup Git + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git show -s + + - name: Update flake + run: | + set +e + + nix flake update --accept-flake-config + nix flake info --accept-flake-config + + # suppress inactive repo update weekly + git log --pretty=format:"%s" -1 HEAD | grep "dep: flake update" && exit 0 + + git add . + git status + git commit -m "dep: flake update $(date +'%Y-%m-%dT%H:%M:%S')" || exit 0 + git push diff --git a/.gitignore b/.gitignore index 95824b3a..327ea4d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +book src/.vitepress/cache src/.vitepress/dist +src/.vitepress/.temp node_modules +result diff --git a/.releaserc b/.releaserc new file mode 100644 index 00000000..63c5dbe5 --- /dev/null +++ b/.releaserc @@ -0,0 +1,70 @@ +{ + "branches": [ + { + "name": "main", + "prerelease": true + }, + "stable" + ], + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits", + "releaseRules": [ + { "breaking": true, "release": "major" }, + { "revert": true, "release": "patch" }, + { "type": "feat", "release": "minor" }, + { "type": "fix", "release": "patch" }, + { "type": "rfct", "release": "patch" }, + { "type": "style", "release": "patch" }, + { "type": "typo", "release": "patch" }, + { "type": "grammar", "release": "patch" }, + { "type": "ambig", "release": "patch" }, + { "type": "punctua", "release": "patch" }, + { "type": "chore", "release": "patch" }, + { "type": "ci", "release": "patch" } + ] + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { "type": "feat", "section": "Features", "hidden": false }, + { "type": "fix", "section": "Bug Fixes", "hidden": false }, + { "type": "rfct", "section": "Refactors", "hidden": false }, + { "type": "style", "section": "Style Improves", "hidden": false }, + { "type": "typo", "section": "Typo Fixes", "hidden": false }, + { "type": "grammar", "section": "Grammar Fixes",vv "hidden": false }, + { "type": "ambig", "section": "Ambiguity Fixes", "hidden": false }, + { "type": "punctua", "section": "Punctuation Fixes", "hidden": false }, + { "type": "chore", "section": "Chores", "hidden": false }, + { "type": "ci", "section": "CI", "hidden": true } + ] + } + } + ], + [ + "@semantic-release/github", + { + "assets": [ + { "path": "ebook/epub/药娘的天空.epub", "name": "transky-${nextRelease.version}.epub" }, + { "path": "ebook/mobi/药娘的天空.mobi", "name": "transky-${nextRelease.version}.mobi" }, + { "path": "ebook/typst-pdf/药娘的天空.pdf", "name": "transky-${nextRelease.version}.pdf" } + ], + "successComment": false, + "failComment": false + } + ], + [ + "@saithodev/semantic-release-backmerge", + { + "backmergeBranches": [{ "from": "stable", "to": "main" }], + "clearWorkspace": true + } + ] + ] +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..277c7b65 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,138 @@ +# 贡献指南 + +## 用语规范 + +本项目贡献者包括跨性别者等多元文化群体,请在贡献时尊重 ta 人,使用友善礼貌的词语。 + +## 提交规范 + +> 提交说明中所有字段均应在 CJK 字符与非 CJK 字符间插入空格。 + +提交说明格式: + +``` +[()]: +<空行> + +<空行> +