Skip to content

Commit

Permalink
chore(ci): bump version script (#28)
Browse files Browse the repository at this point in the history
pauldambra authored Jan 30, 2025
1 parent 947549a commit eb79a16
Showing 2 changed files with 50 additions and 39 deletions.
48 changes: 9 additions & 39 deletions .github/workflows/label-version-bump.yml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions scripts/version-packages.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit eb79a16

Please sign in to comment.