diff --git a/.github/workflows/pre_commit.yaml b/.github/workflows/pre_commit.yaml new file mode 100644 index 0000000..aeda467 --- /dev/null +++ b/.github/workflows/pre_commit.yaml @@ -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 \ No newline at end of file diff --git a/scripts/verify_branch.sh b/scripts/verify_branch.sh index febb898..235bdd8 100755 --- a/scripts/verify_branch.sh +++ b/scripts/verify_branch.sh @@ -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-' @@ -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