diff --git a/.github/actions/cache_foundry_build/action.yml b/.github/actions/cache_foundry_build/action.yml new file mode 100644 index 000000000..e4aaf45ba --- /dev/null +++ b/.github/actions/cache_foundry_build/action.yml @@ -0,0 +1,29 @@ +name: 'Cache foundry build' +description: 'Caches foundry build by path' + +inputs: + package_folder: # id of input + description: 'contracts package folder' + required: true + foundry_profile: + description: 'foundry profile for caching' + +runs: + using: "composite" + + steps: + - name: Cache contracts build + uses: actions/cache@v3 + with: + # npm cache files are stored in out and cache + path: | + ${{ inputs.package_folder }}/cache + ${{ inputs.package_folder }}/out + # cache key is based on foundry config, contracts source tests, and scripts + key: ${{ inputs.package_folder }}${{ inputs.foundry_profile}}-${{ hashFiles(format('{0}/foundry.toml', inputs.package_folder)) }}-${{ hashFiles(format('{0}/src/**/*.sol', inputs.package_folder)) }}-${{ hashFiles(format('{0}/test/**/*.sol', inputs.package_folder)) }}-${{ hashFiles(format('{0}/script/**/*.sol', inputs.package_folder)) }} + # the following backups cache keys are searched, in case an exact match is not found + # see https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key + restore-keys: | + ${{ inputs.package_folder }}${{ inputs.foundry_profile}}-${{ hashFiles(format('{0}/foundry.toml', inputs.package_folder)) }}-${{ hashFiles(format('{0}/src/**/*.sol', inputs.package_folder)) }}-${{ hashFiles(format('{0}/test/**/*.sol', inputs.package_folder)) }}- + ${{ inputs.package_folder }}${{ inputs.foundry_profile}}-${{ hashFiles(format('{0}/foundry.toml', inputs.package_folder)) }}-${{ hashFiles(format('{0}/src/**/*.sol', inputs.package_folder)) }}- + ${{ inputs.package_folder }}${{ inputs.foundry_profile}}-${{ hashFiles(format('{0}/foundry.toml', inputs.package_folder)) }}- diff --git a/.github/workflows/1155.yml b/.github/workflows/1155.yml new file mode 100644 index 000000000..0eba44f0a --- /dev/null +++ b/.github/workflows/1155.yml @@ -0,0 +1,21 @@ +name: "1155" +on: + workflow_call: + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + package_folder: packages/1155-contracts + + test: + needs: build + uses: ./.github/workflows/test.yml + with: + package_folder: packages/1155-contracts + + coverage: + uses: ./.github/workflows/coverage.yml + with: + package: "1155-contracts" + files_to_ignore: '"*DeploymentConfig*" "*Redeem*" "*deployment*" "*packages*"' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..71a558d58 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,28 @@ +on: + workflow_call: + inputs: + package_folder: + required: true + type: string + +jobs: + check: + strategy: + fail-fast: true + + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install node deps and founry + uses: ./.github/actions/setup_deps + + - name: Cache build + uses: ./.github/actions/cache_foundry_build + with: + package_folder: ${{ inputs.package_folder }} + + - name: Build contracts + run: | + cd ${{ inputs.package_folder}} && forge build diff --git a/.github/workflows/contracts.yml b/.github/workflows/contracts.yml new file mode 100644 index 000000000..ae500c2cd --- /dev/null +++ b/.github/workflows/contracts.yml @@ -0,0 +1,17 @@ +name: "Contracts" + +on: "push" + +jobs: + contracts-1155: + name: 1155 + uses: ./.github/workflows/1155.yml + + contracts-protocol-rewards: + name: Protocol Rewards + uses: ./.github/workflows/protocol-rewards.yml + + contracts-protocol-deployments: + name: Protocol Deployments + uses: ./.github/workflows/protocol-deployments.yml + secrets: inherit diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 966b7ba79..58e251a8c 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: true - name: Check solidity test coverage + name: Coverage runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -29,6 +29,12 @@ jobs: - name: Install node deps and founry uses: ./.github/actions/setup_deps + - name: Cache build + uses: ./.github/actions/cache_foundry_build + with: + package_folder: packages/${{ inputs.package }} + foundry_profile: coverage + - name: Run Forge coverage run: cd $package_folder && forge coverage --report lcov diff --git a/.github/workflows/foundry.yml b/.github/workflows/foundry.yml deleted file mode 100644 index ad7a2eb47..000000000 --- a/.github/workflows/foundry.yml +++ /dev/null @@ -1,150 +0,0 @@ -name: "Foundry" - -on: "push" - -env: - # Setting an environment variable with the value of a configuration variable - $build_artifact: foundry_artifact - -jobs: - build: - name: Build contracts and cache output - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install node deps and founry - uses: ./.github/actions/setup_deps - - - name: Build contracts - run: | - npx turbo run build:contracts - - - name: Archive built artifacts - uses: actions/upload-artifact@v3 - with: - name: $build_artifact - path: | - **/*/cache - **/*/out - retention-days: 1 - - contract_size_check: - needs: build - strategy: - fail-fast: true - - name: Check contract sizes - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install node deps and founry - uses: ./.github/actions/setup_deps - - - name: Download foundry artifacts - uses: actions/download-artifact@v3 - with: - name: $build_artifact - - - name: Check contract sizes - run: | - npx turbo run build:sizes - - test: - needs: build - strategy: - fail-fast: true - - name: Tests - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install node deps and founry - uses: ./.github/actions/setup_deps - - - name: Download foundry artifacts - uses: actions/download-artifact@v3 - with: - name: $build_artifact - - - name: Run tests - run: | - npx turbo run test - - test_fork: - needs: build - strategy: - fail-fast: true - - name: Fork tests - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install node deps and founry - uses: ./.github/actions/setup_deps - - - name: Download foundry artifacts - uses: actions/download-artifact@v3 - with: - name: $build_artifact - - - name: Run fork tests - run: | - npx turbo run test:fork - env: - ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }} - - storage_layout: - needs: build - strategy: - fail-fast: true - - name: Inpect storage layout - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install node deps and founry - uses: ./.github/actions/setup_deps - - - name: Download foundry artifacts - uses: actions/download-artifact@v3 - with: - name: $build_artifact - - - name: "Inspect Storage Layout" - continue-on-error: false - run: npx turbo run storage-inspect:check - - build_js: - strategy: - fail-fast: true - - name: Build js package - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install node deps and founry - uses: ./.github/actions/setup_deps - - - name: Build js package - run: | - npx turbo run build - - coverage-1155: - uses: ./.github/workflows/coverage.yml - name: "Test coverage - 1155" - with: - package: "1155-contracts" - files_to_ignore: '"*DeploymentConfig*" "*Redeem*" "*deployment*" "*packages*"' - - coverage-protocol-rewards: - uses: ./.github/workflows/coverage.yml - name: "Test coverage - protocol rewards" - with: - package: "protocol-rewards" - files_to_ignore: '"*lib*"' diff --git a/.github/workflows/protocol-deployments.yml b/.github/workflows/protocol-deployments.yml new file mode 100644 index 000000000..44ba3db37 --- /dev/null +++ b/.github/workflows/protocol-deployments.yml @@ -0,0 +1,16 @@ +name: "1155" +on: + workflow_call: + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + package_folder: packages/protocol-deployments + + test: + needs: build + uses: ./.github/workflows/test.yml + with: + package_folder: packages/protocol-deployments + secrets: inherit diff --git a/.github/workflows/protocol-rewards.yml b/.github/workflows/protocol-rewards.yml new file mode 100644 index 000000000..2e30c8fae --- /dev/null +++ b/.github/workflows/protocol-rewards.yml @@ -0,0 +1,21 @@ +name: "Protocol Rewards" +on: + workflow_call: + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + package_folder: packages/protocol-rewards + + test: + needs: build + uses: ./.github/workflows/test.yml + with: + package_folder: packages/protocol-rewards + + coverage: + uses: ./.github/workflows/coverage.yml + with: + package: "protocol-rewards" + files_to_ignore: '"*lib*"' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..90e2c7d7d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +on: + workflow_call: + inputs: + package_folder: + required: true + type: string + +jobs: + check: + strategy: + fail-fast: true + + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install node deps and founry + uses: ./.github/actions/setup_deps + + - name: Load foundry cache + uses: ./.github/actions/cache_foundry_build + with: + package_folder: ${{ inputs.package_folder }} + + - name: Test + run: | + cd ${{ inputs.package_folder}} && yarn test + env: + ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }} diff --git a/packages/protocol-deployments/package.json b/packages/protocol-deployments/package.json index 57b5c6c0e..828c39f6c 100644 --- a/packages/protocol-deployments/package.json +++ b/packages/protocol-deployments/package.json @@ -8,8 +8,7 @@ "type": "module", "scripts": { "dev": "FOUNDRY_PROFILE=dev forge test --watch -vvv", - "test:fork": "FORK_TEST_CHAINS=mainnet,goerli,optimism,optimism_goerli,zora,zora_goerli,base_goerli,base,zora_sepolia forge test -vvv", - "test": "forge test -vvv", + "test": "FORK_TEST_CHAINS=mainnet,goerli,optimism,optimism_goerli,zora,zora_goerli,base_goerli,base,zora_sepolia forge test -vvv", "build": "yarn wagmi && yarn bundle-configs && tsup", "bundle-configs": "node script/bundle-chainConfigs.mjs && yarn prettier", "prettier": "prettier --write 'package/**/*.ts' 'script/**/*.ts' 'wagmi.config.ts'",