From 2fe6e0d79bbdd5ffcdafa904f543c02fe79707cf Mon Sep 17 00:00:00 2001 From: "Matthew M. Keeler" Date: Wed, 15 Nov 2023 09:49:51 -0500 Subject: [PATCH] build: Switch to release please and github actions (#62) --- .circleci/config.yml | 58 --------------------------- .github/actions/build-docs/action.yml | 9 +++++ .github/actions/ci/action.yml | 29 ++++++++++++++ .github/actions/publish/action.yml | 17 ++++++++ .github/workflows/ci.yml | 27 +++++++++++++ .github/workflows/lint-pr-title.yml | 12 ++++++ .github/workflows/manual-publish.yml | 37 +++++++++++++++++ .github/workflows/release-please.yml | 50 +++++++++++++++++++++++ .ldrelease/build.sh | 6 --- .ldrelease/config.yml | 9 ----- .ldrelease/publish-dry-run.sh | 6 --- .ldrelease/publish.sh | 8 ---- .ldrelease/update-version.sh | 5 --- .release-please-manifest.json | 3 ++ release-please-config.json | 10 +++++ 15 files changed, 194 insertions(+), 92 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/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.yml create mode 100644 .github/workflows/release-please.yml delete mode 100755 .ldrelease/build.sh delete mode 100644 .ldrelease/config.yml delete mode 100755 .ldrelease/publish-dry-run.sh delete mode 100755 .ldrelease/publish.sh delete mode 100755 .ldrelease/update-version.sh 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 78c461a..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,58 +0,0 @@ -version: 2 - -jobs: - build: - docker: - - image: cimg/rust:1.67.0 - steps: - - checkout - - run: - name: Check Version - command: | - cargo --version - rustc --version - - run: - name: Check consistent formatting - command: cargo fmt && git diff --exit-code - - run: cargo build -p eventsource-client - - run: cargo test --all-features -p eventsource-client - - run: cargo doc --no-deps -p eventsource-client - - run: cargo clippy --all-features -p eventsource-client -- -D warnings - - store_artifacts: - path: target/doc - destination: doc - - generate-coverage: - docker: - - image: cimg/rust:1.68.0 - steps: - - checkout - - run: cargo build - - run: - name: Gather Coverage - command: ./coverage.sh --html - - store_artifacts: - name: Upload Coverage - path: target/llvm-cov/html - destination: coverage - - contract-tests: - docker: - - image: cimg/rust:1.68.0 - steps: - - checkout - - run: cargo build - - run: - command: make start-contract-test-service - background: true - - run: - name: run contract tests - command: make run-contract-tests - -workflows: - version: 2 - build: - jobs: - - build - - contract-tests - - generate-coverage diff --git a/.github/actions/build-docs/action.yml b/.github/actions/build-docs/action.yml new file mode 100644 index 0000000..9d568d4 --- /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: cargo doc --no-deps -p eventsource-client diff --git a/.github/actions/ci/action.yml b/.github/actions/ci/action.yml new file mode 100644 index 0000000..e45beab --- /dev/null +++ b/.github/actions/ci/action.yml @@ -0,0 +1,29 @@ +name: CI Workflow +description: 'Shared CI workflow.' + +runs: + using: composite + steps: + - name: Check formatting + shell: bash + run: cargo fmt --check + + - name: Run tests + shell: bash + run: cargo test --all-features -p eventsource-client + + - name: Run clippy checks + shell: bash + run: cargo clippy --all-features -p eventsource-client -- -D warnings + + - name: Build contract tests + shell: bash + run: make build-contract-tests + + - name: Start contract test service + shell: bash + run: make start-contract-test-service-bg + + - name: Run contract tests + shell: bash + run: make run-contract-tests diff --git a/.github/actions/publish/action.yml b/.github/actions/publish/action.yml new file mode 100644 index 0000000..7b9e338 --- /dev/null +++ b/.github/actions/publish/action.yml @@ -0,0 +1,17 @@ +name: Publish Package +description: 'Publish the package to crates.io' +inputs: + token: + description: 'Token to use for publishing.' + required: true + dry_run: + description: 'Is this a dry run. If so no package will be published.' + required: true + +runs: + using: composite + steps: + - name: Publish Library + shell: bash + if: ${{ inputs.dry_run == 'false' }} + run: CARGO_REGISTRY_TOKEN="${{inputs.token}}" cargo publish -p eventsource-client diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bbba105 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +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: + ci-build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # If you only need the current version keep this. + + - name: Setup rust tooling + run: | + rustup override set 1.68 + rustup component add rustfmt clippy + + - uses: ./.github/actions/ci + - uses: ./.github/actions/build-docs diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml new file mode 100644 index 0000000..4ba79c1 --- /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.yml b/.github/workflows/manual-publish.yml new file mode 100644 index 0000000..b4116e0 --- /dev/null +++ b/.github/workflows/manual-publish.yml @@ -0,0 +1,37 @@ +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 + + - name: Setup rust tooling + run: | + rustup override set 1.68 + rustup component add rustfmt + + - uses: ./.github/actions/ci + - uses: ./.github/actions/build-docs + + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.0 + name: 'Get crates.io token' + with: + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + ssm_parameter_pairs: '/production/common/releasing/cratesio/api_token = CARGO_REGISTRY_TOKEN' + + - uses: ./.github/actions/publish + with: + token: ${{env.CARGO_REGISTRY_TOKEN}} + dry_run: ${{ inputs.dry_run }} diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..fd9ff74 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,50 @@ +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. + + - name: Setup rust tooling + if: ${{ steps.release.outputs.releases_created }} + run: | + rustup override set 1.68 + rustup component add rustfmt + + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.0 + name: 'Get crates.io token' + with: + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + ssm_parameter_pairs: '/production/common/releasing/cratesio/api_token = CARGO_REGISTRY_TOKEN' + + - uses: ./.github/actions/ci + if: ${{ steps.release.outputs.releases_created }} + + - uses: ./.github/actions/build-docs + if: ${{ steps.release.outputs.releases_created }} + + - uses: ./.github/actions/publish + if: ${{ steps.release.outputs.releases_created }} + with: + token: ${{env.CARGO_REGISTRY_TOKEN}} + dry_run: false diff --git a/.ldrelease/build.sh b/.ldrelease/build.sh deleted file mode 100755 index d7a6616..0000000 --- a/.ldrelease/build.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -set -ue - -cd eventsource-client -cargo package diff --git a/.ldrelease/config.yml b/.ldrelease/config.yml deleted file mode 100644 index b6cd6b9..0000000 --- a/.ldrelease/config.yml +++ /dev/null @@ -1,9 +0,0 @@ -version: 2 - -publications: - - url: https://docs.rs/eventsource-client - description: crates.io - -jobs: - - template: - name: rust diff --git a/.ldrelease/publish-dry-run.sh b/.ldrelease/publish-dry-run.sh deleted file mode 100755 index 8547e59..0000000 --- a/.ldrelease/publish-dry-run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -set -ue - -echo "DRY RUN: not publishing to crates.io, only copying crate" -cp ./target/package/*.crate "${LD_RELEASE_ARTIFACTS_DIR}" diff --git a/.ldrelease/publish.sh b/.ldrelease/publish.sh deleted file mode 100755 index 19ebcf9..0000000 --- a/.ldrelease/publish.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -ue - -export CARGO_REGISTRY_TOKEN="$(cat "${LD_RELEASE_SECRETS_DIR}/rust_cratesio_api_token")" - -cd eventsource-client -cargo publish diff --git a/.ldrelease/update-version.sh b/.ldrelease/update-version.sh deleted file mode 100755 index 5b45f32..0000000 --- a/.ldrelease/update-version.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -set -ue - -sed -i "/^version\b/c version = \"${LD_RELEASE_VERSION}\"" ./eventsource-client/Cargo.toml diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..2cdab9b --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + "eventsource-client": "0.11.0" +} diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..404c2ab --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,10 @@ +{ + "plugins": ["cargo-workspace"], + "release-type": "rust", + "bump-minor-pre-major": true, + "versioning": "default", + "include-component-in-tag": false, + "packages": { + "eventsource-client": {} + } +}