From 9172120d52f60d6e3c42cf5b0f9c89fc456f162b Mon Sep 17 00:00:00 2001 From: JeremyWuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> Date: Sat, 12 Mar 2022 17:17:16 +0800 Subject: [PATCH] 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 --- .github/workflows/build-product.yml | 62 +++++++++++++++++++++++++++++ .gitignore | 1 + package.json | 1 + scripts/build-table.ts | 49 +++++++++++++++++++++++ scripts/file-check.sh | 12 ++++++ 5 files changed, 125 insertions(+) create mode 100644 .github/workflows/build-product.yml create mode 100644 scripts/build-table.ts create mode 100755 scripts/file-check.sh diff --git a/.github/workflows/build-product.yml b/.github/workflows/build-product.yml new file mode 100644 index 0000000000..510c6daf44 --- /dev/null +++ b/.github/workflows/build-product.yml @@ -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: 'Generated with' diff --git a/.gitignore b/.gitignore index ada93b4aac..2a86f07048 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ packages/element-plus/version.ts *.local cypress/screenshots/* cypress/videos/* +tmp diff --git a/package.json b/package.json index a72297b33b..171238c782 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/build-table.ts b/scripts/build-table.ts new file mode 100644 index 0000000000..074369b1ac --- /dev/null +++ b/scripts/build-table.ts @@ -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} + +
:information_source: Files have been changed + +${table} + +
+ +Generated with :heart: by Element Plus bot` + } + + await fs.writeFile(path.resolve(__dirname, '..', 'tmp/diff.md'), output) +} diff --git a/scripts/file-check.sh b/scripts/file-check.sh new file mode 100755 index 0000000000..0c341f4770 --- /dev/null +++ b/scripts/file-check.sh @@ -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