test(ci): add build product checking for prs (#6558)

* test(ci): add build product checking for prs

- Add build product testing to the CI

* Fix error syntax

* Tweak with output table
This commit is contained in:
JeremyWuuuuu 2022-03-12 17:17:16 +08:00 committed by GitHub
parent 2db400c73a
commit 9172120d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 125 additions and 0 deletions

62
.github/workflows/build-product.yml vendored Normal file
View File

@ -0,0 +1,62 @@
name: Build Product 👮‍♂️
on: pull_request
jobs:
check:
name: Build Product Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Add dev branch
run: git branch dev origin/dev
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Cache ~/.pnpm-store
uses: actions/cache@v2
env:
cache-name: cache-pnpm-store
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ matrix.node-version }}-test-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-${{ matrix.node-version }}-test-${{ env.cache-name }}-
${{ runner.os }}-${{ matrix.node-version }}-test-
${{ runner.os }}-
- name: Install dependencies
run: pnpm i --frozen-lockfile
- name: Local build
run: pnpm build
- name: Check build product
run: sh -c ./scripts/file-check.sh
- name: Diff gen
run: pnpm diff:table
- name: Read diff file
id: diff
uses: juliangruber/read-file-action@v1
with:
path: ./tmp/diff.md
- name: Set comment
uses: actions-cool/maintain-one-comment@v2.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: ${{ steps.diff.outputs.content }}
body-include: '<sub>Generated with'

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ packages/element-plus/version.ts
*.local
cypress/screenshots/*
cypress/videos/*
tmp

View File

@ -21,6 +21,7 @@
"dev": "pnpm -C play dev",
"gen": "bash ./scripts/gc.sh",
"gen:version": "sucrase-node scripts/gen-version.ts",
"diff:table": "sucrase-node scripts/build-table.ts",
"update:version": "sucrase-node scripts/update-version.ts",
"clean": "pnpm run clean:dist && pnpm run clean -r --stream",
"clean:dist": "rimraf dist",

49
scripts/build-table.ts Normal file
View File

@ -0,0 +1,49 @@
import fs from 'fs/promises'
import path from 'path'
main()
async function main() {
let output: string
const diffOutput = await fs.readFile(
path.resolve(__dirname, '..', 'tmp/diff.txt'),
'utf-8'
)
const fileDiffs = diffOutput
.split('\n')
.map((s) => s.trim())
.filter((s) => s)
.map((s) => s.split(':'))
if (fileDiffs.length === 0) {
output = ''
} else {
const table = fileDiffs.reduce(
(prev, [source, filename]) => {
const row = `|${filename}`
let status: 'Added 🟢' | 'Removed ⛔️'
if (!source.startsWith('./dist')) {
status = 'Removed ⛔️'
} else {
status = 'Added 🟢'
}
return `${prev}
${row}|${status}|`
},
`| Filename | Status |
|:---|:---:|`
)
output = `**Total changed files:** ${fileDiffs.length}
<details><summary>:information_source: Files have been changed</summary>
${table}
</details>
<sub>Generated with :heart: by Element Plus bot</sub>`
}
await fs.writeFile(path.resolve(__dirname, '..', 'tmp/diff.md'), output)
}

12
scripts/file-check.sh Executable file
View File

@ -0,0 +1,12 @@
#! /bin/bash
CURRENT_PUBLISHED_TARBALL="$(npm view element-plus dist.tarball)"
echo $CURRENT_PUBLISHED_TARBALL
mkdir -p tmp
curl -o ./tmp/latest.tgz $CURRENT_PUBLISHED_TARBALL
tar zxvf ./tmp/latest.tgz -C ./tmp
diff -qr ./tmp/package ./dist/element-plus | grep "Only" | cut -c 8- | sort > ./tmp/diff.txt