Skip to content

Commit 5198817

Browse files
chore: Add release-please support for python. (#127)
## Summary Adds release-please workflows and uses it to release python. Adds a CI check for PR titles to ensure usage of conventional commits. ## How did you test this change? <!-- Frontend - Leave a screencast or a screenshot to visually describe the changes. --> ## Are there any deployment considerations? <!-- Backend - Do we need to consider migrations or backfilling data? --> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 082cbc3 commit 5198817

File tree

16 files changed

+333
-12
lines changed

16 files changed

+333
-12
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Lint PR title
2+
3+
permissions:
4+
contents: read
5+
pull-requests: read
6+
7+
on:
8+
pull_request_target:
9+
types:
10+
- opened
11+
- edited
12+
- synchronize
13+
14+
jobs:
15+
lint-pr-title:
16+
uses: launchdarkly/gh-actions/.github/workflows/lint-pr-title.yml@main

.github/workflows/manual-publish-docs.yml

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
options:
1010
- sdk/highlight-run
1111
- 'sdk/@launchdarkly/observability-node'
12+
- 'sdk/@launchdarkly/observability-python'
1213
workflow_call:
1314
inputs:
1415
workspace_path:
@@ -27,26 +28,72 @@ jobs:
2728
uses: actions/checkout@v4
2829
- run: git submodule update --init --recursive
2930

31+
- name: Check if JS package
32+
id: check-js-package
33+
run: |
34+
if ./scripts/is-js-package.sh ${{ inputs.workspace_path }}; then
35+
echo "is_js_package=true" >> $GITHUB_OUTPUT
36+
else
37+
echo "is_js_package=false" >> $GITHUB_OUTPUT
38+
fi
39+
40+
- name: Check if python package
41+
id: check-python-package
42+
run: |
43+
if ./scripts/is-python-package.sh ${{ inputs.workspace_path }}; then
44+
echo "is_python_package=true" >> $GITHUB_OUTPUT
45+
else
46+
echo "is_python_package=false" >> $GITHUB_OUTPUT
47+
fi
48+
3049
- name: Setup Node.js environment
50+
if: ${{ steps.check-js-package.outputs.is_js_package == 'true' }}
3151
uses: actions/setup-node@v4
3252
with:
3353
node-version: lts/*
3454
cache: 'yarn'
3555

3656
- name: Install js dependencies
57+
if: ${{ steps.check-js-package.outputs.is_js_package == 'true' }}
3758
run: yarn install --mode=skip-build
3859
env:
3960
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
4061

4162
- name: 'Set WORKSPACE_NAME variable'
63+
if: ${{ steps.check-js-package.outputs.is_js_package == 'true' }}
4264
shell: bash
4365
run: |
4466
WORKSPACE_NAME=$(./scripts/package-name.sh ${{ inputs.workspace_path }})
4567
echo "WORKSPACE_NAME=$WORKSPACE_NAME" >> $GITHUB_ENV
4668
47-
- name: Build docs
69+
- name: Build JS package docs
70+
if: ${{ steps.check-js-package.outputs.is_js_package == 'true' }}
4871
run: yarn docs --filter ${{ env.WORKSPACE_NAME }}
4972

73+
- uses: actions/setup-python@v5
74+
if: ${{ steps.check-python-package.outputs.is_python_package == 'true' }}
75+
with:
76+
python-version: '3.10'
77+
78+
- name: Install poetry
79+
if: ${{ steps.check-python-package.outputs.is_python_package == 'true' }}
80+
uses: abatilo/actions-poetry@7b6d33e44b4f08d7021a1dee3c044e9c253d6439
81+
82+
- name: Make Install
83+
# Assume non-js projects will use a Makefile to install dependencies.
84+
# Or an empty install target.
85+
if: ${{ steps.check-js-package.outputs.is_js_package == 'false' }}
86+
run: |
87+
cd ${{ inputs.workspace_path }}
88+
make install
89+
90+
- name: Build Makefile Docs
91+
# Assume non-js projects will use a Makefile to build docs.
92+
if: ${{ steps.check-js-package.outputs.is_js_package == 'false' }}
93+
run: |
94+
cd ${{ inputs.workspace_path }}
95+
make docs
96+
5097
- name: Publish Highlight.run as Observability Plugin
5198
if: inputs.workspace_path == 'sdk/highlight-run'
5299
uses: launchdarkly/gh-actions/actions/[email protected]
@@ -55,7 +102,9 @@ jobs:
55102
output_path: packages/@launchdarkly/observability
56103
github_token: ${{ secrets.GITHUB_TOKEN }}
57104

58-
- name: Publish other JS packages
105+
- name: Publish Docs
106+
# This is generalized to work with any package, but we don't use it for highlight-run,
107+
# because we publish its docs to a different path.
59108
if: inputs.workspace_path != 'sdk/highlight-run'
60109
uses: launchdarkly/gh-actions/actions/[email protected]
61110
with:

.github/workflows/python-plugin.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ jobs:
2727
- uses: actions/checkout@v4
2828
with:
2929
token: ${{ secrets.GITHUB_TOKEN }}
30-
- name: Install poetry
31-
run: pipx install poetry
32-
- uses: actions/setup-python@v4
30+
31+
- uses: actions/setup-python@v5
3332
with:
34-
python-version: '3.12'
35-
cache: 'poetry'
33+
python-version: '3.10'
34+
35+
- name: Install poetry
36+
uses: abatilo/actions-poetry@7b6d33e44b4f08d7021a1dee3c044e9c253d6439
37+
3638
- run: make install
3739
- name: Lint
3840
run: make lint
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Run Release Please
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
release-package:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write # Contents and pull-requests are for release-please to make releases.
12+
pull-requests: write
13+
outputs:
14+
python-plugin-released: ${{ steps.release.outputs['sdk/@launchdarkly/observability-python--release_created'] }}
15+
python-plugin-tag-name: ${{ steps.release.outputs['sdk/@launchdarkly/observability-python--tag_name'] }}
16+
steps:
17+
- uses: googleapis/release-please-action@a02a34c4d625f9be7cb89156071d8567266a2445
18+
id: release
19+
20+
- uses: actions/checkout@v4
21+
if: ${{ steps.release.outputs.releases_created == 'true' }}
22+
with:
23+
fetch-depth: 0 # If you only need the current version keep this.
24+
25+
release-python-plugin:
26+
runs-on: ubuntu-latest
27+
permissions:
28+
id-token: write # Used for publishing secrets and documentation.
29+
needs: ['release-package']
30+
if: ${{ needs.release-package.outputs.python-plugin-released == 'true' }}
31+
outputs:
32+
package-hashes: ${{ steps.package-hashes.outputs.package-hashes }}
33+
steps:
34+
- uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.10'
37+
38+
- name: Install poetry
39+
40+
uses: abatilo/actions-poetry@7b6d33e44b4f08d7021a1dee3c044e9c253d6439
41+
42+
- uses: launchdarkly/gh-actions/actions/[email protected]
43+
name: 'Get PyPI token'
44+
with:
45+
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
46+
ssm_parameter_pairs: '/production/common/releasing/pypi/token = PYPI_AUTH_TOKEN'
47+
48+
- name: Build Python plugin
49+
run: |
50+
cd sdk/@launchdarkly/observability-python
51+
make build
52+
53+
- name: Hash build files for provenance
54+
id: package-hashes
55+
shell: bash
56+
working-directory: ./sdk/@launchdarkly/observability-python/dist
57+
run: |
58+
echo "package-hashes=$(sha256sum * | base64 -w0)" >> "$GITHUB_OUTPUT"
59+
60+
- name: Publish package distributions to PyPI
61+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc
62+
with:
63+
packages-dir: ./sdk/@launchdarkly/observability-python/dist
64+
password: ${{env.PYPI_AUTH_TOKEN}}
65+
66+
release-python-docs:
67+
runs-on: ubuntu-latest
68+
permissions:
69+
contents: write
70+
needs: ['release-python-plugin']
71+
steps:
72+
- name: Build and Publish Docs
73+
uses: ./.github/workflows/manual-publish-docs.yml
74+
with:
75+
workspace_path: sdk/@launchdarkly/observability-python
76+
77+
release-provenance:
78+
needs: ['release-package', 'release-python-plugin']
79+
if: ${{ needs.release-package.outputs.python-plugin-released == 'true' }}
80+
permissions:
81+
actions: read
82+
id-token: write
83+
contents: write
84+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
85+
with:
86+
base64-subjects: '${{ needs.release-python-plugin.outputs.package-hashes }}'
87+
upload-assets: true
88+
upload-tag-name: ${{ needs.release-package.outputs.python-plugin-tag-name }}

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"sdk/@launchdarkly/observability-python": "0.0.0"
3+
}

release-please.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"packages": {
3+
"sdk/@launchdarkly/observability-python": {
4+
"package-name": "launchdarkly-observability-python",
5+
"release-type": "python",
6+
"versioning": "default",
7+
"include-v-in-tag": false,
8+
"extra-files": ["PROVENANCE.md"],
9+
"include-component-in-tag": true,
10+
"release-as": "0.1.0"
11+
}
12+
}
13+
}

scripts/is-js-package.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# Check if the specified directory contains a package.json file.
4+
# ./scripts/is-js-package.sh packages/sdk/server-node
5+
# Returns 0 (success) if package.json exists, 1 (failure) if it doesn't.
6+
7+
set -e
8+
9+
if [ -f "$1/package.json" ]; then
10+
exit 0
11+
else
12+
exit 1
13+
fi

scripts/is-python-package.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# Check if the specified directory contains a pyproject.toml file.
4+
# ./scripts/is-python-package.sh packages/sdk/python
5+
# Returns 0 (success) if pyproject.toml exists, 1 (failure) if it doesn't.
6+
7+
set -e
8+
9+
if [ -f "$1/pyproject.toml" ]; then
10+
exit 0
11+
else
12+
exit 1
13+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.coverage
22
coverage.xml
33
.coveragerc
4+
docs/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Change Log
2+
3+
All notable changes to the LaunchDarkly Python Observability will be documented in this file. This project adheres to Semantic Versioning.

0 commit comments

Comments
 (0)