From ffd73c5e5a29a2f13ca57c1ec9ec5016eab682fd Mon Sep 17 00:00:00 2001 From: geoknee Date: Fri, 30 Aug 2024 13:10:14 +0100 Subject: [PATCH 1/6] use dynamic config building in CI This works by having a small workflow run, compute the list of chain ids to run genesis validation checks on, and then modify a subsequent config file which circleci then runs. --- .circleci/config.yml | 270 ++---------------- .circleci/continue_config.yml | 248 ++++++++++++++++ .../validation-inputs/generate-test-config.sh | 32 +++ 3 files changed, 296 insertions(+), 254 deletions(-) create mode 100644 .circleci/continue_config.yml create mode 100644 validation/genesis/validation-inputs/generate-test-config.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 6f8a5e93b..1c1dd63d1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,265 +1,27 @@ version: 2.1 -orbs: - go: circleci/go@1.8.0 - node: circleci/node@5.2.0 - slack: circleci/slack@4.10.1 +# this allows us to use CircleCI's dynamic configuration feature +setup: true -commands: - notify-failures-on-main: - description: "Notify Slack for CI job failures" - parameters: - channel: - type: string - steps: - - slack/notify: - channel: << parameters.channel >> - event: fail - template: basic_fail_1 - branch_pattern: main - install-just: - steps: - - run: - name: "Install just" - command: | - wget -qO - 'https://proget.makedeb.org/debian-feeds/prebuilt-mpr.pub' | gpg --dearmor | sudo tee /usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg 1> /dev/null - echo "deb [arch=all,$(dpkg --print-architecture) signed-by=/usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg] https://proget.makedeb.org prebuilt-mpr $(lsb_release -cs)" | sudo tee /etc/apt/sources.list.d/prebuilt-mpr.list - sudo apt update - sudo apt install just - install-foundry: - steps: - - run: - # need foundry to execute 'cast call' within add-chain script - name: Install foundry - command: | - echo "SHELL=$SHELL" - # Set up directory structure - mkdir -p $HOME/.foundry/bin - echo 'export PATH="$HOME/.foundry/bin:$PATH"' >> $BASH_ENV - source $BASH_ENV - - # Download foundryup and make it executable - curl -sSL "https://raw.githubusercontent.com/foundry-rs/foundry/master/foundryup/foundryup" -o $HOME/.foundry/bin/foundryup - chmod +x $HOME/.foundry/bin/foundryup - - $HOME/.foundry/bin/foundryup - forge --version - install-gvm: - steps: - - run: - name: install nvm - command: | - sudo apt-get update - sudo apt-get -yq install curl git mercurial make binutils bison gcc build-essential bsdmainutils - bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer) - install-pnpm: - description: "Installs pnpm" - steps: - - run: - name: Install pnpm - command: | - sudo npm install -g pnpm - install-nvm: - description: "Installs nvm" - steps: - - run: - name: Install nvm - command: | - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm - source ~/.bashrc - nvm --version +orbs: + continuation: circleci/continuation@0.3.1 jobs: - golang-lint: - executor: - name: go/default # is based on cimg/go - tag: '1.21' - steps: - - checkout - - install-just - - run: just lint-all - - run: - name: check git tree is clean - command: git diff --exit-code - golang-modules-tidy: - executor: - name: go/default # is based on cimg/go - tag: '1.21' - steps: - - checkout - - install-just - - run: just tidy-all - - run: - name: check git tree is clean - command: git diff --exit-code - golang-test: - shell: /bin/bash -eo pipefail - executor: - name: go/default # is based on cimg/go - tag: '1.21' + setup-genesis-allocs-validation: + macos: + xcode: 14.2.0 + resource_class: macos.m1.medium.gen1 steps: - checkout - - install-just - - install-foundry - - run: - name: run superchain module unit tests - command: just test-superchain - run: - name: run validation module unit tests - command: just test-validation - - run: - name: run add-chain module unit tests - command: just test-add-chain - - notify-failures-on-main: - channel: C03N11M0BBN # to slack channel `notify-ci-failures` - golang-validate-allocs: - docker: - - image: cimg/go:1.22.6-node - resource_class: medium - parameters: - chainid: - type: string - steps: - - checkout - - install-pnpm - - install-just - - install-foundry - - install-gvm - - install-nvm - - run: just validate-genesis-allocs <> - # TODO this should also be filtered on modified chains - golang-validate-modified: - shell: /bin/bash -eo pipefail - executor: - name: go/default # is based on cimg/go - tag: '1.21' - steps: - - checkout - - install-just - - install-foundry - - run: - name: run validation checks - command: just validate-modified-chains main # TODO ideally this is the base branch - golang-validate-all: - shell: /bin/bash -eo pipefail - executor: - name: go/default # is based on cimg/go - tag: '1.21' - steps: - - checkout - - install-just - - install-foundry - - run: - name: run validation checks on all chains - command: just validate "*" - - notify-failures-on-main: - channel: C07GQQZDW1G # to slack channel `notify-superchain-validation-failures` - golang-promotion-test: - shell: /bin/bash -eo pipefail - executor: - name: go/default # is based on cimg/go - tag: '1.21' - steps: - - checkout - - install-just - - install-foundry - - run: - name: run validation checks - command: just promotion-test - - slack/notify: - event: always - custom: | - { - "blocks": [ - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": ":control_knobs: The daily report on standard candidate chains is ready!" - } - }, - { - "type": "divider" - }, - { - "type": "context", - "elements": [ - { - "type": "mrkdwn", - "text": "👀 Click the link to see what validation checks would fail if all candidate chains were promoted to standard (and exclusions removed)." - } - ] - } - ] - } - channel: C07GZVCCUS0 # to slack channel `notify-superchain-promotion-failures` - publish-bot: - environment: - NODE_AUTH_TOKEN: $NPM_TOKEN # Use NPM_TOKEN as the auth token - docker: - - image: cimg/node:18 # Use Node.js 18 - steps: - - checkout - - run: - name: Set deployment token - command: npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}" - - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - run: - name: Build and publish package on NPM 📦 - command: pnpm release - check-codegen: - executor: - name: go/default # is based on cimg/go - tag: '1.21' - steps: - - checkout - - install-just - - run: - name: Run codegen - command: just codegen - - run: - name: check git tree is clean - command: git diff --exit-code + name: Generate list of chainids and insert into continue_config.yml file + command: | + bash validation/genesis/validation-inputs/generate-test-config.sh + - continuation/continue: + configuration_path: .circleci/continue_config.yml + parameters: '{}' workflows: - hourly: - jobs: - - golang-validate-all: - context: - - slack - - golang-test: - context: - - slack - triggers: - - schedule: - cron: "0 * * * *" - filters: - branches: - only: - - main - nightly: - jobs: - - golang-promotion-test: - context: - - slack - triggers: - - schedule: - cron: "0 0 * * *" - filters: - branches: - only: - - main - pr-checks: + setup: jobs: - - golang-lint - - golang-modules-tidy - - golang-test - - golang-validate-genesis-allocs: - matrix: - parameters: - chainid: ["7777777", "4801", "1750", "480","34443", "6806", "84532", "8453", "1135", "4202"] - - golang-validate-modified - - check-codegen + - setup-genesis-allocs-validation diff --git a/.circleci/continue_config.yml b/.circleci/continue_config.yml new file mode 100644 index 000000000..40ba8301a --- /dev/null +++ b/.circleci/continue_config.yml @@ -0,0 +1,248 @@ +version: 2.1 +orbs: + go: circleci/go@1.8.0 + node: circleci/node@5.2.0 + slack: circleci/slack@4.10.1 +commands: + notify-failures-on-main: + description: "Notify Slack for CI job failures" + parameters: + channel: + type: string + steps: + - slack/notify: + channel: << parameters.channel >> + event: fail + template: basic_fail_1 + branch_pattern: main + install-just: + steps: + - run: + name: "Install just" + command: | + wget -qO - 'https://proget.makedeb.org/debian-feeds/prebuilt-mpr.pub' | gpg --dearmor | sudo tee /usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg 1> /dev/null + echo "deb [arch=all,$(dpkg --print-architecture) signed-by=/usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg] https://proget.makedeb.org prebuilt-mpr $(lsb_release -cs)" | sudo tee /etc/apt/sources.list.d/prebuilt-mpr.list + sudo apt update + sudo apt install just + install-foundry: + steps: + - run: + # need foundry to execute 'cast call' within add-chain script + name: Install foundry + command: | + echo "SHELL=$SHELL" + # Set up directory structure + mkdir -p $HOME/.foundry/bin + echo 'export PATH="$HOME/.foundry/bin:$PATH"' >> $BASH_ENV + source $BASH_ENV + + # Download foundryup and make it executable + curl -sSL "https://raw.githubusercontent.com/foundry-rs/foundry/master/foundryup/foundryup" -o $HOME/.foundry/bin/foundryup + chmod +x $HOME/.foundry/bin/foundryup + + $HOME/.foundry/bin/foundryup + forge --version + install-gvm: + steps: + - run: + name: install nvm + command: | + sudo apt-get update + sudo apt-get -yq install curl git mercurial make binutils bison gcc build-essential bsdmainutils + bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer) + install-pnpm: + description: "Installs pnpm" + steps: + - run: + name: Install pnpm + command: | + sudo npm install -g pnpm + install-nvm: + description: "Installs nvm" + steps: + - run: + name: Install nvm + command: | + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm + source ~/.bashrc + nvm --version +jobs: + golang-lint: + executor: + name: go/default # is based on cimg/go + tag: '1.21' + steps: + - checkout + - install-just + - run: just lint-all + - run: + name: check git tree is clean + command: git diff --exit-code + golang-modules-tidy: + executor: + name: go/default # is based on cimg/go + tag: '1.21' + steps: + - checkout + - install-just + - run: just tidy-all + - run: + name: check git tree is clean + command: git diff --exit-code + golang-test: + shell: /bin/bash -eo pipefail + executor: + name: go/default # is based on cimg/go + tag: '1.21' + steps: + - checkout + - install-just + - install-foundry + - run: + name: run superchain module unit tests + command: just test-superchain + - run: + name: run validation module unit tests + command: just test-validation + - run: + name: run add-chain module unit tests + command: just test-add-chain + - notify-failures-on-main: + channel: C03N11M0BBN # to slack channel `notify-ci-failures` + # TODO this should also be filtered on modified chains + golang-validate-modified: + shell: /bin/bash -eo pipefail + executor: + name: go/default # is based on cimg/go + tag: '1.21' + steps: + - checkout + - install-just + - install-foundry + - run: + name: run validation checks + command: just validate-modified-chains main # TODO ideally this is the base branch + golang-validate-all: + shell: /bin/bash -eo pipefail + executor: + name: go/default # is based on cimg/go + tag: '1.21' + steps: + - checkout + - install-just + - install-foundry + - run: + name: run validation checks on all chains + command: just validate "*" + - notify-failures-on-main: + channel: C07GQQZDW1G # to slack channel `notify-superchain-validation-failures` + golang-promotion-test: + shell: /bin/bash -eo pipefail + executor: + name: go/default # is based on cimg/go + tag: '1.21' + steps: + - checkout + - install-just + - install-foundry + - run: + name: run validation checks + command: just promotion-test + - slack/notify: + event: always + custom: "{\n \"blocks\": [\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \":control_knobs: The daily report on standard candidate chains is ready!\"\n }\n },\n {\n \"type\": \"divider\"\n },\n {\n \"type\": \"context\",\n \"elements\": [\n {\n \"type\": \"mrkdwn\",\n \"text\": \"\U0001F440 Click the link to see what validation checks would fail if all candidate chains were promoted to standard (and exclusions removed).\"\n }\n ]\n }\n ]\n}\n" + channel: C07GZVCCUS0 # to slack channel `notify-superchain-promotion-failures` + publish-bot: + environment: + NODE_AUTH_TOKEN: $NPM_TOKEN # Use NPM_TOKEN as the auth token + docker: + - image: cimg/node:18 # Use Node.js 18 + steps: + - checkout + - run: + name: Set deployment token + command: npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}" + - env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + - run: + name: "Build and publish package on NPM \U0001F4E6" + command: pnpm release + check-codegen: + executor: + name: go/default # is based on cimg/go + tag: '1.21' + steps: + - checkout + - install-just + - run: + name: Run codegen + command: just codegen + - run: + name: check git tree is clean + command: git diff --exit-code + golang-validate-genesis-allocs: + docker: + - image: cimg/go:1.22.6-node + resource_class: medium + parameters: + chainid: + type: string + steps: + - checkout + - install-pnpm + - install-just + - install-foundry + - install-gvm + - install-nvm + - run: just validate-genesis-allocs <> +workflows: + hourly: + jobs: + - golang-validate-all: + context: + - slack + - golang-test: + context: + - slack + triggers: + - schedule: + cron: "0 * * * *" + filters: + branches: + only: + - main + nightly: + jobs: + - golang-promotion-test: + context: + - slack + triggers: + - schedule: + cron: "0 0 * * *" + filters: + branches: + only: + - main + pr-checks: + jobs: + - golang-validate-genesis-allocs: + matrix: + parameters: + # This value will be replaced by the generate_test_config.sh script + chainid: + - "1135" + - "1750" + - "34443" + - "4202" + - "480" + - "4801" + - "7777777" + - "8453" + - "84532" + - golang-lint + - golang-modules-tidy + - golang-test + - golang-validate-modified + - check-codegen diff --git a/validation/genesis/validation-inputs/generate-test-config.sh b/validation/genesis/validation-inputs/generate-test-config.sh new file mode 100644 index 000000000..0e7699a45 --- /dev/null +++ b/validation/genesis/validation-inputs/generate-test-config.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -o errexit -o pipefail +set -x + +# Get the list of changed files +targetList=$(git diff --name-only --merge-base main -- validation/genesis/*.toml) + +# Check if targetList is empty +if [ -z "$targetList" ]; then + echo "No matching .toml files found in 'validation/genesis/'. Exiting." + exit 0 +fi + +# Process the targetList to extract directory names and then the base names +targetList=$(echo "$targetList" | xargs dirname | xargs basename) + +# Join the array elements with commas and wrap each element in quotes +targets=$(echo "$targetList" | sed 's/.*/"&"/' | tr '\n' ',') + +# Remove the trailing comma +targets=${targets%,} + +# Wrap in square brackets +targets="[$targets]" + +echo "Will run genesis allocs validation on chains with ids $targets" + +# Install yq +brew install yq + +# Use yq to replace the target-version key +yq e ".workflows.pr-checks.jobs[0].golang-validate-genesis-allocs.matrix.parameters.\"chainid\" = $targets" -i .circleci/continue_config.yml From 8f60e6413075a327bc05f7fdf02e65058484dcb6 Mon Sep 17 00:00:00 2001 From: geoknee Date: Fri, 30 Aug 2024 14:37:44 +0100 Subject: [PATCH 2/6] add comment --- .circleci/continue_config.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.circleci/continue_config.yml b/.circleci/continue_config.yml index 40ba8301a..7c58b40eb 100644 --- a/.circleci/continue_config.yml +++ b/.circleci/continue_config.yml @@ -230,17 +230,9 @@ workflows: - golang-validate-genesis-allocs: matrix: parameters: - # This value will be replaced by the generate_test_config.sh script - chainid: - - "1135" - - "1750" - - "34443" - - "4202" - - "480" - - "4801" - - "7777777" - - "8453" - - "84532" + chainid: [] # defaults to an empty list. + # This list will be replaced by the generate_test_config.sh script + - golang-lint - golang-modules-tidy - golang-test From d7cca6e120e8678011c76dd099400c4e4553ffec Mon Sep 17 00:00:00 2001 From: geoknee Date: Fri, 30 Aug 2024 14:47:48 +0100 Subject: [PATCH 3/6] fan in --- .circleci/continue_config.yml | 10 ++++++++-- .../genesis/validation-inputs/generate-test-config.sh | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.circleci/continue_config.yml b/.circleci/continue_config.yml index 7c58b40eb..37825944a 100644 --- a/.circleci/continue_config.yml +++ b/.circleci/continue_config.yml @@ -197,6 +197,11 @@ jobs: - install-gvm - install-nvm - run: just validate-genesis-allocs <> + genesis-allocs-all-ok: + docker: + - image: cimg/go:1.22.6-node + resource_class: medium + run: echo "all ok" workflows: hourly: jobs: @@ -230,9 +235,10 @@ workflows: - golang-validate-genesis-allocs: matrix: parameters: - chainid: [] # defaults to an empty list. - # This list will be replaced by the generate_test_config.sh script + chainid: [] # This list will be replaced by the generate_test_config.sh script + genesis-allocs-all-ok: + requires: [] # This list will be replaced by the generate_test_config.sh script - golang-lint - golang-modules-tidy - golang-test diff --git a/validation/genesis/validation-inputs/generate-test-config.sh b/validation/genesis/validation-inputs/generate-test-config.sh index 0e7699a45..e661f48e7 100644 --- a/validation/genesis/validation-inputs/generate-test-config.sh +++ b/validation/genesis/validation-inputs/generate-test-config.sh @@ -25,8 +25,18 @@ targets="[$targets]" echo "Will run genesis allocs validation on chains with ids $targets" +# Now build another array, each element prepended with "golang-validate-genesis-allocs-" +prependedTargets=$(echo "$targetList" | sed 's/.*/"golang-validate-genesis-allocs-&"/' | tr '\n' ',') + +# Remove the trailing comma +prependedTargets=${prependedTargets%,} + +# Wrap in square brackets +prependedTargets="[$prependedTargets]" + # Install yq brew install yq # Use yq to replace the target-version key yq e ".workflows.pr-checks.jobs[0].golang-validate-genesis-allocs.matrix.parameters.\"chainid\" = $targets" -i .circleci/continue_config.yml +yq e ".workflows.pr-checks.jobs[0].genesis-allocs-all-ok.requires = $prependedTargets" -i .circleci/continue_config.yml From e6e348727832179d6932e16be269d775dac14ada Mon Sep 17 00:00:00 2001 From: geoknee Date: Fri, 30 Aug 2024 14:50:23 +0100 Subject: [PATCH 4/6] fix --- .circleci/continue_config.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.circleci/continue_config.yml b/.circleci/continue_config.yml index 37825944a..9ccebc6c9 100644 --- a/.circleci/continue_config.yml +++ b/.circleci/continue_config.yml @@ -201,7 +201,9 @@ jobs: docker: - image: cimg/go:1.22.6-node resource_class: medium - run: echo "all ok" + steps: + - checkout + - run: echo "Job 1 is running" workflows: hourly: jobs: @@ -236,8 +238,7 @@ workflows: matrix: parameters: chainid: [] # This list will be replaced by the generate_test_config.sh script - - genesis-allocs-all-ok: + - genesis-allocs-all-ok: requires: [] # This list will be replaced by the generate_test_config.sh script - golang-lint - golang-modules-tidy From d7b4b1903dd2bb1723f9e53587ff0e03d29bc6c4 Mon Sep 17 00:00:00 2001 From: geoknee Date: Fri, 30 Aug 2024 14:56:05 +0100 Subject: [PATCH 5/6] fix script --- validation/genesis/validation-inputs/generate-test-config.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validation/genesis/validation-inputs/generate-test-config.sh b/validation/genesis/validation-inputs/generate-test-config.sh index e661f48e7..0ae4dbfc3 100644 --- a/validation/genesis/validation-inputs/generate-test-config.sh +++ b/validation/genesis/validation-inputs/generate-test-config.sh @@ -38,5 +38,5 @@ prependedTargets="[$prependedTargets]" brew install yq # Use yq to replace the target-version key -yq e ".workflows.pr-checks.jobs[0].golang-validate-genesis-allocs.matrix.parameters.\"chainid\" = $targets" -i .circleci/continue_config.yml -yq e ".workflows.pr-checks.jobs[0].genesis-allocs-all-ok.requires = $prependedTargets" -i .circleci/continue_config.yml +yq e ".workflows.pr-checks.jobs[0].golang-validate-genesis-allocs.matrix.parameters.chainid = $targets" -i .circleci/continue_config.yml +yq e ".workflows.pr-checks.jobs[1].genesis-allocs-all-ok.requires = $prependedTargets" -i .circleci/continue_config.yml From 38dcdb25bb7e8de5aa006291bcfb229c5ac8ef1b Mon Sep 17 00:00:00 2001 From: George Knee Date: Fri, 30 Aug 2024 14:58:23 +0100 Subject: [PATCH 6/6] Update .circleci/continue_config.yml Co-authored-by: Vinod Damle --- .circleci/continue_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/continue_config.yml b/.circleci/continue_config.yml index 9ccebc6c9..d1ace848e 100644 --- a/.circleci/continue_config.yml +++ b/.circleci/continue_config.yml @@ -153,7 +153,7 @@ jobs: - slack/notify: event: always custom: "{\n \"blocks\": [\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \":control_knobs: The daily report on standard candidate chains is ready!\"\n }\n },\n {\n \"type\": \"divider\"\n },\n {\n \"type\": \"context\",\n \"elements\": [\n {\n \"type\": \"mrkdwn\",\n \"text\": \"\U0001F440 Click the link to see what validation checks would fail if all candidate chains were promoted to standard (and exclusions removed).\"\n }\n ]\n }\n ]\n}\n" - channel: C07GZVCCUS0 # to slack channel `notify-superchain-promotion-failures` + channel: C07GZVCCUS0 # to slack channel `notify-superchain-promotion-reports` publish-bot: environment: NODE_AUTH_TOKEN: $NPM_TOKEN # Use NPM_TOKEN as the auth token