Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create preview PRs using labels #1767

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions .github/workflows/make_prs_for_other_repos.yaml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/preview_on_auspice_us.yaml
Original file line number Diff line number Diff line change
@@ -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')
victorlin marked this conversation as resolved.
Show resolved Hide resolved
uses: ./.github/workflows/preview_on_downstream_repo.yaml
secrets: inherit
with:
repository: nextstrain/auspice.us
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Make PR for a repository which depends on Auspice"
name: "Preview on downstream repo"
on:
workflow_call:
inputs:
Expand All @@ -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 }}
jameshadfield marked this conversation as resolved.
Show resolved Hide resolved
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'
Expand All @@ -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"
Expand All @@ -73,17 +51,17 @@ 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).

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')
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/preview_on_nextstrain_org.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 1 addition & 6 deletions DEV_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading