Skip to content

Commit

Permalink
Update verify branch pre-commit hook, add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
IanCa authored and VisLab committed Jul 16, 2024
1 parent ea62cd8 commit e05441b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/pre_commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
pull_request:
types: [labeled, opened, reopened, synchronize]
push:
branches: ["develop*"]

jobs:
run-precommit:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get latest push changes
id: changed-files
uses: tj-actions/changed-files@v44
with:
since_last_remote_commit: true

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install Pre-commit
run: pip install pre-commit

- name: Run pre-commit on changed files
run: |
if [ -n "${{ steps.changed-files.outputs.all_changed_files }}" ]; then
pre-commit run --files ${{ steps.changed-files.outputs.all_changed_files }}
else
echo "No files have changed, skipping pre-commit."
fi
17 changes: 13 additions & 4 deletions scripts/verify_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
# Script to verify changes are on the correct branch
# only applies to branches that start with develop-

# Get the current branch name
branch_name=$(git rev-parse --abbrev-ref HEAD)
# Try to use the BRANCH_NAME environment variable first
if [ -z "$BRANCH_NAME" ]; then
# Environment variable is empty or not set, fallback to git command
echo "Finding branch name from git"
branch_name=$(git rev-parse --abbrev-ref HEAD)
else
# Use the environment variable
branch_name=$BRANCH_NAME
fi


# Echo the branch name
# Echo the branch name and changed files
echo "branch_name: $branch_name"
echo "files: $@"
# Check if the branch name does not start with 'develop-'
Expand All @@ -17,11 +25,12 @@ fi
# Strip 'develop-' from the branch name
branch_name=${branch_name#develop-}

# Verify the branch name is correct after modification
echo "Processed branch_name: $branch_name"

# Define base file pattern based on branch name
if [[ "$branch_name" == "standard" ]]; then
base_pattern="standard_schema"
base_pattern="standard_schema/"
else
base_pattern="library_schemas/${branch_name}/"
fi
Expand Down

0 comments on commit e05441b

Please sign in to comment.