From 9c9bfd32da8c3a1e5059a4ca7854f26c6609b2eb Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Wed, 5 Oct 2022 09:59:30 -0700 Subject: [PATCH] Set nextstrain.org PRs to manual trigger This allows us to only create review PRs in the downstream repo when necessary, reducing the amount of excessive automated PRs. Two notes: 1. The title of the generated PR has been updated to use the source branch name rather than PR number, since that is not guaranteed with the manual trigger. For the PR description, the workflow will link to either the PR or branch if no PR exists. 2. The commit to install Auspice from is changing from the GitHub-managed PR merge HEAD to the source ref HEAD. This can have implications when run on a PR's source branch if there are notable changes in the target branch unincorporated in the source branch. To mitigate this, make sure to update the source branch (e.g. with a git rebase) before triggering this workflow. Also, do all the nextstrain.org work under a separate directory DESTINATION_REPO_DIR to make steps a bit more distinct. --- .../workflows/make_prs_for_other_repos.yaml | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/.github/workflows/make_prs_for_other_repos.yaml b/.github/workflows/make_prs_for_other_repos.yaml index f2420458c..57ebe5526 100644 --- a/.github/workflows/make_prs_for_other_repos.yaml +++ b/.github/workflows/make_prs_for_other_repos.yaml @@ -1,45 +1,66 @@ name: "Make PRs for Nextstrain projects which depend on Auspice" on: - pull_request: + workflow_dispatch: jobs: make-pr-on-nextstrain-dot-org: # + # I don't see this being used for tags, so ensure it's only run on branches + # to make subsequent wording easier. + if: github.ref_type == 'branch' + runs-on: ubuntu-latest + + env: + DESTINATION_REPO_DIR: nextstrain.org + steps: - uses: actions/setup-node@v2 with: node-version: '14' + - name: Checkout nextstrain.org repo uses: actions/checkout@v2 with: repository: nextstrain/nextstrain.org - - name: Install Auspice from PRs HEAD commit - if: ${{ github.event_name == 'pull_request' }} - # Note: $GITHUB_SHA is _not_ the same commit as the HEAD commit on the PR branch - # see https://gitpro.ttaallkk.topmunity/t/github-sha-not-the-same-as-the-triggering-commit/18286/2 + path: ${{ env.DESTINATION_REPO_DIR }} + + - name: Install Auspice from source branch HEAD commit shell: bash + working-directory: ${{ env.DESTINATION_REPO_DIR }} run: | - AUSPICE_COMMIT=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.head.sha) - echo "auspice_commit=$AUSPICE_COMMIT" >> $GITHUB_ENV npm ci - npm install nextstrain/auspice#${AUSPICE_COMMIT} + npm install nextstrain/auspice#${GITHUB_SHA} git add package.json package-lock.json + + - name: Generate Markdown link + id: generate-markdown-link + run: | + PR_NUMBER=$(gh pr view $GITHUB_REF_NAME --repo nextstrain/auspice --json 'number' --jq '.number') || true + if [[ -n $PR_NUMBER ]]; then + echo "::set-output name=text::[PR $PR_NUMBER](https://github.com/nextstrain/auspice/pull/$PR_NUMBER)" + else + echo "::set-output name=text::[branch $GITHUB_REF_NAME](https://github.com/nextstrain/auspice/tree/$GITHUB_REF_NAME)" + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Create Pull Request for testing on nextstrain.org repo - if: ${{ github.event_name == 'pull_request' }} id: cpr uses: peter-evans/create-pull-request@v3 + path: ${{ env.DESTINATION_REPO_DIR }} with: token: ${{ secrets.NEXTSTRAIN_BOT_PAT }} - branch: "nextstrain-bot/test-auspice-pr/${{ github.event.pull_request.number }}" - commit-message: "[testing only] Upgrade Auspice to ${{ env.auspice_commit }}" + branch: "nextstrain-bot/test-auspice-branch/${{ github.ref_name }}" + commit-message: "[testing only] Upgrade Auspice to ${{ github.sha }}" author: 'nextstrain-bot ' committer: 'nextstrain-bot ' - title: '[bot] [DO NOT MERGE] Test Auspice PR ${{ github.event.pull_request.number }}' + title: '[bot] [DO NOT MERGE] Test Auspice branch ${{ github.ref_name }}' body: | - This PR has been created to test Auspice from [PR ${{ github.event.pull_request.number }}](https://github.com/nextstrain/auspice/pull/${{ github.event.pull_request.number }}). + This PR has been created to test Auspice from ${{ steps.generate-markdown-link.outputs.text }}. This message and corresponding commits were automatically created by a GitHub Action from [nextstrain/auspice](https://github.com/nextstrain/auspice). draft: true delete-branch: true + - name: Check outputs run: | echo "Nextstrain.org PR: ${{ steps.cpr.outputs.pull-request-number }}"