diff --git a/.github/workflows/mirror_noir_subrepo.yml b/.github/workflows/mirror_noir_subrepo.yml index 8d3209f32f5..0edb371ae99 100644 --- a/.github/workflows/mirror_noir_subrepo.yml +++ b/.github/workflows/mirror_noir_subrepo.yml @@ -6,92 +6,69 @@ name: Mirror to noir repo # Don't allow multiple of these running at once: concurrency: group: ${{ github.workflow }} + cancel-in-progress: false on: push: branches: - - master - paths: - - 'noir/**' - - '!noir/.gitrepo' + - ad/chore/better-noir-sync + # paths: + # - 'noir/**' + # - '!noir/.gitrepo' jobs: mirror_repo: runs-on: ubuntu-latest steps: - - name: Get commit hash of last aztec-packages squash-merge - id: last_merge_hash - uses: actions/github-script@v5 - with: - script: | - // TODO more robust heuristic if aztecbot does other things in noir - const response = await github.rest.search.commits({ - q: 'author:AztecBot repo:noir-lang/noir branch:master', - order: 'asc' - }); - - return response.data.items[0].commit.tree.sha; - - name: Check for open PRs on noir-lang/noir - id: sync_pr_exists - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} - script: | - const { data: pullRequests } = await github.rest.pulls.list({ - owner: 'noir-lang', - repo: 'noir', - state: 'open', - head: 'aztec-packages' - }); - return pullRequests.length > 0; - - name: Checkout noir repo + - name: Checkout uses: actions/checkout@v3 - if: steps.sync_pr_exists.outputs.result == 'false' with: fetch-depth: 0 - repository: noir-lang/noir token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} - - name: Reset noir-lang/noir branch if no PRs - uses: actions/checkout@v3 - if: steps.sync_pr_exists.outputs.result == 'false' - run: | - git checkout aztec-packages - git reset --hard ${{steps.last_merge_hash.outputs.result}} - git push origin aztec-packages --force + - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} - + # We push using git subrepo (https://github.com/ingydotnet/git-subrepo) - # with some logic to recover from squashed parent commits - # We push to subrepo, commit to master. The commit is needed - # to continue to replay. If we still hit issues such as this - # action failing due to upstream changes, a manual resolution - # PR with ./scripts/git_subrepo.sh pull will be needed. + # and push all Aztec commits as a single commit with metadata. - name: Push to branch run: | + set -xue # print commands SUBREPO_PATH=noir - BRANCH=aztec-packages + BRANCH=aztec2-packages # identify ourselves, needed to commit git config --global user.name AztecBot git config --global user.email tech@aztecprotocol.com - git config --file=noir/.gitrepo subrepo.commit abcdef - if ./scripts/git_subrepo.sh push $SUBREPO_PATH --branch=$BRANCH; then + BASE_NOIR_COMMIT=`git config --file=noir/.gitrepo subrepo.commit` + BASE_AZTEC_COMMIT=`git config --file=noir/.gitrepo subrepo.parent` + # Fix PR branch + git clone https://x-access-token:${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}@github.com/noir-lang/noir.git noir-repo + cd noir-repo + git checkout $BRANCH || git checkout -b $BRANCH + git reset --hard "$BASE_NOIR_COMMIT" + # Reset our branch to our expected target + git push origin $BRANCH --force + cd .. + # Now push to it with subrepo with all non-noise commit messages + MESSAGE=$(git log --pretty=format:"%s" $BASE_AZTEC_COMMIT..HEAD -- noir/ ':!noir/.gitrepo' | grep -v 'git subrepo || true') + git commit --allow-empty -m"chore: Sync to noir-lang/noir" -m"$MESSAGE" + COMMIT=$(git rev-parse HEAD) + if ./scripts/git_subrepo.sh push $SUBREPO_PATH --squash --branch=$BRANCH; then + git reset $COMMIT git commit --amend -am "$(git log -1 --pretty=%B) [skip ci]" git push else echo "Problems syncing noir. We may need to pull the subrepo." exit 1 fi - - - name: Create PR for Aztec Branch - if: steps.sync_pr_exists.outputs.result == 'false' - uses: repo-sync/pull-request@v2 - with: - github_token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} - pr_title: 'feat: Sync commits from `aztec-packages`' - pr_body: 'Development from [aztec-packages](https://github.com/AztecProtocol/aztec-packages).' - destination_branch: 'master' - source_branch: 'aztec-packages' + # Formatted for updating the PR, overrides for release-please commit message parsing + PR_BODY="BEGIN_COMMIT_OVERRIDE\n$MESSAGE\nEND_COMMIT_OVERRIDE" + PR_URL=$(gh pr list --head aztec2-packages --json url --jq ".[0].url") + if [[ "$PR_URL" == "" ]]; then + gh pr create --title "feat: Sync from aztec-packages" --body "$PR_BODY" --base master --head aztec2-packages + else + gh pr edit "$PR_URL" --body "$PR_BODY" + fi \ No newline at end of file diff --git a/.github/workflows/test_action.yml b/.github/workflows/test_action.yml deleted file mode 100644 index cdc8669a658..00000000000 --- a/.github/workflows/test_action.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: Find Recent Closed PR - -on: - push: - branches: [ ad/chore/better-noir-sync ] - -concurrency: - group: noir-sync-action-queue - cancel-in-progress: true - -jobs: - find-pr: - runs-on: ubuntu-latest - - steps: - # - name: Checkout noir repo - # uses: actions/checkout@v3 - # if: steps.sync_pr_exists.outputs.result == 'false' - # with: - # fetch-depth: 0 - # repository: noir-lang/noir - # token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} - # - name: Reset noir-lang/noir branch if no PRs - # if: steps.sync_pr_exists.outputs.result == 'false' - # run: | - # set -x # print commands - # git checkout aztec2-packages || git checkout -b aztec2-packages - # git reset --hard ${{ steps.last_merge_hash.outputs.result }} - # git push origin aztec2-packages --force - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} - - # We push using git subrepo (https://github.com/ingydotnet/git-subrepo) - # with some logic to recover from squashed parent commits - # We push to subrepo, commit to master. The commit is needed - # to continue to replay. If we still hit issues such as this - # action failing due to upstream changes, a manual resolution - # PR with ./scripts/git_subrepo.sh pull will be needed. - - name: Push to branch - run: | - set -xue # print commands - SUBREPO_PATH=noir - BRANCH=aztec2-packages - # identify ourselves, needed to commit - git config --global user.name AztecBot - git config --global user.email tech@aztecprotocol.com - BASE_NOIR_COMMIT=`git config --file=noir/.gitrepo subrepo.commit` - BASE_AZTEC_COMMIT=`git config --file=noir/.gitrepo subrepo.parent` - # Fix PR branch - git clone https://x-access-token:${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}@github.com/noir-lang/noir.git noir-repo - cd noir-repo - git checkout $BRANCH || git checkout -b $BRANCH - git reset --hard "$BASE_NOIR_COMMIT" - # Reset our branch to our expected target - git push origin $BRANCH --force - cd .. - # Now push to it with subrepo with all non-noise commit messages - MESSAGE=$(git log --pretty=format:"%s" $BASE_AZTEC_COMMIT..HEAD -- noir/ ':!noir/.gitrepo' | grep -v 'git subrepo || true') - git commit --allow-empty -m"feat: Sync commits from aztec-packages" -mBEGIN_COMMIT_OVERRIDE -m"$MESSAGE" -mEND_COMMIT_OVERRIDE - COMMIT=$(git rev-parse HEAD) - if ./scripts/git_subrepo.sh push $SUBREPO_PATH --squash --branch=$BRANCH; then - git reset $COMMIT - git commit --amend -am "$(git log -1 --pretty=%B) [skip ci]" - git push - else - echo "Problems syncing noir. We may need to pull the subrepo." - exit 1 - fi - - - # - name: Create PR for Aztec Branch - # if: steps.sync_pr_exists.outputs.result == 'false' - # uses: repo-sync/pull-request@v2 - # with: - # github_token: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} - # pr_title: 'feat: Sync commits from `aztec2-packages`' - # pr_body: 'Development from [aztec2-packages](https://github.com/AztecProtocol/aztec2-packages).' - # destination_branch: 'master' - # source_branch: 'aztec2-packages'