Skip to content

Commit aa1ab1d

Browse files
committed
updates
1 parent f865d63 commit aa1ab1d

File tree

5 files changed

+143
-17
lines changed

5 files changed

+143
-17
lines changed

.github/scripts/common.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,78 @@ patch_toml_package_name() {
3232
patch_pubspec_version() {
3333
uv run "$SCRIPTS/patch_pubspec_version.py" "$@"
3434
}
35+
36+
get_pyproject_version() {
37+
uv run "$SCRIPTS/get_pyproject_version.py" "$@"
38+
}
39+
40+
compute_build_versions() {
41+
local RUN_OFFSET="${RUN_OFFSET:-0}"
42+
: "${GITHUB_RUN_NUMBER:=0}"
43+
44+
local VERSION PKG_VER BUILD_VER PYPI_VER
45+
46+
_emit() {
47+
# $1..$4: VERSION PKG_VER BUILD_VER PYPI_VER
48+
export VERSION="$1" PKG_VER="$2" BUILD_VER="$3" PYPI_VER="$4"
49+
50+
{
51+
echo "VERSION=$VERSION"
52+
echo "PKG_VER=$PKG_VER"
53+
echo "BUILD_VER=$BUILD_VER"
54+
echo "PYPI_VER=$PYPI_VER"
55+
} >> "$GITHUB_ENV"
56+
57+
{
58+
echo "VERSION=$VERSION"
59+
echo "PKG_VER=$PKG_VER"
60+
echo "BUILD_VER=$BUILD_VER"
61+
echo "PYPI_VER=$PYPI_VER"
62+
} | tee -a "$GITHUB_OUTPUT"
63+
}
64+
65+
_next_dev_from() {
66+
# $1: base version (e.g., 1.2.3) → outputs "PKG_VER BUILD_VER PYPI_VER"
67+
local base="$1"
68+
local major minor
69+
major="${base%%.*}"
70+
minor="${base#*.}"; minor="${minor%%.*}"
71+
minor=$((minor + 1))
72+
local pkg="${major}.${minor}.0"
73+
local build="${pkg}+$((GITHUB_RUN_NUMBER + RUN_OFFSET))"
74+
local pypi="${build/+/.dev}"
75+
printf '%s %s %s' "$pkg" "$build" "$pypi"
76+
}
77+
78+
# ---------------- pyproject flow ----------------
79+
if [[ -n "${1-}" ]]; then
80+
local arg="$1" pyproject
81+
if [[ "$arg" == */* || "$arg" == *.toml ]]; then
82+
pyproject="$arg"
83+
else
84+
pyproject="${SDK_PYTHON}/packages/${arg}/pyproject.toml"
85+
fi
86+
87+
VERSION="$(uv run "$SCRIPTS/get_pyproject_version.py" "$pyproject")"
88+
read -r PKG_VER BUILD_VER PYPI_VER < <(_next_dev_from "$VERSION")
89+
_emit "$VERSION" "$PKG_VER" "$BUILD_VER" "$PYPI_VER"
90+
return
91+
fi
92+
93+
# ---------------- git/tag flow ----------------
94+
if [[ "${GITHUB_REF:-}" == refs/tags/* ]]; then
95+
VERSION="${GITHUB_REF#refs/tags/}"; VERSION="${VERSION#v}"
96+
PKG_VER="$VERSION"
97+
BUILD_VER="$PKG_VER"
98+
PYPI_VER="${BUILD_VER/+/.dev}"
99+
_emit "$VERSION" "$PKG_VER" "$BUILD_VER" "$PYPI_VER"
100+
return
101+
fi
102+
103+
# Untagged: base = latest tag (or 0.0.0), then next-dev
104+
local cv
105+
cv="$(git describe --abbrev=0 2>/dev/null || echo "v0.0.0")"
106+
VERSION="${cv#v}"
107+
read -r PKG_VER BUILD_VER PYPI_VER < <(_next_dev_from "$VERSION")
108+
_emit "$VERSION" "$PKG_VER" "$BUILD_VER" "$PYPI_VER"
109+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# /// script
2+
# dependencies = ["tomlkit"]
3+
# ///
4+
5+
"""
6+
Reads a pyproject.toml file and prints the project's version (according to PEP 621).
7+
8+
Usage:
9+
uv run get_pyproject_version.py <pyproject.toml>
10+
11+
Exit codes:
12+
0 success
13+
1 usage error or file missing or version not found
14+
"""
15+
16+
import sys
17+
from pathlib import Path
18+
19+
import tomlkit
20+
21+
22+
def get_version(toml_data) -> str:
23+
v = toml_data["project"]["version"]
24+
return v.strip()
25+
26+
27+
def main() -> None:
28+
if len(sys.argv) != 2:
29+
print(
30+
"Usage: uv run get_pyproject_version.py <pyproject.toml>", file=sys.stderr
31+
)
32+
sys.exit(1)
33+
34+
toml_path = Path(sys.argv[1]).resolve()
35+
if not toml_path.exists():
36+
print(f"Error: File not found: {toml_path}", file=sys.stderr)
37+
sys.exit(1)
38+
39+
with toml_path.open(encoding="utf-8") as f:
40+
data = tomlkit.parse(f.read())
41+
42+
version = get_version(data)
43+
44+
# Print only the version, suitable for command substitution
45+
print(version)
46+
47+
48+
if __name__ == "__main__":
49+
main()

.github/scripts/update_build_version.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,16 @@ fi
6262
# -------------------------------------------------------------
6363
export PYPI_VER="${BUILD_VER/+/.dev}"
6464

65-
# Print values for debugging in logs
66-
echo "PKG_VER=$PKG_VER"
67-
echo "BUILD_VER=$BUILD_VER"
68-
echo "PYPI_VER=$PYPI_VER"
69-
7065
# Export values as environment variables
71-
echo "PKG_VER=$PKG_VER" >> $GITHUB_ENV
72-
echo "BUILD_VER=$BUILD_VER" >> $GITHUB_ENV
73-
echo "PYPI_VER=$PYPI_VER" >> $GITHUB_ENV
66+
{
67+
echo "PKG_VER=$PKG_VER"
68+
echo "BUILD_VER=$BUILD_VER"
69+
echo "PYPI_VER=$PYPI_VER"
70+
} >> "$GITHUB_ENV"
7471

7572
# set GitHub Actions output variables for use in other jobs
7673
{
7774
echo "PKG_VER=$PKG_VER"
7875
echo "BUILD_VER=$BUILD_VER"
7976
echo "PYPI_VER=$PYPI_VER"
80-
} >> $GITHUB_OUTPUT
77+
} | tee -a "$GITHUB_OUTPUT"

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ jobs:
9999

100100
- name: Compute versions
101101
id: versions
102-
run: source "${SCRIPTS}/update_build_version.sh"
102+
run: |
103+
source "$SCRIPTS/common.sh"
104+
compute_build_versions
103105
104106
- name: Setup Flutter
105107
uses: kuhnroyal/flutter-fvm-config-action/setup@v3
@@ -128,6 +130,7 @@ jobs:
128130
printf %s "$PUB_DEV_TOKEN" | base64 --decode > "$HOME/.config/dart/pub-credentials.json"
129131
130132
# patch pubspec for release
133+
source "$SCRIPTS/common.sh"
131134
patch_pubspec_version ./pubspec.yaml "$PKG_VER"
132135
133136
dart pub publish --force

.github/workflows/extensions.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ env:
2020
SDK_PYTHON: "${{ github.workspace }}/sdk/python"
2121
SCRIPTS: "${{ github.workspace }}/.github/scripts"
2222
UV_PYTHON: "3.12"
23-
PKG_VER: "0.2.0"
24-
BUILD_VER: "0.2.0+${{ github.run_number }}"
25-
PYPI_VER: "0.2.0.dev${{ github.run_number }}"
23+
# PKG_VER: "0.2.0"
24+
# BUILD_VER: "0.2.0+${{ github.run_number }}"
25+
# PYPI_VER: "0.2.0.dev${{ github.run_number }}"
2626

2727
jobs:
2828
build:
@@ -32,9 +32,6 @@ jobs:
3232
steps:
3333
- name: Checkout repository
3434
uses: actions/checkout@v4
35-
with:
36-
fetch-depth: 0
37-
fetch-tags: true
3835

3936
- name: Setup uv
4037
uses: astral-sh/setup-uv@v6
@@ -54,11 +51,16 @@ jobs:
5451
cache: true
5552

5653
- name: Publish flet-ads
54+
# if:
5755
working-directory: ${{ env.SDK_PYTHON }}/packages/flet-ads
5856
run: |
59-
uv run "${SCRIPTS}/patch_pubspec_version.py" "src/flutter/flet_ads/pubspec.yaml" "$PKG_VER"
57+
source "$SCRIPTS/common.sh"
58+
pushd "src/flutter/flet_ads"
59+
patch_pubspec_version "pubspec.yaml" "$PKG_VER"
6060
dart pub get && dart analyze
6161
62+
popd
63+
compute_build_versions flet-ads
6264
uv version "$PYPI_VER"
6365
uv build
6466
ls -laR "${SDK_PYTHON}/dist"

0 commit comments

Comments
 (0)