2021-02-01 18:51:52 -05:00
# The outline of this workflow is something that the GitHub Security team warns against
# here: https://securitylab.github.com/research/github-actions-preventing-pwn-requests. But
# due to this workflow only running a git diff check and not building or publishing anything,
# there is no harm in checking out the PR HEAD code.
#
2021-02-02 14:51:20 -05:00
# All the code checked out in this workflow should be considered untrusted. This workflow must
2021-02-01 18:51:52 -05:00
# never call any makefiles or scripts. It must never be changed to run any code from the checkout.
on :
pull_request_target :
2021-02-03 10:19:37 -05:00
types : [ opened]
2021-02-01 18:51:52 -05:00
# Runs on PRs to master and all release branches
branches :
- master
- release/*
jobs :
2021-02-02 17:04:05 -05:00
# checks that a .changelog entry is present for a PR
2021-02-01 18:51:52 -05:00
changelog-check :
# If there a `pr/no-changelog` label we ignore this check
2021-02-03 10:19:37 -05:00
if : "!${{ contains(github.event.pull_request.labels.*.name, 'pr/no-changelog')}}"
2021-02-01 18:51:52 -05:00
runs-on : ubuntu-latest
steps :
- uses : actions/checkout@v2
with :
ref : ${{ github.event.pull_request.head.sha }}
2021-02-02 14:51:20 -05:00
fetch-depth : 0 # by default the checkout action doesn't checkout all branches
2021-02-01 18:51:52 -05:00
- name : Check for changelog entry in diff
run : |
# check if there is a diff in the .changelog directory
2021-02-02 17:04:05 -05:00
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/${{ github.event.pull_request.base.ref }}")" -- .changelog/)
2021-02-01 18:51:52 -05:00
# 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"
2021-02-05 13:48:31 -05:00
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)"
2021-02-01 18:51:52 -05:00
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
2021-02-02 17:04:05 -05:00
# checks that a 'type/docs-cherrypick' label is attached to PRs with website/ changes
website-check :
# If there's a `type/docs-cherrypick` label we ignore this check
2021-02-03 10:19:37 -05:00
if : "!${{ contains(github.event.pull_request.labels.*.name, 'type/docs-cherrypick')}}"
2021-02-02 17:04:05 -05:00
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 website/ dir change in diff
run : |
# check if there is a diff in the website/ directory
website_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/${{ github.event.pull_request.base.ref }}")" -- website/)
# If we find changed files in the website/ directory, we post a comment to the PR
if [ -n "$website_files" ]; then
# post PR comment to GitHub to check if a 'type/docs-cherrypick' label needs to be applied to the PR
echo "website-check: Did not find a 'type/docs-cherrypick' label, posting a reminder in the PR"
2021-02-05 13:48:31 -05:00
github_message="🤔 This PR has changes in the \`website/\` directory but does not have a \`type/docs-cherrypick\` label. If the changes are for the next version, this can be ignored. If they are updates to current docs, attach the label to auto cherrypick to the \`stable-website\` branch after merging."
2021-02-02 17:04:05 -05:00
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"
fi