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

feat: 新版 polyfill 生成机制 #410

Merged
merged 17 commits into from
Jan 23, 2024
Merged
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
1 change: 0 additions & 1 deletion .browserslistrc

This file was deleted.

4 changes: 1 addition & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ src/**/*.json linguist-generated=false
src/*.json linguist-generated=false
src/**/*.yaml linguist-generated=false
src/*.yaml linguist-generated=false

# From generatePolyfill
src/gadgets/libPolyfill/MediaWiki:Gadget-libPolyfill.js linguist-generated=true
src/gadgets/libPolyfill/MediaWiki:Gadget-libPolyfill.*.js linguist-generated=true

# From ganerateCommitsHistory
src/global/zh/MediaWiki:GHIAHistory.json linguist-generated=true
Expand Down
39 changes: 0 additions & 39 deletions .github/workflows/generateConfiguration.yaml

This file was deleted.

93 changes: 93 additions & 0 deletions .github/workflows/generatePolyfill.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Generate Polyfill

on:
push:
paths:
- .github/workflows/generatePolyfill.yaml
- scripts/generatePolyfill/config.yaml
- scripts/generatePolyfill/index.js
merge_group:
pull_request:
paths:
- .github/workflows/generatePolyfill.yaml
- scripts/generatePolyfill/config.yaml
- scripts/generatePolyfill/index.js
workflow_dispatch:
schedule:
- cron: 0 23 * * 0 # Every 07:00 CST Mon

concurrency:
group: ${{ github.workflow_ref }}-${{ github.ref }}

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

permissions:
actions: write
checks: read
contents: write
deployments: read
issues: write
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: write
statuses: write

jobs:
generatePolyfill:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Checkout main repo
with:
fetch-depth: 0
show-progress: false
- name: Get the polyfill config
id: polyfillConfig
run: |
echo "TARGET_POLYFILL_VERSION=$(yq '.TARGET_POLYFILL_VERSION' scripts/generatePolyfill/config.yaml)" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- uses: actions/checkout@v4
name: Checkout polyfill.io
with:
show-progress: false
repository: JakeChampion/polyfill-service
path: polyfill-service
sparse-checkout: |
polyfill-libraries/${{ steps.polyfillConfig.outputs.TARGET_POLYFILL_VERSION }}/
polyfill-libraries/${{ steps.polyfillConfig.outputs.TARGET_POLYFILL_VERSION }}.json
sparse-checkout-cone-mode: false
- name: Move polyfill.io
id: polyfill
run: |
POLYFILL_PATH="${{ runner.temp }}/$(uuidgen)"
echo "POLYFILL_PATH=$POLYFILL_PATH" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
mkdir -pv $POLYFILL_PATH
mv polyfill-service/polyfill-libraries/${{ steps.polyfillConfig.outputs.TARGET_POLYFILL_VERSION }}.json $POLYFILL_PATH/main.json
mv polyfill-service/polyfill-libraries/${{ steps.polyfillConfig.outputs.TARGET_POLYFILL_VERSION }}/ $POLYFILL_PATH/library
rm -rf polyfill-service
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
check-latest: true
cache: npm
- name: Installing the dependencies
uses: AnnAngela/cached_node-modules@v2
with:
command: npm run ci
- name: Git config
run: node scripts/postCommit/prepareGit.js
- name: Gadget-polyfill generator
run: node scripts/generatePolyfill/index.js
env:
POLYFILL_PATH: ${{ steps.polyfill.outputs.POLYFILL_PATH }}
- name: Show git status & push
id: output
run: node scripts/postCommit/push.js
env:
DISPATCH_POST_COMMIT_WORKFLOW: true
7 changes: 3 additions & 4 deletions .github/workflows/postCommit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- scripts/**/*.js
- scripts/**/*.yaml
- "!scripts/test/*.js"
- "!scripts/generateUnrecognizableFeatures/*.js"
- "!scripts/generatePolyfill/*.js"
- "!scripts/detectHardcodedOutdatedNPMPackages/*.js"
- "!scripts/detectHardcodedOutdatedNPMPackages/*.yaml"
- "!scripts/autoAssign/*.js"
Expand All @@ -25,7 +25,7 @@ on:
- scripts/**/*.js
- scripts/**/*.yaml
- "!scripts/test/*.js"
- "!scripts/generateUnrecognizableFeatures/*.js"
- "!scripts/generatePolyfill/*.js"
- "!scripts/detectHardcodedOutdatedNPMPackages/*.js"
- "!scripts/detectHardcodedOutdatedNPMPackages/*.yaml"
- "!scripts/autoAssign/*.js"
Expand Down Expand Up @@ -92,6 +92,7 @@ jobs:
if: always() && needs.skipCI.result == 'success' && needs.skipCI.outputs.skip != 'true'
steps:
- uses: actions/checkout@v4
name: Checkout main repo
with:
fetch-depth: 0
show-progress: false
Expand All @@ -113,8 +114,6 @@ jobs:
run: node scripts/browserify/index.js
- name: Auto prefetch
run: node scripts/prefetch/index.js
- name: Gadget-polyfill generator
run: node scripts/generatePolyfill/index.js
- name: Gadgets-definition Generator
run: node scripts/generateGadgetsDefinition/index.js
- name: Conventional Commits scopes generator
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@
<details><summary>仓库架构详情</summary>

