diff --git a/.github/workflows/make_prs_for_other_repos.yaml b/.github/workflows/make_prs_for_other_repos.yaml deleted file mode 100644 index db16eb5d0..000000000 --- a/.github/workflows/make_prs_for_other_repos.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: "Make PRs for Nextstrain projects which depend on Auspice" -on: - workflow_dispatch: - inputs: - nextstrain-org: - description: 'Make PR on nextstrain.org' - required: true - type: boolean - auspice-us: - description: 'Make PR on auspice.us' - required: true - type: boolean -jobs: - nextstrain-org: - if: inputs.nextstrain-org - uses: ./.github/workflows/make_pr_for_downstream_repo.yaml - secrets: inherit - with: - repository: nextstrain/nextstrain.org - directory: auspice-client - auspice-us: - if: inputs.auspice-us - uses: ./.github/workflows/make_pr_for_downstream_repo.yaml - secrets: inherit - with: - repository: nextstrain/auspice.us diff --git a/.github/workflows/preview_on_auspice_us.yaml b/.github/workflows/preview_on_auspice_us.yaml new file mode 100644 index 000000000..d33fbc912 --- /dev/null +++ b/.github/workflows/preview_on_auspice_us.yaml @@ -0,0 +1,21 @@ +name: "Preview on auspice.us" +on: + pull_request: + types: + - opened + - synchronize + - reopened + - labeled + + workflow_dispatch: + +jobs: + run: + # Run if PR has the label and is updated or is newly labeled with the label + if: | + (github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'preview on auspice.us')) || + (github.event.action == 'labeled' && github.event.label.name == 'preview on auspice.us') + uses: ./.github/workflows/preview_on_downstream_repo.yaml + secrets: inherit + with: + repository: nextstrain/auspice.us diff --git a/.github/workflows/make_pr_for_downstream_repo.yaml b/.github/workflows/preview_on_downstream_repo.yaml similarity index 56% rename from .github/workflows/make_pr_for_downstream_repo.yaml rename to .github/workflows/preview_on_downstream_repo.yaml index 77b851395..b2109f02d 100644 --- a/.github/workflows/make_pr_for_downstream_repo.yaml +++ b/.github/workflows/preview_on_downstream_repo.yaml @@ -1,4 +1,4 @@ -name: "Make PR for a repository which depends on Auspice" +name: "Preview on downstream repo" on: workflow_call: inputs: @@ -9,42 +9,20 @@ on: required: false type: string default: . -jobs: - make-pr-on-downstream-repo: - # I don't see this being used for tags, so ensure it's only run on branches - # to make subsequent logic and wording easier. - if: github.ref_type == 'branch' +# Cancel any in-progress runs of a caller workflow on the same branch. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + run: runs-on: ubuntu-latest env: DESTINATION_REPO_DIR: repo steps: - # Outputs: - # - pr-number: The PR number from the branch name (exits if no PR exists). - # - auspice-sha: The GitHub-managed merge ref. Used for npm install. - # - # Note that $GITHUB_SHA shouldn't be used here because it refers to the - # branch HEAD which is not merged with the PR target branch. If the - # workflow trigger event was `pull_request` then it would refer to the - # merge ref¹, but we use `workflow_dispatch` to reduce the number of PRs. - # - # ¹ https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request - - name: Detect PR from branch - id: detect-pr - run: | - PR_NUMBER=$(gh pr view $GITHUB_REF_NAME --repo nextstrain/auspice --json 'number' --jq '.number') || true - if [[ -z $PR_NUMBER ]]; then - echo "ERROR: This branch is not associated with a PR in Auspice." >&2 - exit 1 - fi - MERGE_SHA=$(gh pr view $GITHUB_REF_NAME --repo nextstrain/auspice --json 'potentialMergeCommit' --jq '.potentialMergeCommit.oid') - echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT - echo "auspice-sha=$MERGE_SHA" >> $GITHUB_OUTPUT - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/setup-node@v4 with: node-version: '16' @@ -61,7 +39,7 @@ jobs: working-directory: ${{ env.DESTINATION_REPO_DIR }}/${{ inputs.directory }} run: | npm ci - npm install nextstrain/auspice#${{ steps.detect-pr.outputs.auspice-sha }} + npm install nextstrain/auspice#${{ github.sha }} git add package.json package-lock.json git config user.name "nextstrain-bot" @@ -73,9 +51,9 @@ jobs: working-directory: ${{ env.DESTINATION_REPO_DIR }} env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }} - title: '[bot] [DO NOT MERGE] Test Auspice PR ${{ steps.detect-pr.outputs.pr-number }}' + title: '[bot] [DO NOT MERGE] Test Auspice PR ${{ github.event.number }}' body: | - This PR has been created to test this project running Auspice with changes from https://github.com/nextstrain/auspice/pull/${{ steps.detect-pr.outputs.pr-number }}. + This PR has been created to test this project running Auspice with changes from https://github.com/nextstrain/auspice/pull/${{ github.event.number }}. Note that Auspice has been installed with changes from both the PR's source and target branches. This will surface any issues that can arise from merging the PR in Auspice. To address these issues locally, update the source branch (e.g. with a git rebase). @@ -83,7 +61,7 @@ jobs: This message and corresponding commits were automatically created by a GitHub Action from [nextstrain/auspice](https://github.com/nextstrain/auspice). body_file: pr_body.txt run: | - branch="nextstrain-bot/test-auspice-pr/${{ steps.detect-pr.outputs.pr-number }}" + branch="nextstrain-bot/test-auspice-pr/${{ github.event.number }}" git switch -c "$branch" git push --force origin HEAD pr_url=$(gh pr list --head "$branch" --json url | jq -r '.[0].url') diff --git a/.github/workflows/preview_on_nextstrain_org.yaml b/.github/workflows/preview_on_nextstrain_org.yaml new file mode 100644 index 000000000..f217b2c2f --- /dev/null +++ b/.github/workflows/preview_on_nextstrain_org.yaml @@ -0,0 +1,22 @@ +name: "Preview on nextstrain.org" +on: + pull_request: + types: + - opened + - synchronize + - reopened + - labeled + + workflow_dispatch: + +jobs: + run: + # Run if PR has the label and is updated or is newly labeled with the label + if: | + (github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'preview on nextstrain.org')) || + (github.event.action == 'labeled' && github.event.label.name == 'preview on nextstrain.org') + uses: ./.github/workflows/preview_on_downstream_repo.yaml + secrets: inherit + with: + repository: nextstrain/nextstrain.org + directory: auspice-client diff --git a/DEV_DOCS.md b/DEV_DOCS.md index 3601239d2..78cd405ae 100644 --- a/DEV_DOCS.md +++ b/DEV_DOCS.md @@ -100,12 +100,7 @@ A Heroku pipeline for this repository is connected to GitHub under the nextstrai #### Test on downstream repositories -Additionally, a GitHub Actions workflow has been set up to generate PRs in downstream repositories that reflect the new changes in Auspice. To use it: - -1. Go to [the workflow page](https://github.com/nextstrain/auspice/actions/workflows/make_prs_for_other_repos.yaml). -2. Select **Run workflow**. -3. Pick the PR branch, select the downstream repositories you wish to test, and **Run workflow**. -4. Wait for the workflow to finish running. The Auspice PR should show new reference links from the generated PRs. +Additionally, a GitHub Actions workflow has been set up to generate PRs in downstream repositories that reflect the new changes in Auspice. To use it, add the label [preview on auspice.us](https://github.com/nextstrain/auspice/labels/preview%20on%20auspice.us) and/or [preview on nextstrain.org](https://github.com/nextstrain/auspice/labels/preview%20on%20nextstrain.org). ## git-lfs