#!/bin/bash # Script to publish a package to the Gitea registry using the deploy key # Ensure the scripts directory exists mkdir -p scripts # Check if pnpm is installed if ! command -v pnpm &> /dev/null; then echo "Error: pnpm is not installed or not in your PATH." echo "Please install pnpm using one of the following methods:" echo "" echo "Using npm:" echo " npm install -g pnpm" echo "" echo "Using Homebrew (macOS):" echo " brew install pnpm" echo "" echo "Using Windows:" echo " npm install -g pnpm" echo " or" echo " winget install pnpm" echo "" echo "For more installation options, visit: https://pnpm.io/installation" exit 1 fi # Configuration KEY_FILE=".deploy-key" TOKEN_FILE=".gitea-token" GITEA_URL="https://git.generation.one" REGISTRY_URL="$GITEA_URL/api/packages/GenerationOne/npm/" # Check if arguments are provided if [ $# -lt 1 ]; then echo "Usage: $0 [version-bump]" echo "Example: $0 packages/sse-client patch" echo "Version bump can be: patch, minor, major, or none (default: none)" echo "To set a specific version: $0 packages/sse-client version:0.2.0" exit 1 fi PACKAGE_DIR="$1" VERSION_BUMP="${2:-none}" # Check if package directory exists if [ ! -d "$PACKAGE_DIR" ]; then echo "Package directory '$PACKAGE_DIR' does not exist." exit 1 fi # Check if token is available if [ -f "$TOKEN_FILE" ]; then # Read the token from file GITEA_TOKEN=$(cat "$TOKEN_FILE") echo "Using token from $TOKEN_FILE" else # Check if token is in environment variable if [ -z "$GITEA_TOKEN" ]; then echo "Gitea token not found." echo "Please either:" echo "1. Create a file named '$TOKEN_FILE' with your Gitea access token, or" echo "2. Set the GITEA_TOKEN environment variable" echo "You can generate a token at $GITEA_URL/user/settings/applications" echo "Make sure the token has 'packages:write' permission." exit 1 else echo "Using token from GITEA_TOKEN environment variable" fi fi # Navigate to the package directory cd "$PACKAGE_DIR" || exit 1 # Bump version if requested if [ "$VERSION_BUMP" != "none" ]; then # Check if it's a specific version (format: version:x.y.z) if [[ "$VERSION_BUMP" == version:* ]]; then SPECIFIC_VERSION="${VERSION_BUMP#version:}" echo "Setting specific version ($SPECIFIC_VERSION)..." npm version "$SPECIFIC_VERSION" --no-git-tag-version --allow-same-version else echo "Bumping version ($VERSION_BUMP)..." npm version "$VERSION_BUMP" --no-git-tag-version fi fi # Determine which package manager to use (prefer pnpm, fallback to npm) PKG_MANAGER="npm" if command -v pnpm &> /dev/null; then PKG_MANAGER="pnpm" echo "Using pnpm as package manager" else echo "pnpm not found, falling back to npm" fi # Install dependencies echo "Installing dependencies..." $PKG_MANAGER install --no-frozen-lockfile # Build the package echo "Building package..." $PKG_MANAGER run build # Set up .npmrc for publishing echo "Setting up .npmrc for publishing..." echo "@g1:registry=$REGISTRY_URL" > .npmrc echo "//git.generation.one/api/packages/GenerationOne/npm/:_authToken=$GITEA_TOKEN" >> .npmrc echo "legacy-peer-deps=true" >> .npmrc echo "resolution-mode=highest" >> .npmrc # Publish the package echo "Publishing package..." $PKG_MANAGER publish --no-git-checks echo "Package published successfully!"