diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1dd72f7..e6a3fd9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,5 @@ name: Validate Plugin Version Test -on: [pull_request] +on: [push, pull_request] jobs: test: runs-on: ubuntu-latest diff --git a/action.yml b/action.yml index 82d2513..5672379 100644 --- a/action.yml +++ b/action.yml @@ -24,7 +24,6 @@ inputs: branch: description: The branch to use as the base for PRs and commit the changes back to. required: false - default: 'main' pr-status: description: The status of the PR to create. Default is 'draft'. Accepts 'draft' or 'open'. required: false @@ -50,5 +49,6 @@ runs: FILENAMES: ${{ inputs.filenames }} BRANCH: ${{ inputs.branch }} PR_STATUS: ${{ inputs.pr-status }} + GITHUB_BASE_REF: ${{ github.base_ref }} run: bash ${{ github.action_path }}/bin/validate-plugin-version.sh \ No newline at end of file diff --git a/bin/validate-plugin-version.sh b/bin/validate-plugin-version.sh index 62bf413..6c450f4 100644 --- a/bin/validate-plugin-version.sh +++ b/bin/validate-plugin-version.sh @@ -3,12 +3,15 @@ set -euo pipefail IFS=$'\n\t' main() { - # Determine the default branch - DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) + if [[ -n "${GITHUB_BASE_REF:-}" ]]; then + DEFAULT_BRANCH="${GITHUB_BASE_REF}" + else + DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) + fi echo "Default branch is $DEFAULT_BRANCH" # Check out the specified branch if $BRANCH is set and not already on it - if [[ -n "${BRANCH:-}" && "$(git rev-parse --abbrev-ref HEAD)" != "$BRANCH" ]]; then + if [[ -z "${GITHUB_BASE_REF:-}" && -n "${BRANCH:-}" && "$(git rev-parse --abbrev-ref HEAD)" != "$BRANCH" ]]; then echo "Checking if branch $BRANCH exists." if ! git show-ref --verify --quiet "refs/heads/$BRANCH"; then if git show-ref --verify --quiet "refs/remotes/origin/$BRANCH"; then