Skip to content

Commit e2f8527

Browse files
lmolkovatrask
andauthored
Label PRs that contain breaking changes based on the changelog (#1769)
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent 68b0afa commit e2f8527

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

.github/workflows/prepare-new-issue.yml

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v4
1212

13-
- name: Run update permissions
14-
run: chmod +x ./.github/workflows/scripts/prepare-new-issue.sh
15-
1613
- name: Run prepare-new-issue.sh
1714
run: ./.github/workflows/scripts/prepare-new-issue.sh
1815
env:

.github/workflows/prepare-new-pr.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: 'Prepare new PR'
2+
on:
3+
pull_request_target:
4+
types: [opened, synchronize]
5+
branches: [ 'main*' ]
6+
paths: ['.chloggen/*']
7+
8+
jobs:
9+
prepare-new-pr:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
pull-requests: write
14+
if: ${{ github.repository_owner == 'open-telemetry' }}
15+
steps:
16+
# check out main
17+
- uses: actions/checkout@v4
18+
# sparse checkout to only get the .chloggen directory
19+
- uses: actions/checkout@v4
20+
with:
21+
ref: ${{ github.head_ref }}
22+
path: prchangelog
23+
sparse-checkout: .chloggen
24+
25+
# we're going to run prepare-new-pr script from the main branch
26+
# to parse changelog record from the PR branch.
27+
- name: Run prepare-new-pr.sh
28+
run: ./.github/workflows/scripts/prepare-new-pr.sh
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
PR: ${{ github.event.pull_request.number }}
32+
PR_CHANGELOG_PATH: prchangelog
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright The OpenTelemetry Authors
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# This script uses chloggen file to get the change_type and adds it as a label to the PR.
7+
# If there are none or multiple changelog files, it will ignore the PR.
8+
#
9+
# Notes:
10+
# - label should exist in the repository in order to add it to the PR.
11+
# - if label already exist, this is a no-op.
12+
# - if any error happens, the script quietly exits with 0.
13+
14+
if [ -z ${PR:-} ]; then
15+
echo "PR number is required"
16+
exit 1
17+
fi
18+
19+
if [ -z ${PR_CHANGELOG_PATH:-} ]; then
20+
echo "PR_CHANGELOG_PATH is required"
21+
exit 1
22+
fi
23+
24+
CHLOG="$(gh pr view $PR --json files --jq '.files.[].path | select (. | startswith(".chloggen/"))')"
25+
echo "Change log file(s): ${CHLOG}"
26+
27+
if [ -z "$CHLOG" ]; then
28+
echo "No changelog found in the PR. Ignoring this change."
29+
exit 0
30+
fi
31+
32+
COUNT="$(echo "$CHLOG" | wc -l)"
33+
if [ $COUNT -eq 1 ]; then
34+
CHANGE_TYPE=$(awk -F': ' '/^change_type:/ {print $2}' "$PR_CHANGELOG_PATH/$CHLOG" | xargs)
35+
echo $CHANGE_TYPE
36+
gh pr edit "${PR}" --add-label "${CHANGE_TYPE}" || true
37+
else
38+
echo "Found multiple changelog files. Ignoring this change."
39+
fi

0 commit comments

Comments
 (0)