Skip to content

Commit 6669fcc

Browse files
committed
Create preview PRs using labels
Benefits: 1. Ease of use - straight from the PR page 2. Workflow runs will show on the PR checks 3. Simplified logic in reusable workflow
1 parent d38af86 commit 6669fcc

5 files changed

+53
-66
lines changed

.github/workflows/make_prs_for_other_repos.yaml

-26
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "Preview on auspice.us"
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- synchronize
7+
- reopened
8+
- labeled
9+
10+
workflow_dispatch:
11+
12+
jobs:
13+
run:
14+
if: |
15+
github.event.label.name == 'preview on auspice.us' ||
16+
contains( github.event.pull_request.labels.*.name, 'preview on auspice.us')
17+
uses: ./.github/workflows/preview_on_downstream_repo.yaml
18+
secrets: inherit
19+
with:
20+
repository: nextstrain/auspice.us

.github/workflows/make_pr_for_downstream_repo.yaml renamed to .github/workflows/preview_on_downstream_repo.yaml

+11-34
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Make PR for a repository which depends on Auspice"
1+
name: "Preview on downstream repo"
22
on:
33
workflow_call:
44
inputs:
@@ -9,42 +9,19 @@ on:
99
required: false
1010
type: string
1111
default: .
12-
jobs:
13-
make-pr-on-downstream-repo:
14-
# I don't see this being used for tags, so ensure it's only run on branches
15-
# to make subsequent logic and wording easier.
16-
if: github.ref_type == 'branch'
1712

13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
run:
1819
runs-on: ubuntu-latest
1920

2021
env:
2122
DESTINATION_REPO_DIR: repo
2223

2324
steps:
24-
# Outputs:
25-
# - pr-number: The PR number from the branch name (exits if no PR exists).
26-
# - auspice-sha: The GitHub-managed merge ref. Used for npm install.
27-
#
28-
# Note that $GITHUB_SHA shouldn't be used here because it refers to the
29-
# branch HEAD which is not merged with the PR target branch. If the
30-
# workflow trigger event was `pull_request` then it would refer to the
31-
# merge ref¹, but we use `workflow_dispatch` to reduce the number of PRs.
32-
#
33-
# ¹ https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
34-
- name: Detect PR from branch
35-
id: detect-pr
36-
run: |
37-
PR_NUMBER=$(gh pr view $GITHUB_REF_NAME --repo nextstrain/auspice --json 'number' --jq '.number') || true
38-
if [[ -z $PR_NUMBER ]]; then
39-
echo "ERROR: This branch is not associated with a PR in Auspice." >&2
40-
exit 1
41-
fi
42-
MERGE_SHA=$(gh pr view $GITHUB_REF_NAME --repo nextstrain/auspice --json 'potentialMergeCommit' --jq '.potentialMergeCommit.oid')
43-
echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT
44-
echo "auspice-sha=$MERGE_SHA" >> $GITHUB_OUTPUT
45-
env:
46-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47-
4825
- uses: actions/setup-node@v4
4926
with:
5027
node-version: '16'
@@ -61,7 +38,7 @@ jobs:
6138
working-directory: ${{ env.DESTINATION_REPO_DIR }}/${{ inputs.directory }}
6239
run: |
6340
npm ci
64-
npm install nextstrain/auspice#${{ steps.detect-pr.outputs.auspice-sha }}
41+
npm install nextstrain/auspice#${{ github.sha }}
6542
git add package.json package-lock.json
6643
6744
git config user.name "nextstrain-bot"
@@ -73,17 +50,17 @@ jobs:
7350
working-directory: ${{ env.DESTINATION_REPO_DIR }}
7451
env:
7552
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }}
76-
title: '[bot] [DO NOT MERGE] Test Auspice PR ${{ steps.detect-pr.outputs.pr-number }}'
53+
title: '[bot] [DO NOT MERGE] Test Auspice PR ${{ github.event.number }}'
7754
body: |
78-
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 }}.
55+
This PR has been created to test this project running Auspice with changes from https://github.com/nextstrain/auspice/pull/${{ github.event.number }}.
7956
8057
Note that Auspice has been installed with changes from both the PR's source and target branches.
8158
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).
8259
8360
This message and corresponding commits were automatically created by a GitHub Action from [nextstrain/auspice](https://github.com/nextstrain/auspice).
8461
body_file: pr_body.txt
8562
run: |
86-
branch="nextstrain-bot/test-auspice-pr/${{ steps.detect-pr.outputs.pr-number }}"
63+
branch="nextstrain-bot/test-auspice-pr/${{ github.event.number }}"
8764
git switch -c "$branch"
8865
git push --force origin HEAD
8966
pr_url=$(gh pr list --head "$branch" --json url | jq -r '.[0].url')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "Preview on nextstrain.org"
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- synchronize
7+
- reopened
8+
- labeled
9+
10+
workflow_dispatch:
11+
12+
jobs:
13+
run:
14+
if: |
15+
github.event.label.name == 'preview on nextstrain.org' ||
16+
contains( github.event.pull_request.labels.*.name, 'preview on nextstrain.org')
17+
uses: ./.github/workflows/preview_on_downstream_repo.yaml
18+
secrets: inherit
19+
with:
20+
repository: nextstrain/nextstrain.org
21+
directory: auspice-client

DEV_DOCS.md

+1-6
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,7 @@ A Heroku pipeline for this repository is connected to GitHub under the nextstrai
100100

101101
#### Test on downstream repositories
102102

103-
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:
104-
105-
1. Go to [the workflow page](https://github.com/nextstrain/auspice/actions/workflows/make_prs_for_other_repos.yaml).
106-
2. Select **Run workflow**.
107-
3. Pick the PR branch, select the downstream repositories you wish to test, and **Run workflow**.
108-
4. Wait for the workflow to finish running. The Auspice PR should show new reference links from the generated PRs.
103+
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).
109104

110105
## git-lfs
111106

0 commit comments

Comments
 (0)