From 31dfcc93241fed349f8015f9a10bfff488e3270f Mon Sep 17 00:00:00 2001 From: Khattab Date: Fri, 9 Feb 2024 22:03:38 +0200 Subject: [PATCH] feature(devops-work): add github action to Prevent Direct Pushes to Main --- .github/workflows/prevent-direct-push.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/prevent-direct-push.yml diff --git a/.github/workflows/prevent-direct-push.yml b/.github/workflows/prevent-direct-push.yml new file mode 100644 index 0000000..92e6519 --- /dev/null +++ b/.github/workflows/prevent-direct-push.yml @@ -0,0 +1,19 @@ +name: Prevent Direct Pushes to Main + +on: + push: + branches: + - main + +jobs: + prevent_direct_push: + runs-on: ubuntu-latest + + steps: + - name: Check if push is direct to main and not a force push + if: > + github.ref == 'refs/heads/main' && + github.event_name == 'push' && + github.event.pull_request == null && + github.event.head_commit != null + run: exit 1 # Exit with an error code to fail the workflow