Skip to content

Commit

Permalink
Set nextstrain.org PRs to manual trigger
Browse files Browse the repository at this point in the history
This allows us to only create review PRs in the downstream repo when
necessary, reducing the amount of excessive automated PRs.

Two notes:

1. With the manual trigger, there is an option to allow this workflow to
   run on tags and branches without PRs. To keep the logic simpler and
   maintain previous behavior, I've chosen to not allow those scenarios.
2. The GITHUB_SHA of workflow_dispatch is no longer the GitHub-managed
   PR merge ref, so it can be used here to retain original behavior.

Also, do all the nextstrain.org work under a separate directory
DESTINATION_REPO_DIR to make steps a bit more distinct.
  • Loading branch information
victorlin committed Oct 6, 2022
1 parent 05268e8 commit a89046f
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions .github/workflows/make_prs_for_other_repos.yaml
Original file line number Diff line number Diff line change
@@ -1,45 +1,68 @@
name: "Make PRs for Nextstrain projects which depend on Auspice"
on:
pull_request:
workflow_dispatch:
jobs:
make-pr-on-nextstrain-dot-org: # <job_id>
# 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'

runs-on: ubuntu-latest

env:
DESTINATION_REPO_DIR: nextstrain.org

steps:
# Outputs:
# - pr-number: The PR number from the branch name (exits if no PR exists).
- 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
echo "::set-output name=pr-number::$PR_NUMBER"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/setup-node@v2
with:
node-version: '14'

- name: Checkout nextstrain.org repo
uses: actions/checkout@v2
with:
repository: nextstrain/nextstrain.org
path: ${{ env.DESTINATION_REPO_DIR }}

- 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://github.community/t/github-sha-not-the-same-as-the-triggering-commit/18286/2
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: Create Pull Request for testing on nextstrain.org repo
if: ${{ github.event_name == 'pull_request' }}
id: cpr
uses: peter-evans/create-pull-request@v3
with:
path: ${{ env.DESTINATION_REPO_DIR }}
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-pr/${{ steps.detect-pr.outputs.pr-number }}"
commit-message: "[testing only] Upgrade Auspice to ${{ github.sha }}"
author: 'nextstrain-bot <[email protected]>'
committer: 'nextstrain-bot <[email protected]>'
title: '[bot] [DO NOT MERGE] Test Auspice PR ${{ github.event.pull_request.number }}'
title: '[bot] [DO NOT MERGE] Test Auspice PR ${{ steps.detect-pr.outputs.pr-number }}'
body: |
This PR has been created to test nextstrain.org running Auspice with changes from https://github.com/nextstrain/auspice/pull/${{ github.event.pull_request.number }}.
This PR has been created to test nextstrain.org running Auspice with changes from https://github.com/nextstrain/auspice/pull/${{ steps.detect-pr.outputs.pr-number }}.
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 }}"
Expand Down

0 comments on commit a89046f

Please sign in to comment.