From 9b5983e784f48a130fbb1c767235fa6982e6dd30 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Fri, 15 Dec 2023 13:47:25 +0000 Subject: [PATCH] fix: map relative path to protocol circuits (#3694) This PR fixes an issue with how we mirror code in the monorepo to aztecprotocol/aztec-nr. A while back the root aztec library added a dependency on noir-protocol-circuits. In the monorepo this is achieved by use of a relative path in Nargo.toml. This works fine for contracts that pull in Aztec.nr through the monorepo (see also #3604) but it breaks projects that use [AztecProtocol/aztec-nr](https://github.com/AztecProtocol/aztec-nr) because the relative path won't exist in the mirrored repo. What this PR does is map any relative dependencies to protocol circuits to a git dependency before pushing that commit to the mirrored repo. It then undoes this change before pushing to the monorepo (we want to keep using relative paths in the monorepo). I would've preferred using `yq` since it claims it suports TOML (and is included in the default Github actions package list) but its support is limited to only basic types (so no objects like `{path="..."}`) and it can only read toml but not write it. https://github.com/mikefarah/yq/issues/1364#issuecomment-1483957510 --- .github/workflows/mirror_repos.yml | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mirror_repos.yml b/.github/workflows/mirror_repos.yml index 7f48d3d00c0..d29078c98cd 100644 --- a/.github/workflows/mirror_repos.yml +++ b/.github/workflows/mirror_repos.yml @@ -9,7 +9,7 @@ name: Mirror Repositories on: schedule: # Run the workflow every night at 2:00 AM UTC. - - cron: '0 2 * * *' + - cron: "0 2 * * *" jobs: mirror-to-build-system-repo: @@ -72,9 +72,33 @@ jobs: git config --global user.name AztecBot git config --global user.email tech@aztecprotocol.com + monorepo_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" + # list all aztec-packages tags, take the "highest" version + monorepo_tag="$(git tag --list aztec-packages-v* | sort --version-sort | tail -1)" + monorepo_protocol_circuits_path="yarn-project/noir-protocol-circuits" + nargo_file="$SUBREPO_PATH/aztec/Nargo.toml" + + # match lines like this: + # protocol_types = { path = "../../noir-protocol-circuits/src/crates/types" } + # and replace with + # protocol_types = { git="https://github.com/aztecprotocol/aztec-packages", tag="aztec-packages-v0.16.9", directory="yarn-project/noir-protocol-circuits/src/crates/types" } + sed --regexp-extended --in-place \ + "s;path\s*=\s*\".*noir-protocol-circuits(.*)\";git=\"$monorepo_url\", tag=\"$monorepo_tag\", directory=\"$monorepo_protocol_circuits_path\1\";" \ + $nargo_file + + git commit --all --message "chore: replace relative paths to noir-protocol-circuits" + if ./scripts/git_subrepo.sh push $SUBREPO_PATH --branch=master; then git fetch # in case a commit came after this git rebase origin/master - git commit --amend -m "$(git log -1 --pretty=%B) [skip ci]" + + # restore old Nargo.toml + # We have to go back two generations. History looks like this: + # HEAD <--- the commit generated by git_subrepo + # HEAD~1 <--- the chore commit created above + # HEAD~2 <--- the original commit we were supposed to mirror or the tip of master after rebase + git restore --source=HEAD~2 -- $nargo_file + git commit --all --amend -m "$(git log -1 --pretty=%B) [skip ci]" + git push fi