-
Notifications
You must be signed in to change notification settings - Fork 162
96 lines (82 loc) · 3.29 KB
/
preview_on_downstream_repo.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: "Preview on downstream repo"
on:
workflow_call:
inputs:
repository:
required: true
type: string
directory:
required: false
type: string
default: .
cleanup:
required: true
type: boolean
# Cancel any in-progress runs of a caller workflow on the same pull request.
concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true
env:
branch: nextstrain-bot/test-auspice-pr/${{ github.event.number }}
jobs:
sync:
name: Create or update downstream PR
if: ${{ !inputs.cleanup }}
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Checkout downstream repo
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
token: ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }}
- name: Install Auspice from PRs HEAD commit
shell: bash
working-directory: ${{ inputs.directory }}
env:
NODE_ENV: production
run: |
npm config set ignore-scripts true
npm ci
npm install nextstrain/auspice#${{ github.sha }}
git add package.json package-lock.json
git config user.name "nextstrain-bot"
git config user.email "[email protected]"
git commit --message="[testing only] Upgrade Auspice to ${{ github.sha }}"
- name: Create Pull Request
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }}
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/${{ 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 PR is maintained by a [GitHub Actions workflow](https://github.com/nextstrain/auspice/blob/-/.github/workflows/preview_on_downstream_repo.yaml).
It will be automatically kept up to date and closed when the upstream PR has been merged or closed.
run: |
git switch -c "$branch"
git push --force origin HEAD
pr_url=$(gh pr list --head "$branch" --json url | jq -r '.[0].url')
if [ "$pr_url" = "null" ]; then
pr_url="$(gh pr create --title "$title" --body "$body" --draft)"
echo "Pull request created: $pr_url" >> "$GITHUB_STEP_SUMMARY"
else
echo "Pull request updated: $pr_url" >> "$GITHUB_STEP_SUMMARY"
fi
cleanup:
name: Cleanup downstream PR
if: inputs.cleanup
runs-on: ubuntu-latest
steps:
- name: Checkout downstream repo
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
token: ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }}
- env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }}
run: |
gh pr close "$branch"
git push --delete origin "$branch"