Skip to content
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

ci: Fix pr-check script always checking latest PR instead of current #38

Merged
merged 1 commit into from
Jan 3, 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
13 changes: 9 additions & 4 deletions .github/ci-scripts/pr-label-check.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/bash

# Check if PR number is provided
if [ -z "$1" ]; then
echo "Error: PR number is required."
exit 1
fi

PR_NUMBER="$1"

# Function to check if a specific label exists in a list
contains_label() {
local label="$1"
Expand All @@ -12,11 +20,8 @@ contains_label() {
return 1
}

# Fetch the most recent merged PR number
LAST_PR_NUMBER=$(gh pr list --state merged --json number --jq '.[0].number')

# Fetch the labels of the PR
labels=$(gh pr view "$LAST_PR_NUMBER" --json labels --jq '.labels[].name')
labels=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')

# Convert labels to an array
IFS=$'\n' read -rd '' -a label_array <<<"$labels"
Expand Down
22 changes: 15 additions & 7 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
if [ "${{ github.event_name }}" == "pull_request_review" ]; then
PR_NUMBER=${{ github.event.pull_request.number }}
else
PR_NUMBER=$(gh pr list --state merged --json number --jq '.[0].number')
Expand All @@ -54,19 +54,27 @@ jobs:
echo "::notice::PR used to check version bump: #$PR_NUMBER"
echo "::notice::PR labels: "[${LABELS//$'\n'/,}]""

RELEASE_TYPE=$(./.github/ci-scripts/pr-label-check.sh) || exit_code=$?
if [ "$exit_code" -ne 0 ]; then
echo "::error::PR #"$PR_NUMBER" has more than one release label"
exit $exit_code
# Make script executable
chmod +x ./.github/ci-scripts/pr-label-check.sh

# Run the script and capture both output and exit code
RELEASE_TYPE=$(./.github/ci-scripts/pr-label-check.sh $PR_NUMBER 2>&1) || {
# If script exits with non-zero, output the error and exit
echo "::error::Script failed with output: $RELEASE_TYPE"
exit 1
}

# Only proceed if we have a valid release type
if [ -z "$RELEASE_TYPE" ]; then
echo "::error::No valid release type determined"
exit 1
fi

echo "version=$RELEASE_TYPE" >> $GITHUB_OUTPUT
echo "::group::Output version"
echo "::notice::Release type: $RELEASE_TYPE"
if [ "$RELEASE_TYPE" == "no-release" ]; then
echo "::notice::PR is not flagged for release, skipping other steps"
fi
echo "::endgroup::"

- name: Bump version
id: bump
Expand Down
Loading