Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require or not changelog based on label #117

Merged
merged 3 commits into from Apr 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 13 additions & 40 deletions .github/workflows/changelog-check.yml
Expand Up @@ -2,71 +2,44 @@ name: CHANGELOG Check

on:
pull_request:
issue_comment:
types: [opened, synchronize, reopened, labeled, unlabeled, edited]

env:
CHANGELOG_REQUIRED: true
IGNORE_CHECK_LABEL: allow-no-changelog

jobs:
changelog-check:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest

steps:
- name: Check if CHANGELOG is not required
id: command-check
- name: Override variable if PR is labeled ${{ env.IGNORE_CHECK_LABEL }}
if: ${{ contains(github.event.pull_request.labels.*.name, env.IGNORE_CHECK_LABEL) }}
run: |
PR_COMMENTS=$( \
curl -sSL -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
)

readarray -t comments < <(jq -c '.[]' <<<"$PR_COMMENTS")
IFS=$'\n' #read til newline
CHECK_CHANGELOG=true

for item in "${comments[@]}"; do
author_association=$(jq --raw-output '.author_association' <<< "$item")
body=$(jq --raw-output '.body' <<< "$item")

echo "author_association: $author_association"
echo "body: $body"

if [[ "$author_association" == "OWNER" || "$author_association" == "COLLABORATOR" ]]; then
# if body is no-changelog, set var to false, else if body is require-changelog, set var to true.
if [[ "$body" == *"/no-changelog"* ]]; then
CHECK_CHANGELOG=false
elif [[ "$body" == *"/require-changelog"* ]]; then
CHECK_CHANGELOG=true
fi
fi
done

if [[ "$CHECK_CHANGELOG" == "false" ]]; then
echo "No CHANGELOG required"
echo "status=skip" >> $GITHUB_OUTPUT
fi
echo "CHANGELOG_REQUIRED=false" >> $GITHUB_ENV

- uses: actions/checkout@v3
if: steps.command-check.outputs.status != 'skip'
if: fromJSON(env.CHANGELOG_REQUIRED)
with:
fetch-depth: 0
ref: refs/pull/${{ github.event.pull_request.number }}/head
ref: ${{ github.head_ref }}

# Example 1
- name: Get changed files
if: steps.command-check.outputs.status != 'skip'
if: fromJSON(env.CHANGELOG_REQUIRED)
id: changed-files
uses: tj-actions/changed-files@v35

# Example 2
- name: Get changed files in the docs folder
if: steps.command-check.outputs.status != 'skip'
if: fromJSON(env.CHANGELOG_REQUIRED)
id: changelog-changed
uses: tj-actions/changed-files@v35
with:
files: CHANGELOG.md

- name: Fail workflow if CHANGELOG.md has not been changed
if: steps.command-check.outputs.status != 'skip' && steps.changelog-changed.outputs.any_changed == 'false'
if: fromJSON(env.CHANGELOG_REQUIRED) && steps.changelog-changed.outputs.any_changed == 'false'
run: |
echo "CHANGELOG.md has not been changed"
exit 1