Skip to content

Commit

Permalink
test(ci): add build product checking for prs (element-plus#6558)
Browse files Browse the repository at this point in the history
* test(ci): add build product checking for prs

- Add build product testing to the CI

* Fix error syntax

* Tweak with output table
  • Loading branch information
jw-foss authored Mar 12, 2022
1 parent 2db400c commit 9172120
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/build-product.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: ${{ steps.diff.outputs.content }}
body-include: '<sub>Generated with'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ packages/element-plus/version.ts
*.local
cypress/screenshots/*
cypress/videos/*
tmp
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
49 changes: 49 additions & 0 deletions scripts/build-table.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions scripts/file-check.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9172120

Please sign in to comment.