diff --git a/.github/actions/update-versions/action.yml b/.github/actions/update-versions/action.yml new file mode 100644 index 0000000..05708c8 --- /dev/null +++ b/.github/actions/update-versions/action.yml @@ -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 \ + LaunchDarklyReleaseBot@launchdarkly.com diff --git a/.github/workflows/manual-publish-docs.yml b/.github/workflows/manual-publish-docs.yml index 7020ac0..85cdc26 100644 --- a/.github/workflows/manual-publish-docs.yml +++ b/.github/workflows/manual-publish-docs.yml @@ -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. diff --git a/.github/workflows/manual-update-versions.yml b/.github/workflows/manual-update-versions.yml new file mode 100644 index 0000000..714aa62 --- /dev/null +++ b/.github/workflows/manual-update-versions.yml @@ -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 }} diff --git a/README.md b/README.md index ba9c5ec..4704a60 100644 --- a/README.md +++ b/README.md @@ -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 \ diff --git a/launchdarkly-server-sdk-1.0-0.rockspec b/launchdarkly-server-sdk-1.0-0.rockspec index e60936e..b209745 100644 --- a/launchdarkly-server-sdk-1.0-0.rockspec +++ b/launchdarkly-server-sdk-1.0-0.rockspec @@ -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 = { diff --git a/launchdarkly-server-sdk-redis-1.0-0.rockspec b/launchdarkly-server-sdk-redis-1.0-0.rockspec index 62dc8e7..3f27948 100644 --- a/launchdarkly-server-sdk-redis-1.0-0.rockspec +++ b/launchdarkly-server-sdk-redis-1.0-0.rockspec @@ -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 = { diff --git a/release-please-config.json b/release-please-config.json index 67ccd2b..6b46642 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -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" ] } } diff --git a/scripts/update-versions.sh b/scripts/update-versions.sh new file mode 100755 index 0000000..bd9b970 --- /dev/null +++ b/scripts/update-versions.sh @@ -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 [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 LaunchDarklyReleaseBot@launchdarkly.com" + 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