Skip to content

[Actions] Create go/gitStatusCheck Action #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions actions/go/gitStatusCheck/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
33 changes: 33 additions & 0 deletions actions/go/gitStatusCheck/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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