diff --git a/.github/workflows/changelog-check.yml b/.github/workflows/changelog-check.yml index 0a9f88c1..755ccd4d 100644 --- a/.github/workflows/changelog-check.yml +++ b/.github/workflows/changelog-check.yml @@ -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