Skip to content

Commit

Permalink
refactor(automation): Add Check to ensure only next moves code to prod (
Browse files Browse the repository at this point in the history
#5676)

* Rename test workflow and clean up code

The test workflow file has been renamed to 'on-pr.yml' to better reflect its usage. Extra space within the workflow file has also been removed for neatness and readability.

* Add Github action to validate PR source branch

This commit introduces a new Github Action workflow that checks the source branch of pull requests. The action ensures that only changes from the "next" branch can enter the "prod" branch.

* Add validation for branch names in Github action

In the "on-pr-change" Github action, additional validation checks have been added to ensure the HEAD_REF and BASE_REF branch names do not contain invalid characters. Now, the script checks for invalid characters in branch names and restricts merge requests to the prod branch only from the next branch.

* Refactor branch character check in workflow file

Removed the previously defined environmental variables for checking branch names in the .github/workflows/on-pr-change.yml file. The branch character validation has been removed as this is already done by Github. The same check was simplified using Github context variables directly.

* Update branch check logic in Github Actions workflow

The commit adds environment variables to store HEAD_REF and BASE_REF in the Github Actions workflow for checking branches in .github/workflows/on-pr-change.yml file. Using these variables should improve the readability and maintainability of the branch comparison logic.

* Refactored GitHub Actions workflow conditions

The commit refactors the conditional check in the on-pr-change.yml GitHub Actions workflow. It introduces new variables: HEAD and BASE to replace the direct usage of env.HEAD_REF and env.BASE_REF in the condition check, enhancing readability and maintainability.

* Simplify conditional statement in GitHub Action

This commit streamlines the conditional statement in the on-pr-change.yml GitHub Action script. The previous version unnecessarily assigned HEAD_REF and BASE_REF environment variables to local variables, which were subsequently used in the branch comparison checks. The updated version directly uses these environment variables.

* Update .github/workflows/on-pr.yml

---------

Co-authored-by: Richard Fontein <[email protected]>
  • Loading branch information
Cliftonz and rifont authored Jun 4, 2024
1 parent 8e0635d commit abb9ed6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/on-pr-change.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check pull request source branch
on:
pull_request_target:
types:
- opened
- reopened
- synchronize
- edited
jobs:
check-branches:
runs-on: ubuntu-latest
steps:
- name: Check branches
env:
HEAD_REF: ${{ github.head_ref }}
BASE_REF: ${{ github.base_ref }}
run: |
if [ $HEAD_REF != "next" ] && [ $BASE_REF == "prod" ]; then
echo "Merge requests to prod branch are only allowed from next branch."
exit 1
fi
File renamed without changes.

0 comments on commit abb9ed6

Please sign in to comment.