From bf7a834e1747efb2badbc5ab7e38ad7c19fab791 Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Thu, 1 May 2025 12:39:08 -0400 Subject: [PATCH] ci: fix GH Actions issue on `release` event in `ensure-database-migrations-drop-columns-the-correct-way` step (#5527) --- .github/workflows/linting-and-tests.yml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/linting-and-tests.yml b/.github/workflows/linting-and-tests.yml index 50eeab0a..87f5e928 100644 --- a/.github/workflows/linting-and-tests.yml +++ b/.github/workflows/linting-and-tests.yml @@ -105,15 +105,28 @@ jobs: id: extract_base_ref shell: bash env: - BASE_REF: ${{ github.event.pull_request.base.ref }} + EVENT_NAME: ${{ github.event_name }} + PR_BASE_REF: ${{ github.event.pull_request.base.ref }} + RELEASE_TARGET: ${{ github.event.release.target_commitish }} run: | - # Validate against safe pattern (alphanumeric, underscore, dash, dot, and forward slash only) - if [[ ! "${BASE_REF}" =~ ^[a-zA-Z0-9_/.-]+$ ]]; then - echo "Invalid branch name pattern detected" + # Determine base ref from safe, pre-evaluated env variables + if [[ "$EVENT_NAME" == "pull_request" ]]; then + BASE_REF="$PR_BASE_REF" + elif [[ "$EVENT_NAME" == "release" ]]; then + BASE_REF="$RELEASE_TARGET" + else + echo "Unsupported event: $EVENT_NAME" exit 1 fi + + # Validate against safe pattern (alphanumeric, underscore, dash, dot, and forward slash only) + if [[ ! "$BASE_REF" =~ ^[a-zA-Z0-9_/.-]+$ ]]; then + echo "Invalid branch name pattern detected: $BASE_REF" + exit 1 + fi + # Store validated ref for later steps - echo "base_ref=${BASE_REF}" >> $GITHUB_OUTPUT + echo "base_ref=$BASE_REF" >> $GITHUB_OUTPUT - name: Fetch base branch shell: bash