From 8327d3394adcd441e94de88689dd009fe030587b Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Fri, 26 Jan 2024 15:02:52 -0500 Subject: [PATCH 1/4] ci: Automate release process with release please --- .github/actions/build-docs/action.yml | 9 ++++ .github/actions/build/action.yml | 9 ++++ .github/actions/publish/action.yml | 18 ++++++++ .github/workflows/ci.yml | 64 +++++++++++++++++++++++++++ .github/workflows/lint-pr-title.yml | 12 +++++ .github/workflows/manual-publish.yml | 38 ++++++++++++++++ .github/workflows/release-please.yml | 53 ++++++++++++++++++++++ .github/workflows/stale.yml | 10 +++++ .release-please-manifest.json | 3 ++ release-please-config.json | 11 +++++ 10 files changed, 227 insertions(+) create mode 100644 .github/actions/build-docs/action.yml create mode 100644 .github/actions/build/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 create mode 100644 .github/workflows/stale.yml create mode 100644 .release-please-manifest.json create mode 100644 release-please-config.json diff --git a/.github/actions/build-docs/action.yml b/.github/actions/build-docs/action.yml new file mode 100644 index 0000000..84e6a1b --- /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: make docs diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 0000000..5cf127c --- /dev/null +++ b/.github/actions/build/action.yml @@ -0,0 +1,9 @@ +name: Build distribution files +description: 'Build distribution files' + +runs: + using: composite + steps: + - name: Build distribution files + shell: bash + run: poetry build diff --git a/.github/actions/publish/action.yml b/.github/actions/publish/action.yml new file mode 100644 index 0000000..60910ad --- /dev/null +++ b/.github/actions/publish/action.yml @@ -0,0 +1,18 @@ +name: Publish Package +description: 'Publish the package to PyPI' +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 package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + if: ${{ inputs.dry_run == 'false' }} + with: + password: ${{inputs.token}} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2018bac --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +name: Quality control checks + +on: + push: + branches: [ main, 'feat/**' ] + paths-ignore: + - '**.md' # Do not need to run CI for markdown changes. + pull_request: + branches: [ main, 'feat/**' ] + paths-ignore: + - '**.md' + +jobs: + linux: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install poetry + run: pipx install poetry + + - uses: ./.github/actions/build + - uses: ./.github/actions/build-docs + + - name: Run tests + run: make test + + - name: Verify typehints + run: make lint + + windows: + runs-on: windows-latest + + defaults: + run: + shell: powershell + + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install requirements + run: | + pipx install poetry + poetry install --all-extras + + - name: Run tests + run: make test 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..2472724 --- /dev/null +++ b/.github/workflows/manual-publish.yml @@ -0,0 +1,38 @@ +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: actions/setup-python@v4 + with: + python-version: 3.8 + + - name: Install poetry + run: pipx install poetry + + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.0 + name: 'Get PyPI token' + with: + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + ssm_parameter_pairs: '/production/common/releasing/pypi/token = PYPI_AUTH_TOKEN' + + - uses: ./.github/actions/build + + - uses: ./.github/actions/publish + with: + token: ${{env.PYPI_AUTH_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..e081bc8 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,53 @@ +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: actions/setup-python@v4 + if: ${{ steps.release.outputs.releases_created }} + with: + python-version: 3.8 + + - name: Install poetry + if: ${{ steps.release.outputs.releases_created }} + run: pipx install poetry + + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.0 + if: ${{ steps.release.outputs.releases_created }} + name: 'Get PyPI token' + with: + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + ssm_parameter_pairs: '/production/common/releasing/pypi/token = PYPI_AUTH_TOKEN' + + - uses: ./.github/actions/build + 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.PYPI_AUTH_TOKEN}} + dry_run: false diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..14118d4 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,10 @@ +name: 'Close stale issues and PRs' +on: + workflow_dispatch: + schedule: + # Happen once per day at 1:30 AM + - cron: '30 1 * * *' + +jobs: + sdk-close-stale: + uses: launchdarkly/gh-actions/.github/workflows/sdk-stale.yml@main diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..466df71 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.1.0" +} diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..e06f67d --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,11 @@ +{ + "packages": { + ".": { + "release-type": "python", + "versioning": "default", + "include-v-in-tag": false, + "extra-files": ["docs/conf.py"], + "include-component-in-tag": false + } + } +} From 2e821065867bdc76d4651e3f2d0da5c099ae146b Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Thu, 1 Feb 2024 13:38:48 -0500 Subject: [PATCH 2/4] Mark as bug or feature --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index bf29b04..70e4f18 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -2,7 +2,7 @@ name: Bug report about: Create a report to help us improve title: '' -labels: '' +labels: 'bug' assignees: '' --- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 3f7d5bf..424628c 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -2,7 +2,7 @@ name: Feature request about: Suggest an idea for this project title: '' -labels: '' +labels: 'feature' assignees: '' --- From b59739b507e86cd2a84af4b8fac3d0cadbfadf46 Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Thu, 1 Feb 2024 13:40:01 -0500 Subject: [PATCH 3/4] Bump version of release secrets --- .github/workflows/manual-publish.yml | 2 +- .github/workflows/release-please.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/manual-publish.yml b/.github/workflows/manual-publish.yml index 2472724..b2a862d 100644 --- a/.github/workflows/manual-publish.yml +++ b/.github/workflows/manual-publish.yml @@ -24,7 +24,7 @@ jobs: - name: Install poetry run: pipx install poetry - - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.0 + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.2 name: 'Get PyPI token' with: aws_assume_role: ${{ vars.AWS_ROLE_ARN }} diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index e081bc8..74740be 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -33,7 +33,7 @@ jobs: if: ${{ steps.release.outputs.releases_created }} run: pipx install poetry - - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.0 + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.2 if: ${{ steps.release.outputs.releases_created }} name: 'Get PyPI token' with: From 40d8a76d8a47c035e3c082ca881231c8ae9b4f3a Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Fri, 2 Feb 2024 14:48:21 -0500 Subject: [PATCH 4/4] feat: Add support for shutdown method --- ld_openfeature/provider.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ld_openfeature/provider.py b/ld_openfeature/provider.py index d8f29d6..a3d67bf 100644 --- a/ld_openfeature/provider.py +++ b/ld_openfeature/provider.py @@ -19,6 +19,9 @@ def __init__(self, client: LDClient): self.__context_converter = EvaluationContextConverter() self.__details_converter = ResolutionDetailsConverter() + def shutdown(self): + self.__client.close() + def get_metadata(self) -> Metadata: return Metadata("launchdarkly-openfeature-server")