Skip to content

Commit

Permalink
Merge pull request #1567: Enable preview PRs for auspice.us
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin authored Oct 10, 2022
2 parents a6f6e5b + 2c10f73 commit 2c7eb8d
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 78 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/make_pr_for_downstream_repo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: "Make PR for a repository which depends on Auspice"
on:
workflow_call:
inputs:
repository:
required: true
type: string
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'

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 "::set-output name=pr-number::$PR_NUMBER"
echo "::set-output name=auspice-sha::$MERGE_SHA"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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

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

- name: Install Auspice from PRs HEAD commit
shell: bash
working-directory: ${{ env.DESTINATION_REPO_DIR }}
run: |
npm ci
npm install nextstrain/auspice#${{ steps.detect-pr.outputs.auspice-sha }}
git add package.json package-lock.json
- name: Create 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/${{ 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 ${{ steps.detect-pr.outputs.pr-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 }}.
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).
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 "PR number: ${{ steps.cpr.outputs.pull-request-number }}"
echo "PR URL: ${{ steps.cpr.outputs.pull-request-url }}"
99 changes: 21 additions & 78 deletions .github/workflows/make_prs_for_other_repos.yaml
Original file line number Diff line number Diff line change
@@ -1,82 +1,25 @@
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:
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).
# - 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 "::set-output name=pr-number::$PR_NUMBER"
echo "::set-output name=auspice-sha::$MERGE_SHA"
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
shell: bash
working-directory: ${{ env.DESTINATION_REPO_DIR }}
run: |
npm ci
npm install nextstrain/auspice#${{ steps.detect-pr.outputs.auspice-sha }}
git add package.json package-lock.json
- name: Create Pull Request for testing on nextstrain.org repo
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/${{ 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 ${{ 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/${{ steps.detect-pr.outputs.pr-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).
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 }}"
echo "Pull Request URL: ${{ steps.cpr.outputs.pull-request-url }}"
nextstrain-org:
if: inputs.nextstrain-org
uses: ./.github/workflows/make_pr_for_downstream_repo.yaml
secrets: inherit
with:
repository: nextstrain/nextstrain.org
auspice-us:
if: inputs.auspice-us
uses: ./.github/workflows/make_pr_for_downstream_repo.yaml
secrets: inherit
with:
repository: nextstrain/auspice.us

0 comments on commit 2c7eb8d

Please sign in to comment.