Skip to content

Commit

Permalink
ci: add script to update rockspec versions (#37)
Browse files Browse the repository at this point in the history
The rockspec format requires the actual filename to contain the version
of the package - so we can't use release-please's built in
`x-release-please-version` utility.

This adds a bash script which can be run locally or in CI to accomplish
the task. Inspiration from @keelerm84's work on the iOS SDK.

It renames the rockspec & updates the `version` field contained within,
plus updates the README examples. If provided with a git username and
password, it'll commit the changes and push. Otherwise the changes are
left staged.
  • Loading branch information
cwaldren-ld authored Jan 4, 2024
1 parent 0b57240 commit 36ff1c3
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 6 deletions.
30 changes: 30 additions & 0 deletions .github/actions/update-versions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Update Lua package version
description: 'Update rockspec file name and version, and code example in README.md'
inputs:
branch:
description: 'Branch to checkout and push updates to'
required: true
version:
description: 'The semantic version to use'
required: true
package:
description: 'The rockspec package to update'
required: true

runs:
using: composite
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
fetch-depth: 0

- name: Update rockspec file name and version
shell: bash
run: |
./scripts/update-versions.sh \
${{ inputs.package}} \
${{ inputs.version }} \
LaunchDarklyReleaseBot \
[email protected]
2 changes: 1 addition & 1 deletion .github/workflows/manual-publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:

name: Publish Documentation
jobs:
build-publish:
build-publish-docs:
runs-on: ubuntu-latest
permissions:
contents: write # Needed to write github pages.
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/manual-update-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
workflow_dispatch:
inputs:
version:
description: "The semantic version to use (no leading 'v'). Will update versions for base and Redis SDK."
required: true
branch:
description: 'Branch to checkout and push updates to'
required: true

name: Update Versions
jobs:
update-versions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update launchdarkly-server-sdk version
uses: ./.github/actions/update-versions
with:
package: launchdarkly-server-sdk
branch: ${{ inputs.branch }}
version: ${{ inputs.version }}

- name: Update launchdarkly-server-sdk-redis version
uses: ./.github/actions/update-versions
with:
package: launchdarkly-server-sdk-redis
branch: ${{ inputs.branch }}
version: ${{ inputs.version }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Refer to the [SDK documentation](https://docs.launchdarkly.com/sdk/server-side/l
To compile the LuaRock modules:
1. Install [LuaRocks](https://github.com/luarocks/luarocks/wiki/Download)
2. Build the [C++ Server-side SDK](https://github.com/launchdarkly/cpp-sdks) from source using CMake, or obtain pre-built artifacts from the [releases page](https://github.com/launchdarkly/cpp-sdks/releases?q=%22launchdarkly-cpp-server%22)
3. Run `luarocks make`:
3. Run `luarocks make` (replace the version number as necessary):
```bash
# Base SDK
luarocks make launchdarkly-server-sdk-1.0-0.rockspec \
Expand Down
2 changes: 1 addition & 1 deletion launchdarkly-server-sdk-1.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ description = {

source = {
url = "git+https://github.com/launchdarkly/lua-server-sdk.git",
tag = "v2.0.0" -- {{ x-release-please-version }}
tag = "v2.0.0"
}

dependencies = {
Expand Down
2 changes: 1 addition & 1 deletion launchdarkly-server-sdk-redis-1.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ description = {

source = {
url = "git+https://github.com/launchdarkly/lua-server-sdk.git",
tag = "v2.0.0" -- {{ x-release-please-version }}
tag = "v2.0.0"
}

dependencies = {
Expand Down
3 changes: 1 addition & 2 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"bump-minor-pre-major": true,
"versioning": "default",
"extra-files": [
"launchdarkly-server-sdk.c",
"launchdarkly-server-sdk-1.0-0.rockspec"
"launchdarkly-server-sdk.c"
]
}
}
Expand Down
101 changes: 101 additions & 0 deletions scripts/update-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

set -e

# This script has two responsibilities:
# 1. Update the package version in the rockspec file.
# 2. Update the actual filename of the rockspec file.
# These two should match.
# This script doesn't update the rockspec version - the part after the package version, but before the .rockspec
# suffix. That should be done manually if the rockspec itself has changed but not the package contents.
#
# For example, if the current version is 1.0.0, then the rockspec filename is
# launchdarkly-server-sdk-1.0.0-0.rockspec.
#
# If the new version is 1.2.0, then we want the new filename to be
# launchdarkly-server-sdk-1.2.0-0.rockspec.


input_rockspec=$1
input_version=$2
git_username=$3
git_email=$4

autocommit=''
if [ -n "$git_username" ] || [ -n "$git_email" ]; then
autocommit=1
fi

# Ensure autocommit if provided is
if [ -z "$input_rockspec" ] || [ -z "$input_version" ]; then
echo "Usage: $0 <rockspec package> <new version> [git username] [git email]"
echo "Example usage locally: $0 launchdarkly-server-sdk 1.2.0"
echo "Example usage in CI: $0 launchdarkly-server-sdk 1.2.0 LaunchDarklyReleaseBot [email protected]"
echo "Providing a git username and email will automatically commit & push any changes."
exit 1
fi

for file in "$input_rockspec"-*.rockspec; do
[[ -e "$file" ]] || (echo "No rockspec file found for $input_rockspec" && exit 1)

# Since the glob might match rockspecs with further suffixes (like -redis), make sure there's actually
# a version number following the $input_rockspec prefix.
if [[ ! "$file" =~ "$input_rockspec-"[0-9] ]]; then
continue
fi

# Strip off the prefix + '-' so only the semver, rockspec revision, and file extension remain.
version_suffix="${file#$input_rockspec-}"

IFS='-' read -ra parts <<< "$version_suffix"
semver="${parts[0]}"
rockspec="${parts[1]}"

# Split the suffix by '.' so we can get the rockspec version number.
IFS='.' read -ra rockspec_parts <<< "$rockspec"

rockspec_revision="${rockspec_parts[0]}"
echo "Rockspec found: $file"
echo " package version: $semver"
echo " rockspec revision: $rockspec_revision"


new_file_name="$input_rockspec-$input_version-$rockspec_revision.rockspec"
git mv "$file" "$new_file_name"
echo "Renamed $file to $new_file_name"

# Update the 'version' field with the new semver.
sed -i.bak "s/version = \".*\"/version = \"$input_version-$rockspec_revision\"/" "$new_file_name"
echo "Bumped version from $semver to $input_version"

# Update the 'tag' field to contain the git tag, which we're hardcoding as 'v' + the version number. This
# relies on the assumption that our release please config specifies a leading v.
sed -i.bak "s/tag = \".*\"/tag = \"v$input_version\"/" "$new_file_name"
echo "Updated source.tag to v$input_version"

rm -f "$new_file_name.bak"

# Update README.md to replace $file with the new filename, which will result in the codesample having the new
# version number.
sed -i.bak "s/$file/$new_file_name/" README.md
echo "Updated README.md code example"
rm -f README.md.bak

if [ "$(git status --porcelain | wc -l)" -gt 0 ]; then
if [ -n "$git_username" ]; then
git config user.name "$git_username"
fi
if [ -n "$git_email" ]; then
git config user.email "$git_email"
fi
git add "$new_file_name"
git add README.md
if [ $autocommit ]; then
git commit -m "chore: bump $input_rockspec version from $semver to $input_version and update README"
git push
else
echo "Changes staged, but not committed. Please commit manually."
fi
exit 0
fi
done

0 comments on commit 36ff1c3

Please sign in to comment.