Auto-deploy IPC contracts to Calibrationnet when changed #120
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto-deploy IPC contracts to Calibrationnet when changed | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- contracts/** | |
permissions: | |
contents: write | |
env: | |
GIT_USERNAME: github-actions[bot] | |
GIT_EMAIL: ipc+github-actions[bot]@users.noreply.github.com | |
concurrency: | |
# Only allow one run at a time for this workflow | |
group: auto-deploy-contracts | |
cancel-in-progress: true | |
jobs: | |
deploy-contracts: | |
runs-on: ubuntu-latest | |
env: | |
RPC_URL: https://calibration.filfox.io/rpc/v1 | |
PRIVATE_KEY: ${{ secrets.CONTRACTS_DEPLOYER_PRIVATE_KEY }} | |
steps: | |
- name: Configure git | |
run: | | |
git config --global user.name "$GIT_USERNAME" | |
git config --global user.email "$GIT_EMAIL" | |
- name: Check out the branch that triggered this run | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref_name }} | |
submodules: recursive | |
fetch-depth: 0 | |
- uses: pnpm/action-setup@v2 | |
- name: Set up node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '21' | |
cache: 'pnpm' | |
- name: Install Foundry | |
uses: foundry-rs/foundry-toolchain@v1 | |
- name: Cache artifacts | |
uses: actions/cache@v4 | |
with: | |
## Hardhat is intelligent enough to perform incremental compilation. But GitHub Actions caches are immutable. | |
## Since we can't have a rolling cache, we create a new cache for each run, but use restore-keys to load the | |
## most recently created cache. | |
## Reference: https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache | |
key: ${{ runner.os }}-contracts-artifacts-${{ github.run_id }} | |
restore-keys: | | |
${{ runner.os }}-contracts-artifacts- | |
path: | | |
contracts/out | |
contracts/deployments | |
contracts/artifacts | |
- name: Deploy IPC contracts to Calibrationnet | |
id: deploy_contracts | |
env: | |
REGISTRY_CREATION_PRIVILEGES: 'unrestricted' | |
run: | | |
cd contracts | |
pnpm install | |
output=$(make deploy-stack NETWORK=calibrationnet | tee /dev/stdout) | |
echo "deploy_output<<EOF" >> $GITHUB_OUTPUT | |
echo "$output" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Extract deployed addresses | |
run: | | |
deploy_output='${{ steps.deploy_contracts.outputs.deploy_output }}' | |
echo "$deploy_output" | |
deployed_gateway_address=$(jq -r ".address" deployments/calibrationnet/GatewayDiamond.json) | |
deployed_registry_address=$(jq -r ".address" deployments/calibrationnet/SubnetRegistryDiamond.json) | |
echo "gateway_address=$deployed_gateway_address" >> $GITHUB_ENV | |
echo "registry_address=$deployed_registry_address" >> $GITHUB_ENV | |
echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_ENV | |
- name: Review deployed addresses | |
run: | | |
echo "commit_hash: $commit_hash" | |
echo "gateway_address: $gateway_address" | |
echo "registry_address: $registry_address" | |
- name: Switch code repo to cd/contracts branch | |
uses: actions/checkout@v4 | |
with: | |
ref: cd/contracts | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Write deployment addresses | |
run: | | |
mkdir -p deployments | |
json_str='{"commit":"'$commit_hash'","gateway_addr":"'$gateway_address'","registry_addr":"'$registry_address'"}' | |
jq -n "$json_str" > deployments/r314159.json | |
cat deployments/r314159.json | |
- name: Commit and push deployment addresses file | |
run: | | |
git add deployments/r314159.json | |
git commit -m "Contracts deployed @ ${{ github.sha }}" | |
git push origin cd/contracts |