Auto-deploy IPC contracts to Calibrationnet when changed #112
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 | ||
workflows: write | ||
Check failure on line 13 in .github/workflows/auto-deploy-contracts.yaml
|
||
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: Checkout cd/contracts branch-test | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: cd/contracts-test | ||
submodules: recursive | ||
fetch-depth: 0 | ||
- 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: (Dry run) Try merge from main to fail early if there are unresolvable conflicts | ||
run: | | ||
git show HEAD | ||
git checkout main | ||
git pull --rebase origin main | ||
git checkout cd/contracts-test | ||
git merge main --no-edit --allow-unrelated-histories | ||
- name: Checkout the branch that triggered this run | ||
uses: actions/checkout@v4 | ||
with: | ||
# TODO(jie): After switch to workflow_dispatch only, we should use ref_name. | ||
# head_ref only works for workflow triggered by pull requests. | ||
# ref: ${{ github.ref_name }} | ||
ref: ${{ github.head_ref }} | ||
submodules: recursive | ||
- name: Setup node and npm | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'npm' | ||
cache-dependency-path: 'pnpm-lock.yaml' | ||
- name: Deploy IPC contracts to Calibrationnet | ||
id: deploy_contracts | ||
run: | | ||
cd contracts | ||
npm install | ||
output=$(make deploy-stack NETWORK=calibrationnet | tee /dev/tty) | ||
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-test | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: cd/contracts-test | ||
submodules: recursive | ||
fetch-depth: 0 | ||
- name: Merge from main branch and update cd/contracts branch-test | ||
run: | | ||
git checkout main | ||
git pull --rebase origin main | ||
git checkout cd/contracts-test | ||
git merge main --no-edit --allow-unrelated-histories | ||
git push -f origin cd/contracts-test | ||
- name: Write deployed address to output file | ||
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 output file and push it to remote repo | ||
run: | | ||
git add deployments/r314159.json | ||
git commit -m "Update contract address" | ||
git push origin cd/contracts-test |