diff --git a/actions/go/gitStatusCheck/action.yml b/actions/go/gitStatusCheck/action.yml new file mode 100644 index 0000000..fffff0b --- /dev/null +++ b/actions/go/gitStatusCheck/action.yml @@ -0,0 +1,27 @@ +name: Git Status Check for Go +description: "Determines if specific files have changes (*.go, go.mod, go.sum)" +inputs: + branch: + type: string + required: false + default: main +outputs: + shouldRun: + description: 'Whether specified files were modified' + value: ${{ steps.CheckWorkflowCriteria.outputs.shouldRun }} +runs: + using: 'composite' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set execute permissions + shell: bash + run: chmod +x ${{github.action_path}}/entrypoint.sh + + - name: Check Workflow Criteria + id: CheckWorkflowCriteria + shell: bash + run: ${{github.action_path}}/entrypoint.sh + env: + BRANCH_NAME: ${{ inputs.branch }} diff --git a/actions/go/gitStatusCheck/entrypoint.sh b/actions/go/gitStatusCheck/entrypoint.sh new file mode 100644 index 0000000..fe188d7 --- /dev/null +++ b/actions/go/gitStatusCheck/entrypoint.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +echo "Checking for changes in specific files..." + +# Fetch the pull request's merge commit +pr_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH") +git fetch origin +refs/pull/"${pr_number}"/merge +diff_files=$(git diff --name-only origin/"$BRANCH_NAME" FETCH_HEAD) + +# Output the diff files for debugging +echo "Changed files:" +echo "$diff_files" + +# Initialize the flag +should_run_entire_workflow=false + +# Check each file in the diff +for file in $diff_files; do + if [[ "$file" == *.go ]] || [[ "$file" == "go.mod" ]] || [[ "$file" == "go.sum" ]]; then + echo "Triggering file is $file" + should_run_entire_workflow=true + break + fi +done + +# Set the output based on the flag +if [ "$should_run_entire_workflow" = true ]; then + echo "Setting shouldRun to $should_run_entire_workflow" + echo "shouldRun=true" >> "$GITHUB_OUTPUT" +else + echo "Setting shouldRun to $should_run_entire_workflow" + echo "shouldRun=false" >> "$GITHUB_OUTPUT" +fi \ No newline at end of file