Skip to content

Commit

Permalink
ci(metadata): 添加 CD 配置 | Add CD configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuoqiu-Yingyi committed Jun 21, 2023
1 parent a102e9f commit 7eccd4b
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 4 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# 构建并部署 | Build and deploy

name: build

on:
workflow_dispatch:
push:
tags:
# REF https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
- "v[0-9]+.[0-9]+.[0-9]+"

env:
PACKAGE_PATH: ./workspace/widgets/metadata

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Checkout
# REF https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v3
with:
## 将要拉取的仓库 | repository will to pull
repository: Zuoqiu-Yingyi/siyuan-packages-monorepo

# Install Node.js
# REF https://github.com/marketplace/actions/setup-node-js-environment
- name: Install Node.js
uses: actions/setup-node@v3
with:
## Node.js 版本号 | Node.js version
node-version: 20

## Node.js 源 | Node.js registry
registry-url: https://registry.npmjs.org

# Install pnpm
# REF https://github.com/marketplace/actions/setup-pnpm
- name: Install pnpm
uses: pnpm/action-setup@v2
id: pnpm-install
with:
## pnpm 版本号 | pnpm version
version: 8

## 是否安装 npm 包 | if install npm package?
run_install: false

# Get pnpm store directory
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
# Setup pnpm cache
# REF https://github.com/marketplace/actions/cache
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
# Install dependencies
- name: Install dependencies
run: |
cd $GITHUB_WORKSPACE
cd ./workspace
pnpm install
# Build package
- name: Build package
run: |
cd $GITHUB_WORKSPACE
cd $PACKAGE_PATH
pnpm build
# Deploy to publish branch
# REF https://github.com/marketplace/actions/github-pages
- name: Deploy to publish branch
if: success()
uses: crazy-max/ghaction-github-pages@v3
with:
## 构建产物目录 | directory of build artifacts
build_dir: ${{ env.PACKAGE_PATH }}/dist

## 提交到目标分支
target_branch: publish
env:
GITHUB_TOKEN: ${{ secrets.PAT_ACTIONS }}
81 changes: 81 additions & 0 deletions .github/workflows/release-distribution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 发行构建产物 | Release the distribution

name: release-distribution

on:
workflow_dispatch:
# REF https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
workflow_run:
workflows:
- build
types:
- completed
push:
branches:
- publish

permissions:
contents: write

jobs:
release-distribution:
runs-on: ubuntu-latest
steps:
# Checkout
# REF https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v3
with:
ref: publish

# Package
- name: Package
run: |
git archive -o ./package.zip HEAD
# Get latest release
# REF https://github.com/marketplace/actions/get-latest-release
- name: Get latest release
uses: pozetroninc/github-action-get-latest-release@v0.7.0
id: latest-release
with:
## 仓库所有者/仓库名 | owner/name
repository: ${{ github.repository }}

## 排除的发行类型 | Excluded types of release
# excludes: prerelease, draft
excludes: draft

# Get timestamp
# REF https://github.com/marketplace/actions/get-timestamp-action
- name: Get timestamp
uses: nanzm/get-time-action@v1.1
id: timestamp
with:
## 时区 | time zone
timeZone: 8

## 时间戳格式 | timestamp format
format: "YYYYMMDDHHmmss"

# Release distribution
# REF https://github.com/marketplace/actions/gh-release
- name: Release distribution
uses: softprops/action-gh-release@v1
with:
## 发行描述 | description of release
body: ${{ steps.latest-release.outputs.description }}

## 是否为预发行 | is prelease?
prerelease: true

## 标签名称 | tag name
# REF https://semver.org/
tag_name: ${{ steps.latest-release.outputs.release }}+${{ steps.timestamp.outputs.time }}

## 标签关联的提交/分支 | The commit/branch associated with the tag
target_commitish: publish

## 附件列表 | attachment list
files: |
package.zip
108 changes: 108 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# 发行源码 | Release the source code

name: release-please

on:
workflow_dispatch:
push:
branches:
- main

permissions:
contents: write
pull-requests: write


jobs:
release-please:
runs-on: ubuntu-latest
steps:
# Create release
# REF https://github.com/marketplace/actions/release-please-action
- name: Create release
uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: release-please-action

## A GitHub secret token, the action defaults to using the special secrets.GITHUB_TOKEN
## REF https://github.com/marketplace/actions/release-please-action#github-credentials
token: ${{ secrets.PAT_ACTIONS }}

## branch to open pull release PR against (detected by default)
default-branch: main

## Should breaking changes before 1.0.0 produce minor bumps? Default false
bump-minor-pre-major: false