- [`.github`](.github) 文件夹用以保存 GitHub Dependabot 和 GitHub Actions 所需配置文件,其中:
- [`.github/workflows/postCommit.yaml`](.github/workflows/postCommit.yaml) 用以保存自动化流程,包含自动配置 Conventional Commits(约定式提交)所需 scope(作用域)信息、自动导入来自 npm 和指定页面的代码、自动补全小工具列表和自动生成 polyfill 文件;
- [`.github/workflows/generateUnrecognizableFeatures.yaml`](.github/workflows/generateUnrecognizableFeatures.yaml) 用以定时生成 [`scripts/generatePolyfill/unrecognizableFeatures.json`](scripts/generatePolyfill/unrecognizableFeatures.json) 以减少生成 polyfill 时的网络请求
- [`.github/workflows/auto_assign.yaml`](.github/workflows/auto_assign.yaml) 用以自动对 pull request 和 issue 添加 assignees 和 reviewers(若有)。
- [`.github/workflows/postCommit.yaml`](.github/workflows/postCommit.yaml) 用以保存自动化流程,包含自动配置 Conventional Commits(约定式提交)所需 scope(作用域)信息、自动导入来自 npm 和指定页面的代码、自动补全小工具列表;:
- [`.github/workflows/postCommit.yaml`](.github/workflows/postCommit.yaml) 用以自动生成 polyfill 文件
- [`.github/workflows/auto_assign.yaml`](.github/workflows/auto_assign.yaml) 用以自动对 pull request 和 issue 添加 assignees 和 reviewers(若有)。
- [`.vscode/settings.json`](.vscode/settings.json) 用来保存 Conventional Commits(约定式提交)所需 scope(作用域)信息;
- [`scripts`](scripts) 文件夹用以保存流程所需代码,其中:
- [`scripts/postCommit/prepareGit.js`](scripts/postCommit/prepareGit.js) 用来准备 Github Actions 上的 git 环境,自动生成 author 和 committer 的相关信息;
- [`scripts/browserify/index.js`](scripts/browserify/index.js) 用来通过 [browserify](https://browserify.org/) 库导入来自 npm 的代码,其目标在 [`scripts/browserify/targets.yaml`](scripts/browserify/targets.yaml) 中定义;
- [`scripts/prefetch/index.js`](scripts/prefetch/index.js) 用来导入来自指定页面的代码,其目标在 [`scripts/prefetch/targets.yaml`](scripts/prefetch/targets.yaml) 中定义;
- [`scripts/generatePolyfill/index.js`](scripts/generatePolyfill/index.js) 用来自动生成 polyfill 文件,该代码使用了来自《金融时报》的 [polyfill.io](https://polyfill.io/v3/)([Financial-Times/polyfill-service](https://github.com/Financial-Times/polyfill-service))和 [Financial-Times/polyfill-library](https://github.com/Financial-Times/polyfill-library);
- [`scripts/generatePolyfill/index.js`](scripts/generatePolyfill/index.js) 用来自动生成 polyfill 文件,该代码使用了 [JakeChampion/polyfill-service](https://github.com/JakeChampion/polyfill-service);
- [`scripts/generateGadgetsDefinition/index.js`](scripts/generateGadgetsDefinition/index.js) 用来自动补全小工具列表,当发现新增小工具时,该代码会自动将对应小工具插入到 [`src/gadgets/Gadgets-definition-list.yaml`](src/gadgets/Gadgets-definition-list.yaml) 的响应列表的末尾;
- [`scripts/generateConventionalCommitsScopes/index.js`](scripts/generateConventionalCommitsScopes/index.js) 用来自动配置 Conventional Commits(约定式提交)所需 scope(作用域)信息;
- [`scripts/postCommit/linguist-generated.js`](scripts/postCommit/linguist-generated.js) 用来自动生成 [`.gitattributes`](.gitattributes) 以告知 Github 如何区分代码是否自动生成;
- [`scripts/postCommit/push.js`](scripts/postCommit/push.js) 用来推送由 Github Actions 做出的更改;
- [`scripts/generateUnrecognizableFeatures/index.js`](scripts/generateUnrecognizableFeatures/index.js) 用来生成 [`scripts/generatePolyfill/unrecognizableFeatures.json`](scripts/generatePolyfill/unrecognizableFeatures.json) 以减少生成 polyfill 时的网络请求;
- [`scripts/emailmapChecker/index.js`](scripts/emailmapChecker/index.js) 用来检查相关用户是否将其萌娘百科用户名和邮箱地址添加到 [`.mailmap`](.mailmap),若当前环境为本地则检测 git 配置文件里的邮箱地址,若当前环境为 Github Actions 则检查相关 commits 的邮箱地址。
- [`scripts/ci/before.js`](scripts/ci/before.js) 和 [`scripts/ci/after.js`](scripts/ci/after.js) 用来在 `npm run ci` 里自动替换 [`package-lock.json`](package-lock.json) 里的 `resolved` 对应的 registry 为你本地设置的 registry,有助于加快安装速度。
- 自动化工具的配置文件:
Expand Down Expand Up @@ -64,7 +63,7 @@

## 自动化流程

- 每周一 00:00 UTC 会自动触发一次 generateUnrecognizableFeatures CI;
- 每周日 23:00 UTC 会自动触发一次 Generate Polyfill CI;
- 每天 00:15 UTC(但愿,Github Actions的 cron 延迟真的好高 \_(:з」∠)\_)会自动触发一次 postCommit CI;
- 每提交一次 commit(包括提交 pull request 和在 pull request 里提交新的 commit),postCommit CI 会触发;
- 当 postCommit CI 检测到新内容时,会自动触发一次 Linter test。
Expand Down
9 changes: 6 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ignores = [
"**/dist/**",
"**/.*/**",
"node_modules",
"src/gadgets/libPolyfill/*",
];

const srcESlintrcFiles = (await readDir("./src")).filter((n) => path.basename(n) === ".eslintrc.yaml");
Expand All @@ -34,9 +35,11 @@ const fileSpec = {
browser: {
files: [
"src/**/*",
"scripts/generatePolyfill/template.js",
"scripts/generatePolyfill/customPolyfills/**/*",
],
ignores: [
...ignores,
],
ignores,
},
node: {
files: [
Expand All @@ -45,7 +48,7 @@ const fileSpec = {
],
ignores: [
...ignores,
"scripts/generatePolyfill/template.js",
"scripts/generatePolyfill/customPolyfills/**/*",
],
},
};
Expand Down
Loading