Skip to content

Commit

Permalink
ci: test refactor of sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
paigen11 committed Oct 3, 2024
1 parent a50a3c9 commit a510813
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 31 deletions.
33 changes: 3 additions & 30 deletions .github/workflows/publish-beta-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,7 @@ jobs:
- name: Get existing beta versions from npm
id: get_existing_versions
run: |
# Query npm for existing versions of the package
EXISTING_VERSIONS=$(npm show @blues-inc/notehub-js versions --json)
echo "Existing versions on npm: $EXISTING_VERSIONS"
# Extract current version without any existing beta suffix
BASE_VERSION=$(echo "$CURRENT_VERSION" | sed -E 's/-beta\.[0-9]+$//')
# Extract only the beta versions for the current base version (e.g., 1.0.23-beta.X)
CURRENT_BETA_VERSIONS=$(echo "$EXISTING_VERSIONS" | jq -r '.[]' | grep -E "^${BASE_VERSION}-beta\.[0-9]+$" || true)
echo "Current beta versions: $CURRENT_BETA_VERSIONS"
# Determine the next beta version number
if [ -z "$CURRENT_BETA_VERSIONS" ]; then
NEXT_BETA_VERSION=1
else
# Extract numeric suffixes of all beta versions, sort, and get the highest
HIGHEST_BETA_VERSION=$(echo "$CURRENT_BETA_VERSIONS" | sed -E 's/.*-beta\.([0-9]+)$/\1/' | sort -n | tail -n 1)
NEXT_BETA_VERSION=$((HIGHEST_BETA_VERSION + 1))
fi
# Set the new version as `MAJOR.MINOR.PATCH-beta.N`
NEW_VERSION="${BASE_VERSION}-beta.$NEXT_BETA_VERSION"
echo "Next beta version: $NEW_VERSION"
# Save to GitHub environment variables
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
run: bash ./.github/scripts/get-existing-beta-versions.sh $CURRENT_VERSION

- name: Update version to beta
run: |
Expand Down Expand Up @@ -83,8 +56,8 @@ jobs:
- name: Publish Beta Version to npm
run: |
echo "Publishing beta version to npm... $new_version"
cd src
npm publish --tag beta --access public
# cd src
# npm publish --tag beta --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/scripts/get-existing-beta-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
# bash boilerplate
# Script to retrieve existing beta versions from npm and determine the next beta version.

readonly SCRIPT_NAME="$(basename "$0")"
readonly SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
function l { # Log a message to the terminal.
echo
echo -e "[$SCRIPT_NAME] ${1:-}"
}

set -e

# Ensure a valid version was provided
if [ -z "$1" ]; then
echo "Usage: $0 <current-version>"
exit 1
fi

CURRENT_VERSION=$1
echo "Current project version: $CURRENT_VERSION"

# Query npm for existing versions of the package
EXISTING_VERSIONS=$(npm show @blues-inc/notehub-js versions --json)
echo "Existing versions on npm: $EXISTING_VERSIONS"

# Extract current version without any existing beta suffix
BASE_VERSION=$(echo "$CURRENT_VERSION" | sed -E 's/-beta\.[0-9]+$//')
echo "Base version: $BASE_VERSION"

# Extract only the beta versions for the current base version (e.g., 1.0.23-beta.X)
CURRENT_BETA_VERSIONS=$(echo "$EXISTING_VERSIONS" | jq -r '.[]' | grep -E "^${BASE_VERSION}-beta\.[0-9]+$" || true)
echo "Current beta versions: $CURRENT_BETA_VERSIONS"

# Determine the next beta version number
if [ -z "$CURRENT_BETA_VERSIONS" ]; then
NEXT_BETA_VERSION=1
else
# Extract numeric suffixes of all beta versions, sort, and get the highest
HIGHEST_BETA_VERSION=$(echo "$CURRENT_BETA_VERSIONS" | sed -E 's/.*-beta\.([0-9]+)$/\1/' | sort -n | tail -n 1)
NEXT_BETA_VERSION=$((HIGHEST_BETA_VERSION + 1))
fi

# Set the new version as `MAJOR.MINOR.PATCH-beta.N`
NEW_VERSION="${BASE_VERSION}-beta.$NEXT_BETA_VERSION"
echo "Next beta version: $NEW_VERSION"

# Save the new version as a GitHub environment variable
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
2 changes: 1 addition & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ info:
title: Notehub API
version: 1.1.0
description: |
The OpenAPI definition for the Notehub.io API.
The OpenAPI definition for the Notehub.io API. Test
contact:
name: Blues Engineering
email: engineering@blues.io
Expand Down

0 comments on commit a510813

Please sign in to comment.