## Should feat changes before 1.0.0 produce patch bumps instead of minor bumps? Default false
bump-patch-for-minor-pre-major: false

## If set, create releases that are pre-major or pre-release version marked as pre-release on GitHub. Defaults false
prerelease: true

## header used within the release PR body, defaults to using :robot: I have created a release *beep* *boop*
pull-request-header: ":robot: A new release will be created"

## A JSON formatted String containing to override the outputted changelog sections
changelog-types: |-
[
{
"type": "build",
"section": "Build System",
"hidden": false
},
{
"type": "chore",
"section": "Miscellaneous",
"hidden": false
},
{
"type": "ci",
"section": "Continuous Integration",
"hidden": false
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "feat",
"section": "Features",
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false
},
{
"type": "perf",
"section": "Performance Improvements"
},
{
"type": "refactor",
"section": "Code Refactoring",
"hidden": false
},
{
"type": "revert",
"section": "Reverts"
},
{
"type": "style",
"section": "Styles",
"hidden": false
},
{
"type": "test",
"section": "Tests",
"hidden": false
},
{
"type": "",
"section": "Other Changes",
"hidden": false
}
]
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
# widget-metadata
> **[READ ONLY] Subtree split of the [siyuan-packages-monorepo](https://github.com/Zuoqiu-Yingyi/siyuan-packages-monorepo) [/workspace/widgets/metadata](https://github.com/Zuoqiu-Yingyi/siyuan-packages-monorepo/tree/main/workspace/widgets/metadata)**
思源笔记文档块元数据挂件 | A Widget of document block metadata for SiYuan Note
<div align="center">
<img alt="icon" src="./public/icon.png" style="width: 8em; height: 8em;">

[README.md](./public/README.md)
---
[![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/Zuoqiu-Yingyi/widget-metadata?include_prereleases&style=flat-square)](https://github.com/Zuoqiu-Yingyi/widget-metadata/releases/latest)
[![GitHub Release Date](https://img.shields.io/github/release-date/Zuoqiu-Yingyi/widget-metadata?style=flat-square)](https://github.com/Zuoqiu-Yingyi/widget-metadata/releases/latest)
[![GitHub License](https://img.shields.io/github/license/Zuoqiu-Yingyi/widget-metadata?style=flat-square)](https://github.com/Zuoqiu-Yingyi/widget-metadata/blob/main/LICENSE)
[![GitHub last commit](https://img.shields.io/github/last-commit/Zuoqiu-Yingyi/widget-metadata?style=flat-square)](https://github.com/Zuoqiu-Yingyi/widget-metadata/commits/main)
![GitHub repo size](https://img.shields.io/github/repo-size/Zuoqiu-Yingyi/widget-metadata?style=flat-square)
![hits](https://hits.b3log.org/Zuoqiu-Yingyi/widget-metadata.svg)
[![GitHub all releases](https://img.shields.io/github/downloads/Zuoqiu-Yingyi/widget-metadata/total?style=flat-square)](https://github.com/Zuoqiu-Yingyi/widget-metadata/releases)

[CHANGELOG.md](./public/CHANGELOG.md)
---
</div>

## USER GUIDE

[简体中文](./public/README_zh_CN.md) \| [English](./public/README.md)

## DEVELOPMENT GUIDE

### RELEASE STEPS

1. Update the version number in `<subrepo-root-dir>/package.json` and `<subrepo-root-dir>/public/plugin.json`, then commit the changes in [monorepo](https://github.com/Zuoqiu-Yingyi/siyuan-packages-monorepo).
2. Run script `./scripts/git-subtree/metadata/push.ps1` with the folowing command in **monorepo root dir** to push the subtree to sub-repository (`dev` branch).
```powershell
pwsh -f "./scripts/git-subtree/metadata/push.ps1"
```
3. Create a pull request from `dev` branch to `main` branch in sub-repository.
4. Merge the pull request.
5. Await for the CD workflow `release-please.yml` to complete, it will create a *release pull request* in sub-repository.
6. Merge the *release pull request*, it will create a new *pre-release* with current [changelog](./CHANGELOG.md) and a new *tag* with [semantic version](https://semver.org/) in sub-repository.
7. Await for the CD workflow `build.yml` to complete, it will update the distribution files to `publish` branch in sub-repository.
8. Await for the CD workflow `release-distribution.yml` to complete, it will create a new *pre-release* with an asset named `package.zip` and a new *tag* with timestamp in sub-repository.

## CHANGELOG

[CHANGE LOG](./CHANGELOG.md)

0 comments on commit 7eccd4b

Please sign in to comment.