update changelog and website checks (#9781)

* remove expression syntax for if conditional

* make changelog check a status check
This commit is contained in:
Alvin Huang 2021-02-26 16:29:49 -05:00 committed by GitHub
parent 6b95e8dfe2
commit efd68a855a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 30 deletions

36
.github/workflows/changelog-checker.yml vendored Normal file
View File

@ -0,0 +1,36 @@
# This workflow checks that there is either a 'pr/no-changelog' label applied to a PR
# or there is a .changelog/<pr number>.txt file associated with a PR for a changelog entry
on:
pull_request:
types: [opened, synchronize, labeled]
# Runs on PRs to master and all release branches
branches:
- master
- release/*
jobs:
# checks that a .changelog entry is present for a PR
changelog-check:
# If there a `pr/no-changelog` label we ignore this check
if: "!contains(github.event.pull_request.labels.*.name, 'pr/no-changelog')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
- name: Check for changelog entry in diff
run: |
# check if there is a diff in the .changelog directory
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/${{ github.event.pull_request.base.ref }}")" -- .changelog/${{ github.event.pull_request.number }}.txt)
# If we do not find a file in .changelog/, we fail the check
if [ -z "$changelog_files" ]; then
# Fail status check when no .changelog entry was found on the PR
echo "Did not find a .changelog entry and the 'pr/no-changelog' label was not applied. Reference - https://github.com/hashicorp/consul/pull/8387."
exit 1
else
echo "Found .changelog entry in PR!"
fi

View File

@ -5,6 +5,11 @@
# #
# All the code checked out in this workflow should be considered untrusted. This workflow must # All the code checked out in this workflow should be considered untrusted. This workflow must
# never call any makefiles or scripts. It must never be changed to run any code from the checkout. # never call any makefiles or scripts. It must never be changed to run any code from the checkout.
# This workflow posts a message to a PR to remind maintainers that there are website/ changes
# in the PR and if they need to be cherry-picked to the stable-website branch, the
# 'type/docs-cherrypick' label needs to be applied.
on: on:
pull_request_target: pull_request_target:
types: [opened] types: [opened]
@ -14,39 +19,10 @@ on:
- release/* - release/*
jobs: jobs:
# checks that a .changelog entry is present for a PR
changelog-check:
# If there a `pr/no-changelog` label we ignore this check
if: "!${{ contains(github.event.pull_request.labels.*.name, 'pr/no-changelog')}}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
- name: Check for changelog entry in diff
run: |
# check if there is a diff in the .changelog directory
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/${{ github.event.pull_request.base.ref }}")" -- .changelog/)
# If we do not find a file in .changelog/, we post a comment to the PR
if [ -z "$changelog_files" ]; then
# post PR comment to GitHub when no .changelog entry was found on PR
echo "changelog-check: Did not find a .changelog entry, posting a reminder in the PR"
github_message="🤔 Double check that this PR does not require a changelog entry in the \`.changelog\` directory. [Reference](https://github.com/hashicorp/consul/pull/8387)"
curl -f -s -H "Authorization: token ${{ secrets.PR_COMMENT_TOKEN }}" \
-X POST \
-d "{ \"body\": \"${github_message}\"}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${{ github.event.pull_request.number }}/comments"
else
echo "changelog-check: Found .changelog entry in PR!"
fi
# checks that a 'type/docs-cherrypick' label is attached to PRs with website/ changes # checks that a 'type/docs-cherrypick' label is attached to PRs with website/ changes
website-check: website-check:
# If there's a `type/docs-cherrypick` label we ignore this check # If there's a `type/docs-cherrypick` label we ignore this check
if: "!${{ contains(github.event.pull_request.labels.*.name, 'type/docs-cherrypick')}}" if: "!contains(github.event.pull_request.labels.*.name, 'type/docs-cherrypick')"
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps: