From 60b7e56c6e0593a66c4ffe9c38a6a71aede717f7 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 17 Nov 2023 11:41:12 +0100 Subject: [PATCH] add a "cleanup-checks" trigger action (#11354) Co-authored-by: phryneas --- .github/workflows/cleanup-checks.yml | 60 ++++++++++++++++++++++++++++ .size-limit.cjs | 12 ++++-- .size-limits.json | 4 ++ config/apiExtractor.ts | 2 +- package.json | 3 +- 5 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/cleanup-checks.yml create mode 100644 .size-limits.json diff --git a/.github/workflows/cleanup-checks.yml b/.github/workflows/cleanup-checks.yml new file mode 100644 index 00000000000..f2024175bd7 --- /dev/null +++ b/.github/workflows/cleanup-checks.yml @@ -0,0 +1,60 @@ +name: Clean up Prettier, Size-limit, and Api-Extractor + +on: + pull_request: + pull_request_review: + types: [submitted, edited] + +jobs: + add_cleanup_label: + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-a-workflow-when-a-pull-request-is-approved + if: | + github.repository == 'apollographql/apollo-client' && + github.event.review.state == 'APPROVED' && + contains(github.event.pull_request.labels.*.name, 'auto-cleanup') == false + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: add label + uses: actions-ecosystem/action-add-labels@v1 + with: + labels: auto-cleanup + + cleanup: + if: | + github.repository == 'apollographql/apollo-client' && + contains(github.event.pull_request.labels.*.name, 'auto-cleanup') + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Setup Node.js 18.x + uses: actions/setup-node@v4 + with: + node-version: 18.x + + - name: Install dependencies (with cache) + uses: bahmutov/npm-install@v1 + + - name: Run build + run: npm run build + + - name: Run Api-Extractor + run: npm run extract-api + env: + CI: "false" + + - name: Run prettier + run: npm run format + + - name: Update size-limit + run: npm run update-size-limits + + - name: Commit changes back + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Clean up Prettier, Size-limit, and Api-Extractor" + push_options: "" + skip_dirty_check: false diff --git a/.size-limit.cjs b/.size-limit.cjs index 427e2778948..b6edc78d7bb 100644 --- a/.size-limit.cjs +++ b/.size-limit.cjs @@ -1,7 +1,8 @@ +const limits = require("./.size-limits.json"); + const checks = [ { path: "dist/apollo-client.min.cjs", - limit: "37975", }, { path: "dist/main.cjs", @@ -10,7 +11,6 @@ const checks = [ { path: "dist/index.js", import: "{ ApolloClient, InMemoryCache, HttpLink }", - limit: "32019", }, ...[ "ApolloProvider", @@ -53,7 +53,7 @@ const checks = [ value.path == "dist/apollo-client.min.cjs" ? value : [ - { ...value, limit: undefined }, + value, { ...value, name: `${value.name} (production)`, @@ -65,6 +65,10 @@ const checks = [ }, }, ] - ); + ) + .map((value) => { + value.limit = limits[value.name]; + return value; + }); module.exports = checks; diff --git a/.size-limits.json b/.size-limits.json new file mode 100644 index 00000000000..f71b98fe37c --- /dev/null +++ b/.size-limits.json @@ -0,0 +1,4 @@ +{ + "dist/apollo-client.min.cjs": 37975, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32019 +} diff --git a/config/apiExtractor.ts b/config/apiExtractor.ts index c8d6dd86ec0..c1a1e90ec49 100644 --- a/config/apiExtractor.ts +++ b/config/apiExtractor.ts @@ -39,7 +39,7 @@ map((entryPoint: { dirs: string[] }) => { }); const extractorResult: ExtractorResult = Extractor.invoke(extractorConfig, { - localBuild: process.env.CI === undefined, + localBuild: process.env.CI === undefined || process.env.CI === "false", showVerboseMessages: true, }); diff --git a/package.json b/package.json index 0ccb9c27923..f821de84196 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,8 @@ "typedoc": "typedoc src/index.ts --json docs/public/docs.json", "changeset-publish": "npm run build && npm run prepdist:changesets && cd dist && changeset publish", "changeset-check": "changeset status --verbose --since=origin/main", - "changeset-version": "changeset version && npm i" + "changeset-version": "changeset version && npm i", + "update-size-limits": "size-limit --json | jq '. | map(select(.sizeLimit) | { key: .name, value: .size}) | from_entries' | tee .new-size-limits.json; mv .new-size-limits.json .size-limits.json" }, "engines": { "npm": "^7.20.3 || ^8.0.0 || ^9.0.0 || ^10.0.0"