From a58a31a4268ab832dd59a7949b32adca8aa44a58 Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 7 Jan 2022 19:27:43 +0100 Subject: [PATCH] fix: test if that works :/ --- .github/workflows/deploy.yml | 2 +- .github/workflows/main.yml | 7 +++++-- scripts/compare-size.js | 31 ++++++++++++++----------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3b00bc028..f2a7a74af 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,7 +29,7 @@ jobs: - name: cache bundle size uses: actions/cache@v2 with: - path: stats.json + path: stats-${{ github.sha }}.json key: stats-${{ github.sha }} # upload to ipfs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 55ab6c255..4b55cef1b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,16 +35,19 @@ jobs: - name: download cached bundle size uses: actions/cache@v2 with: - path: stats_head.json + path: stats-${{ github.event.pull_request.base.sha }}.json key: stats-${{ github.event.pull_request.base.sha }} - name: store hash bundle size uses: actions/cache@v2 with: - path: stats.json + path: stats-${{ github.sha }}.json key: stats-${{ github.sha }} - uses: actions/github-script@v5 + env: + BASE: ${{ github.event.pull_request.base.sha }} + HEAD: ${{ github.sha }} with: script: | const script = require('./scripts/compare-size') diff --git a/scripts/compare-size.js b/scripts/compare-size.js index 3f529f3fd..345cb1b75 100644 --- a/scripts/compare-size.js +++ b/scripts/compare-size.js @@ -1,6 +1,3 @@ -const stats = require('../stats.json'); -const headStats = require('../stats_head.json'); - /** * Whenever a pr is merged to master the ci will take a snapshot of the sourcemaps generated. * When a pr is created or a commit is pushed the ci will: @@ -14,22 +11,22 @@ const headStats = require('../stats_head.json'); * When the diff is >1kb, the ci will comment the bundle size difference. */ module.exports = async ({ github, context }) => { - if (context.eventName === 'pull_request') { - const masterMainChunk = headStats.results.find((chunk) => /js\/main/.test(chunk.bundleName)); - const masterMB = masterMainChunk.totalBytes / 1024 / 1024; + const stats = require(`../stats-${process.env.HEAD}.json`); + const headStats = require(`../stats-${process.env.BASE}.json`); + const masterMainChunk = headStats.results.find((chunk) => /js\/main/.test(chunk.bundleName)); + const masterMB = masterMainChunk.totalBytes / 1024 / 1024; - const currentMainChunk = stats.results.find((chunk) => /js\/main/.test(chunk.bundleName)); - const currentMB = currentMainChunk.totalBytes / 1024 / 1024; + const currentMainChunk = stats.results.find((chunk) => /js\/main/.test(chunk.bundleName)); + const currentMB = currentMainChunk.totalBytes / 1024 / 1024; - const diff = currentMB - masterMB; + const diff = currentMB - masterMB; - if (Math.abs(diff) > 0.001) { - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: `Bundle size change: ${diff} MB`, - }); - } + if (Math.abs(diff) > 0.001) { + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `Bundle size change: ${diff} MB`, + }); } };