-
Notifications
You must be signed in to change notification settings - Fork 14
83 lines (74 loc) · 2.89 KB
/
dependabot-changeset.yml
File metadata and controls
83 lines (74 loc) · 2.89 KB
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
name: Dependabot Changeset
on:
pull_request:
types: [opened]
workflow_dispatch:
inputs:
pr-number:
description: "Pull request number to add a changeset for"
required: true
type: string
permissions:
contents: write
pull-requests: read
jobs:
changeset:
name: Add changeset for dependency update
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]' || github.event_name == 'workflow_dispatch'
steps:
- name: Get PR metadata
id: pr
env:
GH_TOKEN: ${{ secrets.KNOCK_ENG_BOT_GITHUB_TOKEN }}
EVENT_NAME: ${{ github.event_name }}
INPUT_PR_NUMBER: ${{ inputs.pr-number }}
REPO: ${{ github.repository }}
PR_NUMBER_FROM_EVENT: ${{ github.event.pull_request.number }}
PR_TITLE_FROM_EVENT: ${{ github.event.pull_request.title }}
PR_REF_FROM_EVENT: ${{ github.event.pull_request.head.ref }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
PR_JSON=$(gh pr view "$INPUT_PR_NUMBER" --repo "$REPO" --json title,headRefName)
echo "number=$INPUT_PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "title=$(echo "$PR_JSON" | jq -r '.title')" >> "$GITHUB_OUTPUT"
echo "ref=$(echo "$PR_JSON" | jq -r '.headRefName')" >> "$GITHUB_OUTPUT"
else
echo "number=$PR_NUMBER_FROM_EVENT" >> "$GITHUB_OUTPUT"
echo "title=$PR_TITLE_FROM_EVENT" >> "$GITHUB_OUTPUT"
echo "ref=$PR_REF_FROM_EVENT" >> "$GITHUB_OUTPUT"
fi
# Checkout the PR branch for package.json analysis and committing.
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ steps.pr.outputs.ref }}
token: ${{ secrets.KNOCK_ENG_BOT_GITHUB_TOKEN }}
fetch-depth: 2
# Checkout the trusted script from main into a subdirectory.
# This ensures we never execute code from an untrusted PR branch
# when triggered via workflow_dispatch.
- name: Checkout trusted script from main
uses: actions/checkout@v4
with:
ref: main
sparse-checkout: .github/scripts
path: .trusted
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: "package.json"
- name: Detect affected packages and create changeset
id: changeset
env:
PR_TITLE: ${{ steps.pr.outputs.title }}
PR_NUMBER: ${{ steps.pr.outputs.number }}
run: node .trusted/.github/scripts/dependabot-changeset.js
- name: Commit and push changeset
if: steps.changeset.outputs.created == 'true'
run: |
git config user.name "knock-eng-bot"
git config user.email "knock-eng-bot@users.noreply.github.com"
git add .changeset/
git commit -m "chore(deps): add changeset for dependency update"
git push