-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Label PRs that contain breaking changes based on the changelog (#1769)
Co-authored-by: Trask Stalnaker <[email protected]>
- Loading branch information
Showing
3 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: 'Prepare new PR' | ||
on: | ||
pull_request_target: | ||
types: [opened, synchronize] | ||
branches: [ 'main*' ] | ||
paths: ['.chloggen/*'] | ||
|
||
jobs: | ||
prepare-new-pr: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
if: ${{ github.repository_owner == 'open-telemetry' }} | ||
steps: | ||
# check out main | ||
- uses: actions/checkout@v4 | ||
# sparse checkout to only get the .chloggen directory | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
path: prchangelog | ||
sparse-checkout: .chloggen | ||
|
||
# we're going to run prepare-new-pr script from the main branch | ||
# to parse changelog record from the PR branch. | ||
- name: Run prepare-new-pr.sh | ||
run: ./.github/workflows/scripts/prepare-new-pr.sh | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PR: ${{ github.event.pull_request.number }} | ||
PR_CHANGELOG_PATH: prchangelog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Copyright The OpenTelemetry Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# This script uses chloggen file to get the change_type and adds it as a label to the PR. | ||
# If there are none or multiple changelog files, it will ignore the PR. | ||
# | ||
# Notes: | ||
# - label should exist in the repository in order to add it to the PR. | ||
# - if label already exist, this is a no-op. | ||
# - if any error happens, the script quietly exits with 0. | ||
|
||
if [ -z ${PR:-} ]; then | ||
echo "PR number is required" | ||
exit 1 | ||
fi | ||
|
||
if [ -z ${PR_CHANGELOG_PATH:-} ]; then | ||
echo "PR_CHANGELOG_PATH is required" | ||
exit 1 | ||
fi | ||
|
||
CHLOG="$(gh pr view $PR --json files --jq '.files.[].path | select (. | startswith(".chloggen/"))')" | ||
echo "Change log file(s): ${CHLOG}" | ||
|
||
if [ -z "$CHLOG" ]; then | ||
echo "No changelog found in the PR. Ignoring this change." | ||
exit 0 | ||
fi | ||
|
||
COUNT="$(echo "$CHLOG" | wc -l)" | ||
if [ $COUNT -eq 1 ]; then | ||
CHANGE_TYPE=$(awk -F': ' '/^change_type:/ {print $2}' "$PR_CHANGELOG_PATH/$CHLOG" | xargs) | ||
echo $CHANGE_TYPE | ||
gh pr edit "${PR}" --add-label "${CHANGE_TYPE}" || true | ||
else | ||
echo "Found multiple changelog files. Ignoring this change." | ||
fi |