diff --git a/.github/workflows/call.check-query-schema-against-subgraph.yml b/.github/workflows/call.check-query-schema-against-subgraph.yml index 11961641a5..13275c31ec 100644 --- a/.github/workflows/call.check-query-schema-against-subgraph.yml +++ b/.github/workflows/call.check-query-schema-against-subgraph.yml @@ -18,7 +18,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/call.deploy-subgraph.yml b/.github/workflows/call.deploy-subgraph.yml index 5aab6388c3..854ecc2a0a 100644 --- a/.github/workflows/call.deploy-subgraph.yml +++ b/.github/workflows/call.deploy-subgraph.yml @@ -64,7 +64,7 @@ jobs: defaults: run: - shell: nix develop -c bash {0} + shell: nix develop .#ci-default -c bash {0} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/call.test-local-subgraph.yml b/.github/workflows/call.test-local-subgraph.yml index 0fb84d40f5..51e58e4aad 100644 --- a/.github/workflows/call.test-local-subgraph.yml +++ b/.github/workflows/call.test-local-subgraph.yml @@ -13,7 +13,8 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + # FIXME: subgraph test fails with node20 + shell: nix develop .#ci-node18 -c bash -xe {0} steps: - uses: actions/checkout@v4 @@ -59,7 +60,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-node18 -c bash -xe {0} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/call.test-sdk-core.yml b/.github/workflows/call.test-sdk-core.yml index 0c77edadd2..46c2131371 100644 --- a/.github/workflows/call.test-sdk-core.yml +++ b/.github/workflows/call.test-sdk-core.yml @@ -26,7 +26,8 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + # FIXME: subgraph test fails with node20 + shell: nix develop .#ci-node18 -c bash -xe {0} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/call.test-solidity-semantic-money.yml b/.github/workflows/call.test-solidity-semantic-money.yml index ac629f98f7..5a46c4aff4 100644 --- a/.github/workflows/call.test-solidity-semantic-money.yml +++ b/.github/workflows/call.test-solidity-semantic-money.yml @@ -11,7 +11,7 @@ jobs: defaults: run: - shell: nix develop . -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/call.test-subgraph-on-previous-sdk-core-versions.yml b/.github/workflows/call.test-subgraph-on-previous-sdk-core-versions.yml index bd74a576ea..de04046cd1 100644 --- a/.github/workflows/call.test-subgraph-on-previous-sdk-core-versions.yml +++ b/.github/workflows/call.test-subgraph-on-previous-sdk-core-versions.yml @@ -30,7 +30,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/call.upload-coverage-reports.yml b/.github/workflows/call.upload-coverage-reports.yml index a9ab6c3334..fca4edbaee 100644 --- a/.github/workflows/call.upload-coverage-reports.yml +++ b/.github/workflows/call.upload-coverage-reports.yml @@ -21,7 +21,7 @@ jobs: name: ethereum-contracts-coverage path: packages/ethereum-contracts/coverage - name: Upload ethereum-contracts-coverage to codecov - uses: codecov/codecov-action@v4.2.0 + uses: codecov/codecov-action@v4.3.0 with: token: ${{ secrets.codecov_token }} files: packages/ethereum-contracts/coverage/lcov.info diff --git a/.github/workflows/cd.feature.create-pr-artifact.yml b/.github/workflows/cd.feature.create-pr-artifact.yml index a91af4a0be..a536169efc 100644 --- a/.github/workflows/cd.feature.create-pr-artifact.yml +++ b/.github/workflows/cd.feature.create-pr-artifact.yml @@ -12,7 +12,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} if: ${{ !github.event.pull_request.draft }} @@ -41,8 +41,8 @@ jobs: echo " .locked" ${{ github.event.pull_request.locked }} echo " .draft" ${{ github.event.pull_request.draft }} - - name: Check changeset - run: tasks/check-changeset.sh ${{ github.sha }} dev + - name: Create build set + run: tasks/create-build-set.sh ${{ github.sha }} dev origin - name: Install dependencies if: env.PUBLISH_PR_ARTIFACT == 1 diff --git a/.github/workflows/ci.canary.yml b/.github/workflows/ci.canary.yml index 89f27780e3..01cb9d826f 100644 --- a/.github/workflows/ci.canary.yml +++ b/.github/workflows/ci.canary.yml @@ -23,8 +23,8 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Check changeset - run: tasks/check-changeset.sh ${{ github.sha }} dev + - name: Create build set + run: tasks/create-build-set.sh ${{ github.sha }} dev origin essential-build-and-test: name: Build and test essential packages of dev branch @@ -179,7 +179,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} steps: - uses: actions/checkout@v4 @@ -223,7 +223,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} steps: - uses: actions/checkout@v4 @@ -288,7 +288,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/ci.feature.yml b/.github/workflows/ci.feature.yml index 0cb9d3b6fc..d08dca1ef8 100644 --- a/.github/workflows/ci.feature.yml +++ b/.github/workflows/ci.feature.yml @@ -12,6 +12,10 @@ on: merge_group: pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: check: name: Checking what packages need to be built @@ -59,8 +63,8 @@ jobs: - name: Run pre-commit check run: npm run pre-commit - - name: Check changeset - run: tasks/check-changeset.sh ${{ github.sha }} dev + - name: Create build set + run: tasks/create-build-set.sh ${{ github.sha }} dev origin test-ethereum-contracts: name: Test ethereum-contracts (Feature Branch) @@ -71,7 +75,7 @@ jobs: run-coverage-tests: false coverage-ethereum-contracts: - name: Coverage test ethereum-contracts (Feature Branch) + name: Coverage Test ethereum-contracts (Feature Branch) uses: ./.github/workflows/call.test-ethereum-contracts.yml needs: [check] if: needs.check.outputs.build_ethereum_contracts @@ -106,7 +110,7 @@ jobs: # sdk-core integration test + local subgraph w/ local sdk-core test-sdk-core: - name: Test SDK-Core (Feature Branch) + name: Test sdk-core (Feature Branch) uses: ./.github/workflows/call.test-sdk-core.yml needs: [check] if: needs.check.outputs.build_sdk_core @@ -116,7 +120,7 @@ jobs: run-coverage-tests: false coverage-sdk-core: - name: Test SDK-Core (Feature Branch) + name: Coverage Test sdk-core (Feature Branch) uses: ./.github/workflows/call.test-sdk-core.yml needs: [check] if: needs.check.outputs.build_sdk_core diff --git a/.github/workflows/handler.changelog-reminder.yml b/.github/workflows/handler.changelog-reminder.yml index a5c64cf89e..fa751eae46 100644 --- a/.github/workflows/handler.changelog-reminder.yml +++ b/.github/workflows/handler.changelog-reminder.yml @@ -19,9 +19,9 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Check changeset - run: tasks/check-changeset.sh ${{ github.sha }} dev - + - name: Create build set + run: tasks/create-build-set.sh ${{ github.sha }} dev origin + create-reminder: name: Create Changelog reminder in PR discussion @@ -45,4 +45,4 @@ jobs: Reminder to update the CHANGELOG.md for any of the modified packages in this PR. - [ ] CHANGELOG.md modified - [ ] Double check before merge - reactions: white_check_mark \ No newline at end of file + reactions: white_check_mark diff --git a/.github/workflows/handler.deploy-to-mainnet.yml b/.github/workflows/handler.deploy-to-mainnet.yml index 617d3b359f..484ac44dbc 100644 --- a/.github/workflows/handler.deploy-to-mainnet.yml +++ b/.github/workflows/handler.deploy-to-mainnet.yml @@ -28,7 +28,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/handler.deploy-to-testnets.yml b/.github/workflows/handler.deploy-to-testnets.yml index a355181252..b6ec062b54 100644 --- a/.github/workflows/handler.deploy-to-testnets.yml +++ b/.github/workflows/handler.deploy-to-testnets.yml @@ -28,7 +28,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} strategy: fail-fast: false diff --git a/.github/workflows/handler.list-super-token.yml b/.github/workflows/handler.list-super-token.yml index faa9d35e93..67e02909a6 100644 --- a/.github/workflows/handler.list-super-token.yml +++ b/.github/workflows/handler.list-super-token.yml @@ -35,7 +35,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/handler.publish-release-packages.yml b/.github/workflows/handler.publish-release-packages.yml index b6d82f8a1d..0fcb873870 100644 --- a/.github/workflows/handler.publish-release-packages.yml +++ b/.github/workflows/handler.publish-release-packages.yml @@ -14,7 +14,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/handler.run-ethereum-contracts-script.yml b/.github/workflows/handler.run-ethereum-contracts-script.yml index 774b3a81cb..0e994beb82 100644 --- a/.github/workflows/handler.run-ethereum-contracts-script.yml +++ b/.github/workflows/handler.run-ethereum-contracts-script.yml @@ -30,8 +30,8 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} - + shell: nix develop .#ci-default -c bash -xe {0} + env: RELEASE_VERSION: ${{ github.event.inputs.release_version }} RESOLVER_ADMIN_TYPE: ${{ github.event.inputs.admin_type }} diff --git a/.github/workflows/handler.verify-contracts.yml b/.github/workflows/handler.verify-contracts.yml index 321cea196b..34b4ef08c1 100644 --- a/.github/workflows/handler.verify-contracts.yml +++ b/.github/workflows/handler.verify-contracts.yml @@ -28,7 +28,7 @@ jobs: defaults: run: - shell: nix develop -c bash -xe {0} + shell: nix develop .#ci-default -c bash -xe {0} steps: - uses: actions/checkout@v4 diff --git a/flake.lock b/flake.lock index ebd320ecd2..fb9e7b1b8b 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -28,11 +28,11 @@ ] }, "locked": { - "lastModified": 1719997877, - "narHash": "sha256-/Edw+w0PiGgxwnCeJycM0VgH4HtlCi91v1d8xbi+REE=", + "lastModified": 1722676286, + "narHash": "sha256-wEDJdvwRZF2ErQ33nQ0Lqn/48XrPbaadv56/bM2MSZU=", "owner": "shazow", "repo": "foundry.nix", - "rev": "02febba4f1cf0606d790acdb24adcf7a64afb4e1", + "rev": "d84c83b1c1722c8742b3d2d84c9386814d75384e", "type": "github" }, "original": { @@ -44,11 +44,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1707205916, - "narHash": "sha256-fmRJilYGlB7VCt3XsdYxrA0u8e/K84O5xYucerUY0iM=", + "lastModified": 1723019560, + "narHash": "sha256-O/kxmybNecC3Efr6ITOdtCzFv90/B2Iiedavj5aRWt0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "8cc79aa39bbc6eaedaf286ae655b224c71e02907", + "rev": "f5129fb42b9c262318130a97b47516946da3e7d7", "type": "github" }, "original": { @@ -77,11 +77,11 @@ "solc-macos-amd64-list-json": "solc-macos-amd64-list-json" }, "locked": { - "lastModified": 1717442267, - "narHash": "sha256-6TnQvA6Q/xC3r1M+wGC5gnDc/5XfOPjC8X6LlGDWDNc=", + "lastModified": 1723108822, + "narHash": "sha256-0SToQBucC4haDvgiG+JyL566ylCLl8s3SKaBT9m/nVo=", "owner": "hellwolf", "repo": "solc.nix", - "rev": "2ac2862f224aa0d67cbc6b3246392489f8a50596", + "rev": "d1f30906719dfcbd69a90996aa98d8e5322e5705", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index ce3fe67b2c..8ab6136c02 100644 --- a/flake.nix +++ b/flake.nix @@ -73,7 +73,7 @@ ]; # minimem development shell - minimumDevInputs = commonDevInputs ++ ethDevInputs ++ node18DevInputs; + minimumDevInputs = commonDevInputs ++ ethDevInputs ++ node20DevInputs; # additional tooling for whitehat hackers whitehatInputs = with pkgs; [ @@ -113,9 +113,7 @@ FOUNDRY_OFFLINE = "true"; FOUNDRY_SOLC_VERSION = pkgs.lib.getExe pkgs.${solcVer}; } // o); - - # ci-spec-with-ghc - ci-spec-with-ghc = ghcVer : mkShell { + mkShellForSpecCI = ghcVer : mkShell { buildInputs = with pkgs; [ cabal-install haskell.compiler.${ghcVer} @@ -142,14 +140,17 @@ }; # CI shells + devShells.ci-default = mkShell { + buildInputs = ciInputs ++ minimumDevInputs; + }; devShells.ci-node18 = mkShell { buildInputs = ciInputs ++ commonDevInputs ++ ethDevInputs ++ node18DevInputs; }; devShells.ci-node20 = mkShell { buildInputs = ciInputs ++ commonDevInputs ++ ethDevInputs ++ node20DevInputs; }; - devShells.ci-spec-ghc92 = ci-spec-with-ghc ghcVer92; - devShells.ci-spec-ghc94 = ci-spec-with-ghc ghcVer94; + devShells.ci-spec-ghc92 = mkShellForSpecCI ghcVer92; + devShells.ci-spec-ghc94 = mkShellForSpecCI ghcVer94; devShells.ci-hot-fuzz = mkShell { buildInputs = with pkgs; ciInputs ++ commonDevInputs ++ ethDevInputs ++ [ slither-analyzer diff --git a/packages/ethereum-contracts/tasks/coverage-cleanup.sh b/packages/ethereum-contracts/tasks/coverage-cleanup.sh index 0ff548eac5..c7a5d56394 100755 --- a/packages/ethereum-contracts/tasks/coverage-cleanup.sh +++ b/packages/ethereum-contracts/tasks/coverage-cleanup.sh @@ -4,13 +4,15 @@ set -ex cd "$(dirname "$0")"/.. +LCOV="lcov --ignore-errors inconsistent" + # extract coverage for Superfluid contracts from forge coverage -lcov -e ../../lcov.info \ +$LCOV -e ../../lcov.info \ "packages/ethereum-contracts/contracts/*" \ -o lcov.info # remove contracts whose coverage we don't care about (see .solcover.js) -lcov -r lcov.info \ +$LCOV -r lcov.info \ "packages/ethereum-contracts/contracts/mocks/*" \ "packages/ethereum-contracts/contracts/apps/*Base*" \ "packages/ethereum-contracts/contracts/utils/*Test*" \ @@ -19,6 +21,6 @@ lcov -r lcov.info \ -o lcov.info # merge hardhat and forge coverage files -lcov -a lcov.info \ +$LCOV -a lcov.info \ -a coverage/lcov.info \ -o coverage/lcov.info diff --git a/tasks/check-changeset.sh b/tasks/check-changeset.sh deleted file mode 100755 index ab74cfc714..0000000000 --- a/tasks/check-changeset.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash - -set -e - -SOURCE_REF=$1 -BASE_REF=$2 - -echo "SOURCE_REF: $SOURCE_REF" -echo "BASE_REF: $BASE_REF" - -# fetch the latest commit of the base ref -git fetch origin --depth=1 refs/heads/"${BASE_REF}":refs/remotes/origin/"${BASE_REF}" - -# compare the source branch with the dev branch -git diff --name-only "${SOURCE_REF}" refs/remotes/origin/"${BASE_REF}" > changed-files.list -echo Changed files: -echo --- -cat changed-files.list -echo --- - -function setBuildAll() { - BUILD_ETHEREUM_CONTRACTS=1 - BUILD_HOT_FUZZ=1 - BUILD_SDK_CORE=1 - BUILD_SDK_REDUX=1 - #BUILD_SPEC_HASKELL=1 - BUILD_SUBGRAPH=1 - BUILD_AUTOMATION_CONTRACTS=1 - BUILD_SOLIDITY_SEMANTIC_MONEY=1 - echo Everything will be tested. -} - -# set BUILD_* variables to GITHUB_ENV -# (dependency graph implied below) -if [ -n "$GITHUB_ENV" ];then - # if ci workflows changed - if grep -E "^.github/workflows/ci\..*\.yml$" changed-files.list;then - echo "CI workflows changed." - setBuildAll - fi - # if call (reusable) workflows changed - if grep -E "^.github/workflows/call\..*\.yml$" changed-files.list;then - echo "Call workflows changed." - setBuildAll - fi - # if root package.json changed, rebuild everything - if grep -E "^(flake\.nix|flake\.lock|package\.json|yarn\.lock)$" changed-files.list;then - echo "Root package.json changed." - setBuildAll - fi - # if specified solidity-semantic-money folders and files changed - if grep -E "^packages/solidity-semantic-money/(src/|test/|foundry\.toml|Makefile|package\.json)" changed-files.list;then - BUILD_SOLIDITY_SEMANTIC_MONEY=1 - BUILD_ETHEREUM_CONTRACTS=1 - echo Solidity semantic money will be tested. - fi - # if specified ethereum-contracts folders and files changed - if grep -E "^packages/ethereum-contracts/(contracts/|scripts/|test/|truffle-config\.js|package\.json)" changed-files.list;then - BUILD_ETHEREUM_CONTRACTS=1 - BUILD_SUBGRAPH=1 - BUILD_HOT_FUZZ=1 - BUILD_AUTOMATION_CONTRACTS=1 - echo Ethereum contracts, HotFuzz and Subgraph will be tested. - fi - # if specified hot-fuzz folders and files changed - if grep -E "^packages/hot-fuzz/(contracts/|scripts/|.+\.js|.+\.yaml|hot-fuzz|package\.json)" changed-files.list;then - BUILD_HOT_FUZZ=1 - echo HotFuzz will be tested. - fi - # if specified sdk-core folders and files changed - if grep -E "^packages/sdk-core/(src/|test/|package\.json|tsconfig\.*)" changed-files.list;then - BUILD_SDK_CORE=1 - BUILD_SDK_REDUX=1 - BUILD_SUBGRAPH=1 - echo SDK-CORE, SDK-REDUX and SUBGRAPH will be tested. - fi - # if specified sdk-redux folders and files changed - if grep -E "^packages/sdk-redux/(src/|test/|package\.json)" changed-files.list;then - BUILD_SDK_REDUX=1 - echo SDK-REDUX will be tested. - fi - # if specified subgraph folders and files changed - if grep -E "^packages/subgraph/(subgraph\.template\.yaml|schema\.graphql|config|scripts|src|tasks|test|hardhat\.config\.ts|package\.json|docker-compose\.yml)" changed-files.list;then - BUILD_SUBGRAPH=1 - echo Subgraph will be tested. - fi - # if specified haskell folders and files changed - if grep -E "^packages/spec-haskell/(packages/|cabal\.project)" changed-files.list;then - # BUILD_SPEC_HASKELL=1 - echo SPEC-HASKELL will be tested, disabled for now. - fi - # if specified automation-contracts/scheduler folders and files changed - if grep -E "^packages/automation-contracts/scheduler/(contracts/|scripts/|test/|truffle-config\.js|package\.json)" changed-files.list;then - BUILD_AUTOMATION_CONTRACTS=1 - echo Automation Contracts will be tested. - fi - # if specified automation-contracts/autowrap folders and files changed - if grep -E "^packages/automation-contracts/autowrap/(contracts/|scripts/|test/|truffle-config\.js|package\.json)" changed-files.list;then - BUILD_AUTOMATION_CONTRACTS=1 - echo Automation Contracts will be tested. - fi - - if [ "$BUILD_ETHEREUM_CONTRACTS" == 1 ] || [ "$BUILD_SDK_CORE" == 1 ] || [ "$BUILD_SDK_REDUX" == 1 ];then - echo "PR packages will be published." - PUBLISH_PR_ARTIFACT=1 - fi - - { - echo "BUILD_ETHEREUM_CONTRACTS=${BUILD_ETHEREUM_CONTRACTS}" - echo "BUILD_HOT_FUZZ=${BUILD_HOT_FUZZ}" - echo "BUILD_SDK_CORE=${BUILD_SDK_CORE}" - echo "BUILD_SDK_REDUX=${BUILD_SDK_REDUX}" - echo "BUILD_SUBGRAPH=${BUILD_SUBGRAPH}" - echo "BUILD_SPEC_HASKELL=${BUILD_SPEC_HASKELL}" - echo "BUILD_AUTOMATION_CONTRACTS=${BUILD_AUTOMATION_CONTRACTS}" - echo "BUILD_SOLIDITY_SEMANTIC_MONEY=${BUILD_SOLIDITY_SEMANTIC_MONEY}" - echo "PUBLISH_PR_ARTIFACT=${PUBLISH_PR_ARTIFACT}" - } >> "$GITHUB_ENV" -fi diff --git a/tasks/create-build-set.sh b/tasks/create-build-set.sh new file mode 100755 index 0000000000..4336c1ec94 --- /dev/null +++ b/tasks/create-build-set.sh @@ -0,0 +1,134 @@ +#!/usr/bin/env bash +# Synopsis: Create packages build set based on the files change set. +# Usage: create-build-set.sh SOURCE_REF BASE_REF [BASE_ORIGIN] +# Notes: +# - The files change set is derived from the `git diff` between SOURCE_REF and BASE_REF. +# - Optionally, it fetches BASE_REF first BASE_ORIGIN first before `git diff`. +# - The packages build set is output to GITHUB_ENV or /dev/stdout in a form of "BUILD_*" environment variables. + +console.debug() { + echo "debug:" "$@" > /dev/stderr +} + +set -e + +SOURCE_REF=$1 +BASE_REF=$2 +BASE_ORIGIN=$3 + +console.debug "SOURCE_REF: $SOURCE_REF" +console.debug "BASE_REF: $BASE_REF" + +# fetch the latest commit of the BASE_REF from BASE_ORIGIN +if [ -n "${BASE_ORIGIN}" ]; then + git fetch "${BASE_ORIGIN}" --depth=1 refs/heads/"${BASE_REF}":refs/remotes/"${BASE_ORIGIN}"/"${BASE_REF}" +fi + +# compare the source branch with the dev branch +CHANGED_FILES=changed-files.ignore.list +git diff --name-only "${SOURCE_REF}" refs/remotes/origin/"${BASE_REF}" > "$CHANGED_FILES" +console.debug "=== BEGIN CHANGED FILES" +cat "$CHANGED_FILES" > /dev/stderr +console.debug "=== END CHANGED FILES" + +console.debug "=== BEGIN CREATE BUILD SET" + +function setBuildAll() { + BUILD_ETHEREUM_CONTRACTS=1 + BUILD_HOT_FUZZ=1 + BUILD_SDK_CORE=1 + BUILD_SDK_REDUX=1 + BUILD_SPEC_HASKELL=1 + BUILD_SUBGRAPH=1 + BUILD_AUTOMATION_CONTRACTS=1 + BUILD_SOLIDITY_SEMANTIC_MONEY=1 + console.debug "Everything will be tested." +} + +# if ci workflows changed +if grep -E "^.github/workflows/ci\..*\.yml$" "$CHANGED_FILES" > /dev/null; then + console.debug "CI workflows changed." + setBuildAll +fi + +# if call (reusable) workflows changed +if grep -E "^.github/workflows/call\..*\.yml$" "$CHANGED_FILES" > /dev/null; then + console.debug "Call workflows changed." + setBuildAll +fi +# if root package.json changed, rebuild everything +if grep -E "^(flake\.nix|flake\.lock|package\.json|yarn\.lock)$" "$CHANGED_FILES" > /dev/null; then + console.debug "Root package.json changed." + setBuildAll +fi +# if specified solidity-semantic-money folders and files changed +if grep -E "^packages/solidity-semantic-money/(src/|test/|foundry\.toml|Makefile|package\.json)" "$CHANGED_FILES" > /dev/null; then + BUILD_SOLIDITY_SEMANTIC_MONEY=1 + BUILD_ETHEREUM_CONTRACTS=1 + console.debug Solidity semantic money will be tested. +fi +# if specified ethereum-contracts folders and files changed +if grep -E "^packages/ethereum-contracts/(contracts/|scripts/|test/|truffle-config\.js|package\.json)" "$CHANGED_FILES" > /dev/null; then + BUILD_ETHEREUM_CONTRACTS=1 + BUILD_SUBGRAPH=1 + BUILD_HOT_FUZZ=1 + BUILD_AUTOMATION_CONTRACTS=1 + console.debug Ethereum contracts, HotFuzz and Subgraph will be tested. +fi +# if specified hot-fuzz folders and files changed +if grep -E "^packages/hot-fuzz/(contracts/|scripts/|.+\.js|.+\.yaml|hot-fuzz|package\.json)" "$CHANGED_FILES" > /dev/null; then + BUILD_HOT_FUZZ=1 + console.debug HotFuzz will be tested. +fi +# if specified sdk-core folders and files changed +if grep -E "^packages/sdk-core/(src/|test/|package\.json|tsconfig\.*)" "$CHANGED_FILES" > /dev/null; then + BUILD_SDK_CORE=1 + BUILD_SDK_REDUX=1 + BUILD_SUBGRAPH=1 + console.debug SDK-CORE, SDK-REDUX and SUBGRAPH will be tested. +fi +# if specified sdk-redux folders and files changed +if grep -E "^packages/sdk-redux/(src/|test/|package\.json)" "$CHANGED_FILES" > /dev/null; then + BUILD_SDK_REDUX=1 + console.debug SDK-REDUX will be tested. +fi +# if specified subgraph folders and files changed +if grep -E "^packages/subgraph/(subgraph\.template\.yaml|schema\.graphql|config|scripts|src|tasks|test|hardhat\.config\.ts|package\.json|docker-compose\.yml)" "$CHANGED_FILES" > /dev/null; then + BUILD_SUBGRAPH=1 + console.debug Subgraph will be tested. +fi +# if specified haskell folders and files changed +if grep -E "^packages/spec-haskell/(packages/|cabal\.project)" "$CHANGED_FILES" > /dev/null; then + BUILD_SPEC_HASKELL=1 + console.debug SPEC-HASKELL will be tested. +fi +# if specified automation-contracts/scheduler folders and files changed +if grep -E "^packages/automation-contracts/scheduler/(contracts/|scripts/|test/|truffle-config\.js|package\.json)" "$CHANGED_FILES" > /dev/null; then + BUILD_AUTOMATION_CONTRACTS=1 + console.debug Automation Contracts will be tested. +fi +# if specified automation-contracts/autowrap folders and files changed +if grep -E "^packages/automation-contracts/autowrap/(contracts/|scripts/|test/|truffle-config\.js|package\.json)" "$CHANGED_FILES" > /dev/null; then + BUILD_AUTOMATION_CONTRACTS=1 + console.debug Automation Contracts will be tested. +fi + +if [ "$BUILD_ETHEREUM_CONTRACTS" == 1 ] || [ "$BUILD_SDK_CORE" == 1 ] || [ "$BUILD_SDK_REDUX" == 1 ]; then + console.debug "PR packages will be published." + PUBLISH_PR_ARTIFACT=1 +fi + +console.debug "=== END CREATE BUILD SET" + +# print BUILD_* variables to $GITHUB_ENV, for local debugging GITHUB_ENV is default to /dev/stdout +{ + echo "BUILD_ETHEREUM_CONTRACTS=${BUILD_ETHEREUM_CONTRACTS}" + echo "BUILD_HOT_FUZZ=${BUILD_HOT_FUZZ}" + echo "BUILD_SDK_CORE=${BUILD_SDK_CORE}" + echo "BUILD_SDK_REDUX=${BUILD_SDK_REDUX}" + echo "BUILD_SUBGRAPH=${BUILD_SUBGRAPH}" + echo "BUILD_SPEC_HASKELL=${BUILD_SPEC_HASKELL}" + echo "BUILD_AUTOMATION_CONTRACTS=${BUILD_AUTOMATION_CONTRACTS}" + echo "BUILD_SOLIDITY_SEMANTIC_MONEY=${BUILD_SOLIDITY_SEMANTIC_MONEY}" + echo "PUBLISH_PR_ARTIFACT=${PUBLISH_PR_ARTIFACT}" +} >> "${GITHUB_ENV:-/dev/stdout}"