2021-04-19 14:35:15 +03:00
|
|
|
name: "Direct Push Warning"
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
- release-**
|
2022-07-08 20:53:38 +03:00
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
|
2021-04-19 14:35:15 +03:00
|
|
|
jobs:
|
|
|
|
build:
|
2022-07-08 20:53:38 +03:00
|
|
|
permissions:
|
|
|
|
contents: write # for peter-evans/commit-comment to comment on commit
|
2021-04-19 14:35:15 +03:00
|
|
|
runs-on: ubuntu-latest
|
2021-04-20 10:13:07 +03:00
|
|
|
if: github.repository_owner == 'NixOS'
|
2021-04-19 14:35:15 +03:00
|
|
|
env:
|
|
|
|
GITHUB_SHA: ${{ github.sha }}
|
|
|
|
GITHUB_REPOSITORY: ${{ github.repository }}
|
|
|
|
steps:
|
|
|
|
- name: Check if commit is a merge commit
|
|
|
|
id: ismerge
|
|
|
|
run: |
|
|
|
|
ISMERGE=$(curl -H 'Accept: application/vnd.github.groot-preview+json' -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ env.GITHUB_REPOSITORY }}/commits/${{ env.GITHUB_SHA }}/pulls | jq -r '.[] | select(.merge_commit_sha == "${{ env.GITHUB_SHA }}") | any')
|
2022-10-16 00:39:03 +03:00
|
|
|
echo "ismerge=$ISMERGE" >> $GITHUB_OUTPUT
|
2021-06-14 14:47:22 +03:00
|
|
|
# github events are eventually consistent, so wait until changes propagate to thier DB
|
|
|
|
- run: sleep 60
|
|
|
|
if: steps.ismerge.outputs.ismerge != 'true'
|
2021-04-19 14:35:15 +03:00
|
|
|
- name: Warn if the commit was a direct push
|
|
|
|
if: steps.ismerge.outputs.ismerge != 'true'
|
2022-03-23 02:26:58 +03:00
|
|
|
uses: peter-evans/commit-comment@v2
|
2021-04-19 14:35:15 +03:00
|
|
|
with:
|
|
|
|
body: |
|
2021-04-19 15:06:54 +03:00
|
|
|
@${{ github.actor }}, you pushed a commit directly to master/release branch
|
2021-04-19 14:35:15 +03:00
|
|
|
instead of going through a Pull Request.
|
|
|
|
|
|
|
|
That's highly discouraged beyond the few exceptions listed
|
2021-04-20 10:13:07 +03:00
|
|
|
on https://github.com/NixOS/nixpkgs/issues/118661
|