From eb79a165628d67fb706199b177c982d481ddaa15 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Thu, 30 Jan 2025 10:29:45 +0000 Subject: [PATCH] chore(ci): bump version script (#28) --- .github/workflows/label-version-bump.yml | 48 +++++------------------- scripts/version-packages.sh | 41 ++++++++++++++++++++ 2 files changed, 50 insertions(+), 39 deletions(-) create mode 100755 scripts/version-packages.sh diff --git a/.github/workflows/label-version-bump.yml b/.github/workflows/label-version-bump.yml index 1c0b0e77..3e496f5a 100644 --- a/.github/workflows/label-version-bump.yml +++ b/.github/workflows/label-version-bump.yml @@ -9,12 +9,12 @@ jobs: name: Bump version based on PR label runs-on: ubuntu-22.04 if: | - github.event.pull_request.merged - && ( - contains(github.event.pull_request.labels.*.name, 'bump patch') - || contains(github.event.pull_request.labels.*.name, 'bump minor') - || contains(github.event.pull_request.labels.*.name, 'bump major') - ) + github.event.pull_request.merged + && ( + contains(github.event.pull_request.labels.*.name, 'bump patch') + || contains(github.event.pull_request.labels.*.name, 'bump minor') + || contains(github.event.pull_request.labels.*.name, 'bump major') + ) steps: - name: Check out repository uses: actions/checkout@v4 @@ -48,42 +48,12 @@ jobs: BUMP_MINOR_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'bump minor') }} BUMP_MAJOR_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'bump major') }} - - name: Determine new version - id: versions - if: steps.bump-type.outputs.bump-type != 'null' - run: | - npm add --global semver - OLD_VERSION=$(jq ".version" package.json -r) - NEW_VERSION=$(semver $OLD_VERSION -i ${{ steps.bump-type.outputs.bump-type }}) - echo "old-version=$OLD_VERSION" >> "$GITHUB_OUTPUT" - echo "new-version=$NEW_VERSION" >> "$GITHUB_OUTPUT" - - - name: Update version in package.json for packages we import in posthog if: steps.bump-type.outputs.bump-type != 'null' + env: + BUMP_TYPE: ${{ steps.bump-type.outputs.bump-type }} run: | - # Define the package paths - PACKAGES=( - "../packages/record" - "../packages/plugins/rrweb-plugin-console-record" - "../packages/types" - "../packages/rrweb" - ) - - # Loop through each package and update the package.json - for PACKAGE in "${PACKAGES[@]}"; do - PACKAGE_JSON="$PACKAGE/package.json" - - if [ -f "$PACKAGE_JSON" ]; then - echo "Updating version in $PACKAGE_JSON" - mv "$PACKAGE_JSON" "$PACKAGE_JSON.old" || { echo "Failed to rename $PACKAGE_JSON"; exit 1; } - jq --indent 4 '.version = "'${{ steps.versions.outputs.new-version }}'"' "$PACKAGE_JSON.old" > "$PACKAGE_JSON" || { echo "Failed to update version in $PACKAGE_JSON"; exit 1; } - rm "$PACKAGE_JSON.old" || { echo "Failed to remove backup file $PACKAGE_JSON.old"; exit 1; } - else - echo "Error: $PACKAGE_JSON does not exist" - exit 1 - fi - done + $GITHUB_WORKSPACE/scripts/version-packages.sh - name: Update CHANGELOG.md diff --git a/scripts/version-packages.sh b/scripts/version-packages.sh new file mode 100755 index 00000000..406f0eff --- /dev/null +++ b/scripts/version-packages.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +if [[ -z "$BUMP_TYPE" ]]; then + echo "Error: BUMP_TYPE is not set" + exit 1 +fi + +npm add --global semver +SEMVER_BIN=$(which semver || echo "$(npm root --global)/.bin/semver") +echo "semver bin: $SEMVER_BIN" + +# Define the package paths +# assumes this is run with cwd as the root of the repo + PACKAGES=( + "./packages/record" + "./packages/plugins/rrweb-plugin-console-record" + "./packages/types" + "./packages/rrweb" + ) + + # Loop through each package and update the package.json + for PACKAGE in "${PACKAGES[@]}"; do + PACKAGE_JSON="$PACKAGE/package.json" + + echo "Updating version in $PACKAGE_JSON" + OLD_VERSION=$(jq ".version" "$PACKAGE_JSON" -r) + echo "Old Version: $OLD_VERSION" + + NEW_VERSION=$($SEMVER_BIN "$OLD_VERSION" -i ""$BUMP_TYPE"") + echo "New Version: $NEW_VERSION" + + if [ -f "$PACKAGE_JSON" ]; then + echo "Updating version in $PACKAGE_JSON" + mv "$PACKAGE_JSON" "$PACKAGE_JSON.old" || { echo "Failed to rename $PACKAGE_JSON"; exit 1; } + jq --indent 4 '.version = "'$NEW_VERSION'"' "$PACKAGE_JSON.old" > "$PACKAGE_JSON" || { echo "Failed to update version in $PACKAGE_JSON"; exit 1; } + rm "$PACKAGE_JSON.old" || { echo "Failed to remove backup file $PACKAGE_JSON.old"; exit 1; } + else + echo "Error: $PACKAGE_JSON does not exist" + exit 1 + fi + done