Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: refactor workflow #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions .github/workflows/build.yaml → .github/workflows/ebook.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
name: Build releases
name: Build ebook and release

on:
workflow_dispatch:
inputs:
release:
description: Publish a release
required: true
type: boolean
pull_request:
push:
branches:
- "main"
- "release"
paths:
- ".github/workflows/build.yaml"
- ".vitepress/**"
- ".github/workflows/ebook.yaml"
- "src/**"
- "theme/**"
- "book.toml"
- "package-lock.json"
- "package.json"

permissions:
contents: write
issues: write
pull-requests: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -48,19 +46,48 @@ jobs:

- 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

- uses: actions/upload-artifact@v4
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
path: |
result/share/transky-book/book/epub/药娘的天空.epub
result/share/transky-book/book/typst-pdf/药娘的天空.pdf
result/share/transky-book/book/mobi/药娘的天空.mobi

- name: Release eBook
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
release:
permissions:
contents: write
needs: build
if: github.event_name != 'pull_request' && ( ( github.event_name == 'push' && ! contains( github.event.head_commit.message, '[skip release]' ) ) || ( github.event_name == 'workflow_dispatch' && inputs.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

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: current

- name: Install semantic-release
run: |
rm pnpm-lock.yaml
pnpm add semantic-release conventional-changelog-conventionalcommits @saithodev/semantic-release-backmerge

- name: Download artifacts
uses: actions/download-artifact@v4

- name: Release ebook
env:
GITHUB_TOKEN: ${{ github.token }}
run: exit 0
run: pnpm exec semantic-release
20 changes: 6 additions & 14 deletions .github/workflows/publish.yaml → .github/workflows/web.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish to Cloudflare
name: Build website and publish

on:
workflow_dispatch:
Expand All @@ -7,17 +7,11 @@ on:
branches:
- "main"
paths:
- ".github/workflows/publish.yaml"
- ".github/workflows/web.yaml"
- ".vitepress/**"
- "src/**"
- "theme/**"
- "package-lock.json"
- "package.json"

permissions:
contents: write
issues: write
pull-requests: write
- "pnpm-lock.yaml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -38,20 +32,18 @@ jobs:
version: latest
run_install: true

- uses: actions/setup-node@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: pnpm
node-version: current

- name: Install
run: pnpm install

- 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 web:build
pnpm run build

- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
Expand Down
221 changes: 168 additions & 53 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -1,53 +1,168 @@
branches:
- main
plugins:
- - "@semantic-release/commit-analyzer"
- releaseRules:
- type: feat
release: minor
- type: fix
release: minor
- type: refactor
release: patch
- type: style
release: patch
- type: typo
release: patch
- type: grammar
release: patch
- type: ambig
release: patch
- type: punctua
release: patch
- "@semantic-release/release-notes-generator"
- - "@semantic-release/github"
- assets:
- path: book/epub/药娘的天空.epub
name: transky-${nextRelease.version}.epub
- path: book/mobi/药娘的天空.mobi
name: transky-${nextRelease.version}.mobi
- path: book/typst-pdf/药娘的天空.pdf
name: transky-${nextRelease.version}.pdf
preset: conventionalcommits
presetConfig:
- types:
- type: feat
section: Features
- type: fix
section: Bug Fixes
- type: refactor
hidden: true
- type: style
section: Style Improvements
- type: typo
section: Typo Fixes
- type: grammar
section: Grammar Fixes
- type: ambig
section: Ambiguity Fixes
- type: punctua
section: Punctuation Fixes
- type: chore
hidden: true
- type: ci
hidden: true
{
"branches": [
{
"name": "main",
"prerelease": true
},
{
"name": "release",
"prerelease": false
}
],
"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": "refactor",
"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": "refactor",
"section": "Refactors",
"hidden": false
},
{
"type": "style",
"section": "Style Improves",
"hidden": false
},
{
"type": "typo",
"section": "Typo Fixes",
"hidden": false
},
{
"type": "grammar",
"section": "Grammar Fixes",
"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
},
{
"type": "revert",
"section": "Reverts",
"hidden": false
}
]
}
}
],
[
"@semantic-release/github",
{
"assets": [
{
"path": "artifact/epub/药娘的天空.epub",
"name": "transky-${nextRelease.version}.epub"
},
{
"path": "artifact/mobi/药娘的天空.mobi",
"name": "transky-${nextRelease.version}.mobi"
},
{
"path": "artifact/typst-pdf/药娘的天空.pdf",
"name": "transky-${nextRelease.version}.pdf"
}
],
"successComment": false,
"failComment": false
}
],
[
"@saithodev/semantic-release-backmerge",
{
"backmergeBranches": [
{
"from": "release",
"to": "main"
}
],
"mergeMode": "ours"
}
]
]
}
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ Scope 字段描述提交的更改范围。此字段为可选字段。

Subject 字段用于简短地描述提交。此字段应以动词开头,并使用第一人称、一般现在时。此字段首字母小写,句尾不添加句号,中文也是如此。

###### 特殊标签

以下标签具有特殊效果,应放置在 Subject 字段末尾:

- `[skip ci]`:跳过 CI 构建

- `[skip release]`:跳过发布 Release

#### <a name="body"></a>Body 部分

Body 部分是提交说明的主体。此部分用于详细描述此提交。此部分使用第一人称、一般现在时。此字段首字母大写,句尾添加句号。
Expand Down
Loading
Loading