Skip to content

Commit

Permalink
Adding different patterns for attempting to find PR number for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
skduncan committed Oct 22, 2024
1 parent 85a429b commit e67ddd9
Showing 1 changed file with 73 additions and 17 deletions.
90 changes: 73 additions & 17 deletions .github/workflows/github-actions-release-candidate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,58 +49,114 @@ jobs:
- name: Get Semver Label
id: get-label
run: |
set -x # Enable debug mode to print commands as they execute
echo "Event name: ${{ github.event_name }}"
set -x # Enable debug mode
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
PR_NUMBER="${{ github.event.inputs.pr_number }}"
echo "Using provided PR number: $PR_NUMBER"
echo "Using manually provided PR number: $PR_NUMBER"
else
echo "Getting PR number from last commit message..."
echo "Analyzing commit for PR number..."
# Print full commit message for debugging
echo "Full commit message:"
git log -1 --pretty=%B
PR_NUMBER=$(git log -1 --pretty=%B | grep -oP '#\K\d+' || true)
echo "Extracted PR number: $PR_NUMBER"
# Pattern 1: Merge pull request #X from ...
echo "Trying Pattern 1: Standard merge commit format (Merge pull request #X from ...)"
PR_NUMBER=$(git log -1 --pretty=%B | grep -oP "Merge pull request #\K\d+" || true)
if [ ! -z "$PR_NUMBER" ]; then
echo "✅ Pattern 1 successfully found PR number: $PR_NUMBER"
else
echo "❌ Pattern 1 did not find PR number"
fi
# Pattern 2: #X from ...
if [ -z "$PR_NUMBER" ]; then
echo "Trying Pattern 2: Simple PR reference (#X)"
PR_NUMBER=$(git log -1 --pretty=%B | grep -oP "#\K\d+" || true)
if [ ! -z "$PR_NUMBER" ]; then
echo "✅ Pattern 2 successfully found PR number: $PR_NUMBER"
else
echo "❌ Pattern 2 did not find PR number"
fi
fi
# Pattern 3: GitHub event payload
if [ -z "$PR_NUMBER" ]; then
echo "Trying Pattern 3: GitHub event payload"
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
if [ ! -z "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then
echo "✅ Pattern 3 successfully found PR number: $PR_NUMBER"
else
echo "❌ Pattern 3 did not find PR number"
fi
fi
# Pattern 4: Commit message title
if [ -z "$PR_NUMBER" ]; then
echo "Trying Pattern 4: Commit message title"
PR_NUMBER=$(git log -1 --pretty=%s | grep -oP "#\K\d+" || true)
if [ ! -z "$PR_NUMBER" ]; then
echo "✅ Pattern 4 successfully found PR number: $PR_NUMBER"
else
echo "❌ Pattern 4 did not find PR number"
fi
fi
# Pattern 5: GitHub API
if [ -z "$PR_NUMBER" ]; then
echo "Trying Pattern 5: GitHub API for commit"
COMMIT_SHA=$(git rev-parse HEAD)
echo "Checking commit SHA: $COMMIT_SHA"
PR_NUMBER=$(gh api repos/${{ github.repository }}/commits/$COMMIT_SHA/pulls --jq '.[0].number' || true)
if [ ! -z "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then
echo "✅ Pattern 5 successfully found PR number: $PR_NUMBER"
else
echo "❌ Pattern 5 did not find PR number"
fi
fi
echo "Final PR number extraction result: $PR_NUMBER"
fi
if [ -z "$PR_NUMBER" ]; then
echo "Error: No PR number found."
echo "⛔ Error: Could not determine PR number from any pattern"
echo "GitHub event name: ${{ github.event_name }}"
echo "GitHub event path content:"
cat "$GITHUB_EVENT_PATH"
exit 1
fi
echo "Fetching labels for PR #$PR_NUMBER..."
gh auth status
LABELS=$(gh pr view $PR_NUMBER --json labels -q '.labels[].name' || echo "Failed to fetch labels")
echo "Found labels: $LABELS"
if [ "$?" -ne 0 ]; then
echo "Error: Failed to fetch PR labels"
if [ -z "$LABELS" ]; then
echo "Error: Failed to fetch PR labels"
exit 1
fi
echo "Filtering for Semver labels..."
SEMVER_LABEL=$(echo "$LABELS" | grep -E '^(major|minor|patch)$' || true)
echo "Found Semver labels: $SEMVER_LABEL"
if [ -z "$SEMVER_LABEL" ]; then
echo "Error: No valid Semver label (major, minor, patch) found on PR #$PR_NUMBER."
echo "Error: No valid Semver label (major, minor, patch) found on PR #$PR_NUMBER."
exit 1
fi
LABEL_COUNT=$(echo "$SEMVER_LABEL" | wc -l)
echo "Number of Semver labels found: $LABEL_COUNT"
if [ "$LABEL_COUNT" -ne 1 ]; then
echo "Error: Expected exactly one Semver label, found $LABEL_COUNT on PR #$PR_NUMBER."
echo "Error: Expected exactly one Semver label, found $LABEL_COUNT on PR #$PR_NUMBER."
exit 1
fi
echo "SEMVER_LABEL=$SEMVER_LABEL" >> $GITHUB_ENV
echo "Successfully found Semver label: $SEMVER_LABEL"
echo "Successfully found Semver label: $SEMVER_LABEL"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Adding explicit GH_TOKEN for gh CLI

GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Grab Current Version and Set New RC Version
id: set-version
run: |
Expand Down

0 comments on commit e67ddd9

Please sign in to comment.