From 5627f3a219b62586da6c0d9da41ce2ef8a7b0b68 Mon Sep 17 00:00:00 2001 From: "Matthew M. Keeler" Date: Fri, 1 Dec 2023 15:07:23 -0500 Subject: [PATCH] ci: Replace releaser with release please (#229) --- .circleci/config.yml | 153 ------------------ .github/actions/build-docs/action.yml | 9 ++ .github/actions/ci/action.yml | 36 +++++ .github/actions/publish-docs/action.yml | 15 ++ .github/actions/publish/action.yml | 18 +++ .github/workflows/ci.yml | 75 +++++++++ .github/workflows/lint-pr-title.yml | 12 ++ .github/workflows/manual-publish-docs.yml | 23 +++ .github/workflows/manual-publish.yml | 36 +++++ .github/workflows/release-please.yml | 51 ++++++ .ldrelease/build-docs.sh | 15 -- .ldrelease/config.yml | 29 ---- .release-please-manifest.json | 3 + Makefile | 2 +- README.md | 2 +- .../impl/integrations/redis_impl.rb | 2 +- release-please-config.json | 11 ++ spec/migrator_builder_spec.rb | 18 +-- 18 files changed, 301 insertions(+), 209 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/actions/build-docs/action.yml create mode 100644 .github/actions/ci/action.yml create mode 100644 .github/actions/publish-docs/action.yml create mode 100644 .github/actions/publish/action.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/lint-pr-title.yml create mode 100644 .github/workflows/manual-publish-docs.yml create mode 100644 .github/workflows/manual-publish.yml create mode 100644 .github/workflows/release-please.yml delete mode 100755 .ldrelease/build-docs.sh delete mode 100644 .ldrelease/config.yml create mode 100644 .release-please-manifest.json create mode 100644 release-please-config.json diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 4e9170cc..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,153 +0,0 @@ -version: 2.1 - -orbs: - rubocop: hanachin/rubocop@0.0.6 - win: circleci/windows@5.0 - -workflows: - version: 2 - test: - jobs: - - rubocop/rubocop: - after-install-rubocop: - - run: gem install rubocop-performance - - build-test-windows - - build-test-linux: - name: Ruby 3.0 - docker-image: cimg/ruby:3.0 - - build-test-linux: - name: Ruby 3.1 - docker-image: cimg/ruby:3.1 - - build-test-linux: - name: Ruby 3.2 - docker-image: cimg/ruby:3.2 - - build-test-linux: - name: JRuby 9.4 - docker-image: jruby:9.4-jdk - jruby: true - spec-tags: -t '~flaky' - -jobs: - build-test-windows: - executor: win/default - - environment: - LD_SKIP_DATABASE_TESTS: 0 - LD_ENABLE_CODE_COVERAGE: 1 - - steps: - - checkout - - # No idea what this is. But the win orb starts it up on port 8000 which - # conflicts with DynamoDB. So we will stop it. - - run: - name: "Shutdown IBXDashboard" - command: Stop-Service IBXDashboard - - - run: - name: "Setup DynamoDB" - command: | - iwr -outf dynamo.zip https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.zip - mkdir dynamo - Expand-Archive -Path dynamo.zip -DestinationPath dynamo - - run: - name: "Run DynamoDB" - background: true - working_directory: dynamo - command: javaw -D"java.library.path=./DynamoDBLocal_lib" -jar DynamoDBLocal.jar - - - run: - name: "Setup Consul" - command: | - iwr -outf consul.zip https://releases.hashicorp.com/consul/1.14.3/consul_1.14.3_windows_amd64.zip - mkdir consul - Expand-Archive -Path consul.zip -DestinationPath consul - - run: - name: "Run Consul" - background: true - working_directory: consul - command: .\consul.exe agent -dev -client 0.0.0.0 - - - run: - name: "Setup Redis" - command: | - iwr -outf redis.zip https://github.com/MicrosoftArchive/redis/releases/download/win-3.0.504/Redis-x64-3.0.504.zip - mkdir redis - Expand-Archive -Path redis.zip -DestinationPath redis - cd redis - ./redis-server --service-install - - run: - name: "Run Redis" - background: true - working_directory: redis - command: ./redis-server --service-start - - - run: ruby -v - - run: choco install msys2 -y - - run: ridk.cmd install 3 # Install MINGW dev toolchain - - - run: gem install bundler -v 2.2.33 - - run: bundle _2.2.33_ install - - run: mkdir /tmp/circle-artifacts - - run: bundle _2.2.33_ exec rspec --format documentation --format RspecJunitFormatter -o /tmp/circle-artifacts/rspec.xml spec - - run: mv coverage /tmp/circle-artifacts/ - - - store_test_results: - path: /tmp/circle-artifacts - - store_artifacts: - path: /tmp/circle-artifacts - - build-test-linux: - parameters: - docker-image: - type: string - jruby: - type: boolean - default: false - spec-tags: - type: string - default: "" - - docker: - - image: <> - - image: hashicorp/consul - - image: redis - - image: amazon/dynamodb-local - - environment: - LD_SKIP_DATABASE_TESTS: 0 - LD_ENABLE_CODE_COVERAGE: 1 - - steps: - - checkout - - when: - condition: <> - steps: - - run: gem install jruby-openssl -v 0.11.0 # required by bundler, no effect on Ruby MRI - - run: apt-get update -y && apt-get install -y build-essential - - when: - condition: - not: <> - steps: - - run: sudo apt-get update -y && sudo apt-get install -y build-essential - - run: ruby -v - - run: gem install bundler -v 2.2.33 - - run: bundle _2.2.33_ install - - run: mkdir /tmp/circle-artifacts - - run: bundle _2.2.33_ exec rspec --format documentation --format RspecJunitFormatter -o /tmp/circle-artifacts/rspec.xml spec <> - - run: mv coverage /tmp/circle-artifacts/ - - - when: - condition: - not: <> - steps: - - run: make build-contract-tests - - run: - command: make start-contract-test-service - background: true - - run: TEST_HARNESS_PARAMS="-junit /tmp/circle-artifacts/contract-tests-junit.xml" make run-contract-tests - - - store_test_results: - path: /tmp/circle-artifacts - - store_artifacts: - path: /tmp/circle-artifacts diff --git a/.github/actions/build-docs/action.yml b/.github/actions/build-docs/action.yml new file mode 100644 index 00000000..eddd44db --- /dev/null +++ b/.github/actions/build-docs/action.yml @@ -0,0 +1,9 @@ +name: Build Documentation +description: 'Build Documentation.' + +runs: + using: composite + steps: + - name: Build Documentation + shell: bash + run: cd docs && make html diff --git a/.github/actions/ci/action.yml b/.github/actions/ci/action.yml new file mode 100644 index 00000000..599bb901 --- /dev/null +++ b/.github/actions/ci/action.yml @@ -0,0 +1,36 @@ +name: CI Workflow +description: 'Shared CI workflow.' +inputs: + ruby-version: + description: 'The version of ruby to setup and run' + required: true + +runs: + using: composite + steps: + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ inputs.ruby-version }} + bundler: 2.2.33 + + - name: Install dependencies + shell: bash + run: bundle _2.2.33_ install + + - name: Skip flaky tests for jruby + if: ${{ startsWith(inputs.ruby-version, 'jruby') }} + shell: bash + run: echo "SPEC_TAGS=-t '~flaky'" >> $GITHUB_ENV + + - name: Run tests + shell: bash + run: bundle _2.2.33_ exec rspec spec $SPEC_TAGS + + - name: Run RuboCop + shell: bash + run: bundle exec rubocop --parallel + + - name: Run contract tests + if: ${{ !startsWith(inputs.ruby-version, 'jruby') }} + shell: bash + run: make contract-tests diff --git a/.github/actions/publish-docs/action.yml b/.github/actions/publish-docs/action.yml new file mode 100644 index 00000000..9d04fbf3 --- /dev/null +++ b/.github/actions/publish-docs/action.yml @@ -0,0 +1,15 @@ +name: Publish Documentation +description: 'Publish the documentation to GitHub Pages' +inputs: + token: + description: 'Token to use for publishing.' + required: true + +runs: + using: composite + steps: + - uses: launchdarkly/gh-actions/actions/publish-pages@publish-pages-v1.0.1 + name: 'Publish to Github pages' + with: + docs_path: docs/build/html/ + github_token: ${{inputs.token}} # For the shared action the token should be a GITHUB_TOKEN< diff --git a/.github/actions/publish/action.yml b/.github/actions/publish/action.yml new file mode 100644 index 00000000..b1cb2c1c --- /dev/null +++ b/.github/actions/publish/action.yml @@ -0,0 +1,18 @@ +name: Publish Package +description: 'Publish the package to rubygems' +inputs: + dry_run: + description: 'Is this a dry run. If so no package will be published.' + required: true + +runs: + using: composite + steps: + - name: Build gemspec + shell: bash + run: gem build ld-eventsource.gemspec + + - name: Publish Library + shell: bash + if: ${{ inputs.dry_run == 'false' }} + run: gem push ld-eventsource-*.gem diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..846ee44a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,75 @@ +name: Run CI +on: + push: + branches: [ main ] + paths-ignore: + - '**.md' # Do not need to run CI for markdown changes. + pull_request: + branches: [ main ] + paths-ignore: + - '**.md' + +jobs: + build-linux: + runs-on: ubuntu-latest + + env: + LD_SKIP_DATABASE_TESTS: 0 + + strategy: + matrix: + ruby-version: + - '3.0' + - '3.1' + - '3.2' + - jruby-9.4 + + services: + redis: + image: redis + ports: + - 6379:6379 + dynamodb: + image: amazon/dynamodb-local + ports: + - 8000:8000 + consul: + image: hashicorp/consul + ports: + - 8500:8500 + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # If you only need the current version keep this. + + - uses: ./.github/actions/ci + with: + ruby-version: ${{ matrix.ruby-version }} + + - uses: ./.github/actions/build-docs + if: ${{ !startsWith(matrix.ruby-version, 'jruby') }} + + build-windows: + runs-on: windows-latest + + env: + LD_SKIP_DATABASE_TESTS: 1 + + defaults: + run: + shell: powershell + + steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0 + bundler: 2.2.33 + + - name: Install dependencies + run: bundle _2.2.33_ install + + - name: Run tests + run: bundle _2.2.33_ exec rspec spec diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml new file mode 100644 index 00000000..4ba79c13 --- /dev/null +++ b/.github/workflows/lint-pr-title.yml @@ -0,0 +1,12 @@ +name: Lint PR title + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + lint-pr-title: + uses: launchdarkly/gh-actions/.github/workflows/lint-pr-title.yml@main diff --git a/.github/workflows/manual-publish-docs.yml b/.github/workflows/manual-publish-docs.yml new file mode 100644 index 00000000..f883d290 --- /dev/null +++ b/.github/workflows/manual-publish-docs.yml @@ -0,0 +1,23 @@ +on: + workflow_dispatch: + +name: Publish Documentation +jobs: + build-publish-docs: + runs-on: ubuntu-latest + permissions: + id-token: write # Needed if using OIDC to get release secrets. + contents: write # Needed in this case to write github pages. + steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0 + bundler: 2.2.33 + + - uses: ./.github/actions/build-docs + + - uses: ./.github/actions/publish-docs + with: + token: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/manual-publish.yml b/.github/workflows/manual-publish.yml new file mode 100644 index 00000000..c3703e2f --- /dev/null +++ b/.github/workflows/manual-publish.yml @@ -0,0 +1,36 @@ +name: Publish Package +on: + workflow_dispatch: + inputs: + dry_run: + description: 'Is this a dry run. If so no package will be published.' + type: boolean + required: true + +jobs: + build-publish: + runs-on: ubuntu-latest + # Needed to get tokens during publishing. + permissions: + id-token: write + contents: read + steps: + - uses: actions/checkout@v4 + + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.0 + name: 'Get rubygems API key' + with: + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + ssm_parameter_pairs: '/production/common/releasing/rubygems/api_key = GEM_HOST_API_KEY' + + - id: build-and-test + name: Build and Test + uses: ./.github/actions/ci + with: + ruby-version: 3.0 + + - id: publish + name: Publish Package + uses: ./.github/actions/publish + with: + dry_run: ${{ inputs.dry_run }} diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 00000000..14dff4e9 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,51 @@ +name: Run Release Please + +on: + push: + branches: + - main + +jobs: + release-package: + runs-on: ubuntu-latest + permissions: + id-token: write # Needed if using OIDC to get release secrets. + contents: write # Contents and pull-requests are for release-please to make releases. + pull-requests: write + steps: + - uses: google-github-actions/release-please-action@v3 + id: release + with: + command: manifest + token: ${{secrets.GITHUB_TOKEN}} + default-branch: main + + - uses: actions/checkout@v4 + if: ${{ steps.release.outputs.releases_created }} + with: + fetch-depth: 0 # If you only need the current version keep this. + + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.0 + if: ${{ steps.release.outputs.releases_created }} + name: 'Get rubygems API key' + with: + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + ssm_parameter_pairs: '/production/common/releasing/rubygems/api_key = GEM_HOST_API_KEY' + + - uses: ./.github/actions/ci + if: ${{ steps.release.outputs.releases_created }} + with: + ruby-version: 3.0 + + - uses: ./.github/actions/build-docs + if: ${{ steps.release.outputs.releases_created }} + + - uses: ./.github/actions/publish + if: ${{ steps.release.outputs.releases_created }} + with: + dry_run: false + + - uses: ./.github/actions/publish-docs + if: ${{ steps.release.outputs.releases_created }} + with: + token: ${{secrets.GITHUB_TOKEN}} diff --git a/.ldrelease/build-docs.sh b/.ldrelease/build-docs.sh deleted file mode 100755 index 8f41a5b6..00000000 --- a/.ldrelease/build-docs.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# doc generation is not part of Releaser's standard Ruby project template - -cd ./docs -make -cd build/html - -# Releaser will pick up generated docs if we put them in the designated -# directory. They will be uploaded to GitHub Pages and also attached as -# release artifacts. There's no separate "publish-docs" step because the -# external service that also hosts them doesn't require an upload, it just -# picks up gems automatically. - -cp -r * "${LD_RELEASE_DOCS_DIR}" diff --git a/.ldrelease/config.yml b/.ldrelease/config.yml deleted file mode 100644 index 89f4f24b..00000000 --- a/.ldrelease/config.yml +++ /dev/null @@ -1,29 +0,0 @@ -version: 2 - -repo: - public: ruby-server-sdk - private: ruby-server-sdk-private - -branches: - - name: main - - name: 5.x - - name: 6.x - - name: 7.x - -publications: - - url: https://rubygems.org/gems/launchdarkly-server-sdk - description: RubyGems - - url: https://www.rubydoc.info/gems/launchdarkly-server-sdk - description: documentation - -jobs: - - docker: - image: ruby:3.0-buster - template: - name: ruby - -documentation: - gitHubPages: true - -sdk: - displayName: "Ruby" diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 00000000..c575a162 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "7.3.0" +} diff --git a/Makefile b/Makefile index 07676969..176acf14 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ start-contract-test-service-bg: @make start-contract-test-service >$(TEMP_TEST_OUTPUT) 2>&1 & run-contract-tests: - @curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/main/downloader/run.sh \ + @curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/v2/downloader/run.sh \ | VERSION=v2 PARAMS="-url http://localhost:9000 -debug -stop-service-at-end $(TEST_HARNESS_PARAMS)" sh contract-tests: build-contract-tests start-contract-test-service-bg run-contract-tests diff --git a/README.md b/README.md index 8fe7b9ea..02aeb6f8 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ LaunchDarkly Server-side SDK for Ruby [![Gem Version](https://badge.fury.io/rb/launchdarkly-server-sdk.svg)](http://badge.fury.io/rb/launchdarkly-server-sdk) -[![Circle CI](https://circleci.com/gh/launchdarkly/ruby-server-sdk/tree/main.svg?style=svg)](https://circleci.com/gh/launchdarkly/ruby-server-sdk/tree/main) +[![Run CI](https://github.com/launchdarkly/ruby-server-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/launchdarkly/ruby-server-sdk/actions/workflows/ci.yml) [![RubyDoc](https://img.shields.io/static/v1?label=docs+-+all+versions&message=reference&color=00add8)](https://www.rubydoc.info/gems/launchdarkly-server-sdk) [![GitHub Pages](https://img.shields.io/static/v1?label=docs+-+latest&message=reference&color=00add8)](https://launchdarkly.github.io/ruby-server-sdk) diff --git a/lib/ldclient-rb/impl/integrations/redis_impl.rb b/lib/ldclient-rb/impl/integrations/redis_impl.rb index cb7fb6c3..0a0a3a2e 100644 --- a/lib/ldclient-rb/impl/integrations/redis_impl.rb +++ b/lib/ldclient-rb/impl/integrations/redis_impl.rb @@ -112,7 +112,7 @@ def initialize(opts) @pool = create_redis_pool(opts) # shutdown pool on close unless the client passed a custom pool and specified not to shutdown - @pool_shutdown_on_close = (!opts[:pool] || opts.fetch(:pool_shutdown_on_close, true)) + @pool_shutdown_on_close = !opts[:pool] || opts.fetch(:pool_shutdown_on_close, true) @prefix = opts[:prefix] || LaunchDarkly::Integrations::Redis::default_prefix @logger = opts[:logger] || Config.default_logger diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 00000000..9c5e3af8 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,11 @@ +{ + "packages": { + ".": { + "release-type": "ruby", + "bump-minor-pre-major": true, + "versioning": "default", + "include-component-in-tag": false, + "include-v-in-tag": false + } + } +} diff --git a/spec/migrator_builder_spec.rb b/spec/migrator_builder_spec.rb index 00113f2b..fb03d856 100644 --- a/spec/migrator_builder_spec.rb +++ b/spec/migrator_builder_spec.rb @@ -10,8 +10,8 @@ module Migrations it "when properly configured" do with_client(test_config) do |client| builder = subject.new(client) - builder.read(->(_) { return true }, ->(_) { return true }) - builder.write(->(_) { return true }, ->(_) { return true }) + builder.read(->(_) { true }, ->(_) { true }) + builder.write(->(_) { true }, ->(_) { true }) migrator = builder.build expect(migrator).to be_a LaunchDarkly::Interfaces::Migrations::Migrator @@ -23,8 +23,8 @@ module Migrations with_client(test_config) do |client| builder = subject.new(client) builder.read_execution_order(order) - builder.read(->(_) { return true }, ->(_) { return true }) - builder.write(->(_) { return true }, ->(_) { return true }) + builder.read(->(_) { true }, ->(_) { true }) + builder.write(->(_) { true }, ->(_) { true }) migrator = builder.build expect(migrator).to be_a LaunchDarkly::Interfaces::Migrations::Migrator @@ -51,7 +51,7 @@ module Migrations it "if read config has wrong arity" do with_client(test_config) do |client| builder = subject.new(client) - builder.read(-> { return true }, -> { return true }) + builder.read(-> { true }, -> { true }) error = builder.build expect(error).to eq("read configuration not provided") @@ -61,7 +61,7 @@ module Migrations it "if read comparison has wrong arity" do with_client(test_config) do |client| builder = subject.new(client) - builder.read(->(_) { return true }, ->(_) { return true }, ->(_) { return true }) + builder.read(->(_) { true }, ->(_) { true }, ->(_) { true }) error = builder.build expect(error).to eq("read configuration not provided") @@ -71,7 +71,7 @@ module Migrations it "if write config isn't provided" do with_client(test_config) do |client| builder = subject.new(client) - builder.read(->(_) { return true }, ->(_) { return true }) + builder.read(->(_) { true }, ->(_) { true }) error = builder.build expect(error).to eq("write configuration not provided") @@ -81,8 +81,8 @@ module Migrations it "if write config has wrong arity" do with_client(test_config) do |client| builder = subject.new(client) - builder.read(->(_) { return true }, ->(_) { return true }) - builder.write(-> { return true }, -> { return true }) + builder.read(->(_) { true }, ->(_) { true }) + builder.write(-> { true }, -> { true }) error = builder.build expect(error).to eq("write configuration not provided")