forked from usebruno/bruno-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (49 loc) · 1.83 KB
/
Copy pathchangeset.yml
File metadata and controls
56 lines (49 loc) · 1.83 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
name: Changeset
on:
pull_request:
types: [labeled]
branches: [main, 'release/**']
jobs:
changeset:
# A fork PR gets a read-only token, so the push would 403. Skip cleanly instead of
# failing. fork contributors are covered by the changeset status check.
if: >
startsWith(github.event.label.name, 'changeset:') &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Write the changeset
env:
LABEL: ${{ github.event.label.name }}
TITLE: ${{ github.event.pull_request.title }}
BRANCH: ${{ github.event.pull_request.head.ref }}
NUMBER: ${{ github.event.pull_request.number }}
run: |
bump="${LABEL#changeset:}"
slug=$(printf '%s' "$BRANCH" \
| tr '[:upper:]' '[:lower:]' \
| sed -e 's#[^a-z0-9]#-#g' -e 's#--*#-#g' -e 's#^-##' -e 's#-$##')
mkdir -p .changeset
printf -- '---\n"@opencollection/docs": %s\n---\n\n%s (#%s)\n' \
"$bump" "$TITLE" "$NUMBER" > ".changeset/${slug}.md"
cat ".changeset/${slug}.md"
- name: Commit it to the PR branch
env:
ACTOR: ${{ github.actor }}
ACTOR_ID: ${{ github.actor_id }}
run: |
git config user.name "$ACTOR"
git config user.email "${ACTOR_ID}+${ACTOR}@users.noreply.github.com"
git add .changeset
if git diff --cached --quiet; then
echo "changeset unchanged, nothing to commit"
exit 0
fi
git commit -m "chore: add changeset"
git push