chore(actions): build_release

This commit is contained in:
lisonge 2023-11-05 02:03:27 +08:00
parent b1a3310841
commit 0da957ee31
8 changed files with 61 additions and 1846 deletions

View File

@ -1,15 +1,12 @@
name: Release
name: build_release
on:
push:
branches:
- 'main'
on: workflow_dispatch
jobs:
release:
# prevent run on fork
if: ${{ github.repository == 'gkd-kit/subscription' && startsWith(github.event.head_commit.message, 'chore(main):') && contains(github.event.head_commit.message, 'release') }}
build_release:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
@ -25,6 +22,11 @@ jobs:
- run: pnpm run build
- id: version
run: |
version=$(pnpm show @gkd-kit/subscription version)
echo "version=${version}" >> "$GITHUB_OUTPUT"
- name: Git commit
id: commit
run: |
@ -34,15 +36,26 @@ jobs:
git config --global core.safecrlf false
git status
git add .
git commit -m "build: json,readme" -a
git commit -a -m "chore: v${{steps.version.outputs.version}}"
git tag ${{steps.version.outputs.version}}
continue-on-error: true
- name: Git push
uses: ad-m/github-push-action@master
if: ${{ steps.commit.outcome == 'success' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true
- name: Create Release
if: ${{ steps.commit.outcome == 'success' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.version }}
release_name: Release ${{ steps.version.outputs.version }}
- name: Publish package
if: ${{ steps.commit.outcome == 'success' }}
@ -51,4 +64,5 @@ jobs:
pnpm publish
- name: sync npmmirror
if: ${{ steps.commit.outcome == 'success' }}
run: curl -X PUT 'https://registry-direct.npmmirror.com/@gkd-kit/subscription/sync'

View File

@ -1,16 +0,0 @@
name: release-please
on: workflow_dispatch
permissions:
contents: write
pull-requests: write
jobs:
release-please:
if: github.repository == 'gkd-kit/subscription'
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
with:
release-type: node

File diff suppressed because it is too large Load Diff

21
dist/test.json vendored
View File

@ -1,21 +0,0 @@
{
"name": "GKD-我测你们码",
"id": 1,
"version": 1,
"author": "lisonge",
"supportUrl": "https://github.com/gkd-kit/subscription",
"apps": [
{
"id": "li.songe.gkd.debug",
"groups": [
{
"key": 0,
"name": "测试语法错误",
"rules": [
"[text^='跳过'syntax_error] + * >2 TextView[text*='跳转']"
]
}
]
}
]
}

8
dist/test1.json vendored
View File

@ -1,8 +0,0 @@
{
"name": "GKD-漂亮滴很呐",
"id": 2,
"version": 0,
"author": "lisonge",
"supportUrl": "https://github.com/gkd-kit/subscription",
"apps": []
}

8
dist/test2.json vendored
View File

@ -1,8 +0,0 @@
{
"name": "GKD-cancanneed",
"id": 3,
"version": 0,
"author": "lisonge",
"supportUrl": "https://github.com/gkd-kit/subscription",
"apps": []
}

8
dist/test3.json vendored
View File

@ -1,8 +0,0 @@
{
"name": "GKD-鸡你太美",
"id": 4,
"version": 0,
"author": "lisonge",
"supportUrl": "https://github.com/gkd-kit/subscription",
"apps": []
}

View File

@ -2,6 +2,7 @@ import _ from 'lodash';
import fs from 'node:fs/promises';
import path from 'node:path';
import { parseSelector } from './selector';
import type PkgT from '../package.json';
import type { AppConfig, IArray, SubscriptionConfig } from './types';
const iArrayToArray = <T>(array: IArray<T> = []): T[] => {
@ -18,6 +19,26 @@ const sortKeys: (keyof SubscriptionConfig)[] = [
'apps',
];
const orderdStringify = (
obj: any,
keys: string[],
replacer?: (this: any, key: string, value: any) => any,
space?: string | number,
) => {
const map = new Map<string, unknown>();
keys.forEach((k) => {
if (obj[k] === undefined) return;
map.set(k, obj[k]);
});
return (
JSON.stringify(Object.fromEntries(map.entries()), replacer, space) + '\n'
);
};
const pkg: typeof PkgT = JSON.parse(
await fs.readFile(process.cwd() + '/package.json', 'utf-8'),
);
const pkgKeys = Object.keys(pkg);
export const writeConfig = async (fp: string, config: SubscriptionConfig) => {
const oldConfig: SubscriptionConfig = JSON.parse(
await fs.readFile(fp, 'utf-8').catch(() => '{}'),
@ -31,33 +52,30 @@ export const writeConfig = async (fp: string, config: SubscriptionConfig) => {
checkConfig(newConfig);
const hasUpdate = !_.isEqual(newConfig, oldConfig);
if (hasUpdate) {
newConfig.version++;
}
// update md
await updateReadMeMd(newConfig, oldConfig);
console.log('更新文档');
if (!hasUpdate) {
console.log('没有检测到规则变化,跳过更新JSON');
console.log('暂无规则变化');
return;
}
// keep json key sort by map
const map = new Map<string, unknown>();
sortKeys.forEach((k) => {
if (newConfig[k] === undefined) return;
map.set(k, newConfig[k]);
});
const buffer = Buffer.from(
JSON.stringify(Object.fromEntries(map.entries())),
newConfig.version++;
// update md
await updateReadMeMd(newConfig, oldConfig);
// update package.json
pkg.version = `1.${newConfig.version}.0`;
await fs.writeFile(
process.cwd() + '/package.json',
orderdStringify(pkg, pkgKeys, undefined, 2),
'utf-8',
);
// update gkd.json
const buffer = Buffer.from(orderdStringify(newConfig, sortKeys), 'utf-8');
await fs.writeFile(fp, buffer);
console.log(
`更新订阅: 版本:${newConfig.version}, 文件大小: ${
`更新订阅: v${newConfig.version}, 文件大小: ${
(buffer.length / 1024).toFixed(3) + 'KB'
}`,
);
@ -283,6 +301,7 @@ export const updateReadMeMd = async (
}),
);
if (changeCount <= 0) return;
console.log('更新文档: ' + changeCount);
const appListText =
'| 名称 | ID | 规则组 |\n| - | - | - |\n' +