Skip to content

Commit 79b7cbf

Browse files
khvn26emyller
andauthored
ci: Add known SDK version workflow (#6032)
Co-authored-by: Evandro Myller <22429+emyller@users.noreply.github.com>
1 parent e7182a9 commit 79b7cbf

3 files changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: API Run Makefile Target
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
target:
7+
description: The Makefile target to run (e.g. 'add-known-sdk-version')
8+
required: true
9+
opts:
10+
description: Options to pass (e.g. '--sdk flagsmith-python-sdk --version 1.2.3')
11+
required: false
12+
default: ""
13+
pr-title:
14+
description: The title to use for the PR
15+
required: true
16+
pr-notes:
17+
description: Additional notes to add to the PR body
18+
required: false
19+
default: ""
20+
21+
permissions:
22+
contents: write
23+
pull-requests: write
24+
25+
defaults:
26+
run:
27+
working-directory: api
28+
29+
jobs:
30+
add-sdk-version:
31+
runs-on: depot-ubuntu-latest
32+
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- uses: actions/setup-python@v5
37+
with:
38+
python-version: 3.11
39+
cache: "poetry"
40+
41+
- name: Install Dependencies
42+
run: make install-packages
43+
44+
- name: Run `make ${{ inputs.target }} opts=${{ inputs.opts }}`
45+
env:
46+
opts: ${{ inputs.opts }}
47+
run: make ${{ inputs.target }}
48+
49+
- name: Create Pull Request
50+
uses: peter-evans/create-pull-request@v5
51+
with:
52+
branch: chore/make-${{ inputs.target }}-${{ github.run_id }}
53+
title: ${{ inputs.pr-title }}
54+
body: |
55+
Results of `make ${{ inputs.target }} opts="${{ inputs.opts }}"` ran on commit ${{ github.sha }}.
56+
57+
${{ inputs.pr-notes }}

api/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,7 @@ integrate-private-tests:
152152
.PHONY: generate-docs
153153
generate-docs:
154154
poetry run flagsmith docgen metrics > ../docs/docs/system-administration/metrics.md
155+
156+
.PHONY: add-known-sdk-version
157+
add-known-sdk-version:
158+
poetry run python scripts/add-known-sdk-version.py $(opts)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import argparse
2+
import re
3+
from pathlib import Path
4+
5+
MODULE_PATH = "app_analytics/constants.py"
6+
VERSIONS_CONSTANT_NAME = "SDK_USER_AGENT_KNOWN_VERSIONS"
7+
8+
9+
def add_version(sdk_name: str, new_version: str) -> None:
10+
"""Add a new version to known versions constants"""
11+
contents = Path(MODULE_PATH).read_text()
12+
13+
# Add SDK version
14+
contents = re.sub(
15+
pattern=rf"""
16+
^ # Expect to have definition at module-level
17+
(?P<constant_def>{VERSIONS_CONSTANT_NAME}[^=]*=\s*\{{)
18+
(?P<prior_sdks>[^\}}]+)
19+
(?P<sdk_def>"{sdk_name}"\s*:\s*\[)
20+
(?P<sdk_versions>[^\]]*)
21+
(?P<latest_version>"(?:unknown|\d[^"]+)"),?
22+
""",
23+
repl=(
24+
r"\g<constant_def>\g<prior_sdks>\g<sdk_def>\g<sdk_versions>\g<latest_version>"
25+
f',\n "{new_version}",\n '
26+
),
27+
string=contents,
28+
count=1,
29+
flags=re.MULTILINE | re.VERBOSE,
30+
)
31+
32+
Path(MODULE_PATH).write_text(contents)
33+
34+
35+
def main() -> None:
36+
parser = argparse.ArgumentParser(
37+
description="Add a known SDK version to an existing constants entry."
38+
)
39+
parser.add_argument(
40+
"--sdk",
41+
type=str,
42+
required=True,
43+
help="The SDK name, e.g. flagsmith-js-sdk",
44+
)
45+
parser.add_argument(
46+
"--version",
47+
type=str,
48+
required=True,
49+
help="The SDK version, e.g. 9.4.0",
50+
)
51+
args = parser.parse_args()
52+
add_version(args.sdk, args.version)
53+
54+
55+
if __name__ == "__main__":
56+
main()

0 commit comments

Comments
 (0)