From 80d0314ca2ddabc3393697c21ccadc9879f28b17 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 12 Jul 2021 13:37:25 -0700 Subject: [PATCH 1/3] Added script and workflow to automatically update build artifact sizes in check_metadata.sh --- .github/workflows/update_metadata.yml | 39 +++++++++++++++++++++++++++ tests/scripts/update_metadata.sh | 31 +++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 .github/workflows/update_metadata.yml create mode 100755 tests/scripts/update_metadata.sh diff --git a/.github/workflows/update_metadata.yml b/.github/workflows/update_metadata.yml new file mode 100644 index 000000000..5b5e401fa --- /dev/null +++ b/.github/workflows/update_metadata.yml @@ -0,0 +1,39 @@ +# This workflow updates the check_metadata.sh script, which compares the current +# size of build artifacts against their size in the previous version of Blockly. + +name: Update Metadata + +on: [workflow_dispatch] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + node-version: [16.x] + + steps: + - name: Check Out Blockly + uses: actions/checkout@v2 + with: + ref: 'develop' + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Update Metadata + run: source ./tests/scripts/update_metadata.sh + + - name: Create Pull Request + uses: peter-evans/create-pull-request@9825ae65b1cb54b543b938503728b432a0176d29 + with: + commit-message: Updated build artifact sizes in check_metadata.sh + delete-branch: true + title: Updated build artifact sizes in check_metadata.sh + + - name: View Pull Request + run: echo "View Pull Request - ${{ steps.cpr.outputs.pull-request-url }}" \ No newline at end of file diff --git a/tests/scripts/update_metadata.sh b/tests/scripts/update_metadata.sh new file mode 100755 index 000000000..cfd2f43d0 --- /dev/null +++ b/tests/scripts/update_metadata.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Determines the size of generated files and updates check_metadata.sh to +# reflect the new values. + +blockly_size=$(wc -c < "blockly_compressed.js") +blocks_size=$(wc -c < "blocks_compressed.js") +blockly_gz_size=$(wc -c < "blockly_compressed.js.gz") +blocks_gz_size=$(wc -c < "blocks_compressed.js.gz") +quarter=$(date "+Q%q %Y") +version=$(npx -c 'echo "$npm_package_version"') + +replacement="# ${quarter}\t${version}\t${blockly_size}\n" +replacement+="readonly BLOCKLY_SIZE_EXPECTED=${blockly_size}" +sed -ri "s/readonly BLOCKLY_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh + +replacement="# ${quarter}\t${version}\t${blocks_size}\n" +replacement+="readonly BLOCKS_SIZE_EXPECTED=${blocks_size}" +sed -ri "s/readonly BLOCKS_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh + +replacement="# ${quarter}\t${version}\t${blockly_gz_size}\n" +replacement+="readonly BLOCKLY_GZ_SIZE_EXPECTED=${blockly_gz_size}" +sed -ri "s/readonly BLOCKLY_GZ_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh + +replacement="# ${quarter}\t${version}\t${blocks_gz_size}\n" +replacement+="readonly BLOCKS_GZ_SIZE_EXPECTED=${blocks_gz_size}" +sed -ri "s/readonly BLOCKS_GZ_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh \ No newline at end of file From 1fd4b9bb21aa42fbdd191cb89a670c61190d6cff Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 13 Jul 2021 08:43:52 -0700 Subject: [PATCH 2/3] Calculate metadata size from freshly-built and gzipped Blockly. --- .github/workflows/update_metadata.yml | 29 +++++++++++++++++---------- tests/scripts/update_metadata.sh | 8 ++++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.github/workflows/update_metadata.yml b/.github/workflows/update_metadata.yml index 5b5e401fa..7b83b5a03 100644 --- a/.github/workflows/update_metadata.yml +++ b/.github/workflows/update_metadata.yml @@ -6,13 +6,8 @@ name: Update Metadata on: [workflow_dispatch] jobs: - build: - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [ubuntu-latest] - node-version: [16.x] + update-metadata: + runs-on: ubuntu-latest steps: - name: Check Out Blockly @@ -20,10 +15,22 @@ jobs: with: ref: 'develop' - - name: Use Node.js ${{ matrix.node-version }} + - name: Use Node.js 16.x uses: actions/setup-node@v1 with: - node-version: ${{ matrix.node-version }} + node-version: 16.x + + - name: Build Blockly + run: npm run build:compressed + + - name: Build Blockly blocks + run: npm run build:blocks + + - name: Gzip Blockly + run: gzip -k build/blockly_compressed.js + + - name: Gzip Blockly blocks + run: gzip -k build/blocks_compressed.js - name: Update Metadata run: source ./tests/scripts/update_metadata.sh @@ -31,9 +38,9 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@9825ae65b1cb54b543b938503728b432a0176d29 with: - commit-message: Updated build artifact sizes in check_metadata.sh + commit-message: Update build artifact sizes in check_metadata.sh delete-branch: true - title: Updated build artifact sizes in check_metadata.sh + title: Update build artifact sizes in check_metadata.sh - name: View Pull Request run: echo "View Pull Request - ${{ steps.cpr.outputs.pull-request-url }}" \ No newline at end of file diff --git a/tests/scripts/update_metadata.sh b/tests/scripts/update_metadata.sh index cfd2f43d0..d0dac71e7 100755 --- a/tests/scripts/update_metadata.sh +++ b/tests/scripts/update_metadata.sh @@ -3,10 +3,10 @@ # Determines the size of generated files and updates check_metadata.sh to # reflect the new values. -blockly_size=$(wc -c < "blockly_compressed.js") -blocks_size=$(wc -c < "blocks_compressed.js") -blockly_gz_size=$(wc -c < "blockly_compressed.js.gz") -blocks_gz_size=$(wc -c < "blocks_compressed.js.gz") +blockly_size=$(wc -c < "build/blockly_compressed.js") +blocks_size=$(wc -c < "build/blocks_compressed.js") +blockly_gz_size=$(wc -c < "build/blockly_compressed.js.gz") +blocks_gz_size=$(wc -c < "build/blocks_compressed.js.gz") quarter=$(date "+Q%q %Y") version=$(npx -c 'echo "$npm_package_version"') From 8d33869a4a1b0fdee9d80ea73698093ae16bb7d7 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 10:58:08 -0700 Subject: [PATCH 3/3] Gzip build output files in update_metadata.sh instead of update_metadata.yml. --- .github/workflows/update_metadata.yml | 6 ------ tests/scripts/update_metadata.sh | 3 +++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/update_metadata.yml b/.github/workflows/update_metadata.yml index 7b83b5a03..82a36230f 100644 --- a/.github/workflows/update_metadata.yml +++ b/.github/workflows/update_metadata.yml @@ -26,12 +26,6 @@ jobs: - name: Build Blockly blocks run: npm run build:blocks - - name: Gzip Blockly - run: gzip -k build/blockly_compressed.js - - - name: Gzip Blockly blocks - run: gzip -k build/blocks_compressed.js - - name: Update Metadata run: source ./tests/scripts/update_metadata.sh diff --git a/tests/scripts/update_metadata.sh b/tests/scripts/update_metadata.sh index d0dac71e7..d3b97f3ab 100755 --- a/tests/scripts/update_metadata.sh +++ b/tests/scripts/update_metadata.sh @@ -3,6 +3,9 @@ # Determines the size of generated files and updates check_metadata.sh to # reflect the new values. +gzip -k build/blockly_compressed.js +gzip -k build/blocks_compressed.js + blockly_size=$(wc -c < "build/blockly_compressed.js") blocks_size=$(wc -c < "build/blocks_compressed.js") blockly_gz_size=$(wc -c < "build/blockly_compressed.js.gz")