From 96fdaabb404e3967d1ac53455ea72beaecd77589 Mon Sep 17 00:00:00 2001 From: Guillermo Perez Date: Thu, 19 Dec 2024 20:14:20 +0100 Subject: [PATCH] new script for version bumps --- .github/ci-scripts/check-version-bump.sh | 40 ------------------------ .github/ci-scripts/pr-label-check.sh | 36 +++++++++++++++++++++ .github/ci-scripts/toggle-alpha.sh | 30 ------------------ 3 files changed, 36 insertions(+), 70 deletions(-) delete mode 100755 .github/ci-scripts/check-version-bump.sh create mode 100755 .github/ci-scripts/pr-label-check.sh delete mode 100755 .github/ci-scripts/toggle-alpha.sh diff --git a/.github/ci-scripts/check-version-bump.sh b/.github/ci-scripts/check-version-bump.sh deleted file mode 100755 index 6f5c296..0000000 --- a/.github/ci-scripts/check-version-bump.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# Get the current version from package.json -current_version=$(node -p "require('./package.json').version") -current_commit=$(git rev-parse --short HEAD) - -# Get the previous version from the last commit -previous_version=$(git show HEAD~1:package.json | node -p "JSON.parse(require('fs').readFileSync(0, 'utf-8')).version") -previous_commit=$(git rev-parse --short HEAD~1) - -# Compare the versions -if [ "$current_version" != "$previous_version" ]; then - echo "Version changed from $previous_version (commit $previous_commit) to $current_version (commit $current_commit)" - echo "Creating release https://github.com/centrifuge/sdk/releases/tag/$current_version" - exit 0 -else - echo "Version $current_version remains unchanged between commits $previous_commit and $current_commit" - # Initialize error flag - has_error=0 - - # Check if GitHub release exists - if ! curl -s -f "https://api.github.com/repos/centrifuge/sdk/releases/tags/v${current_version}" &>/dev/null; then - echo "ERROR: GitHub tag v${current_version} does not exist." - has_error=1 - fi - - # Check if npm package version exists - if ! npm view "@centrifuge/sdk@${current_version}" version &>/dev/null; then - echo "ERROR: NPM package @centrifuge/sdk@${current_version} does not exist." - has_error=1 - fi - - # Exit with error if either check failed - if [ $has_error -eq 1 ]; then - echo "Maybe a step was skipped for v$current_version? Please check the release manually." - exit 1 - fi - # If the version on package.json is released and hasn't changed, exit without errors. - exit 0 -fi \ No newline at end of file diff --git a/.github/ci-scripts/pr-label-check.sh b/.github/ci-scripts/pr-label-check.sh new file mode 100755 index 0000000..d101981 --- /dev/null +++ b/.github/ci-scripts/pr-label-check.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Function to check if a specific label exists in the list +contains_label() { + local label="$1" + shift + for item in "$@"; do + if [[ "$item" == "$label" ]]; then + return 0 + fi + done + 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') + +# Convert labels to an array +IFS=$'\n' read -rd '' -a label_array <<<"$labels" + +# List of labels to check +LABELS_TO_CHECK=("major" "minor" "patch" "no-release" "alpha") + +# Check for the specified labels +for label in "${LABELS_TO_CHECK[@]}"; do + if contains_label "$label" "${label_array[@]}"; then + echo "$label" + exit 0 + fi +done + +# If no specified label is found, return 'no-release' +echo "no-release" \ No newline at end of file diff --git a/.github/ci-scripts/toggle-alpha.sh b/.github/ci-scripts/toggle-alpha.sh deleted file mode 100755 index e51619c..0000000 --- a/.github/ci-scripts/toggle-alpha.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -# Read the current version from package.json -current_version=$(node -p "require('./package.json').version") - -# Check if version contains alpha -if [[ "$current_version" == *"-alpha"* ]]; then - if [[ "$1" != "yes" ]]; then - # Remove alpha if present and "yes" is not passed - new_version="${current_version%%-alpha*}" - else - # Keep the current version if "yes" is passed - new_version="${current_version}" - fi -elif [[ "$1" == "yes" ]]; then - # Add alpha if not present and "yes" was passed - new_version="${current_version}-alpha" -else - # Keep current version if no alpha and no "yes" passed - new_version="${current_version}" -fi - -# Update the package.json with the new version -node -e " - let pkg = require('./package.json'); - pkg.version = '$new_version'; - require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2)); -" - -echo "Updated version to $new_version" \ No newline at end of file