Skip to content

Commit ebc4274

Browse files
committed
feat: add GENERATE_STARTERCODE_VERSION environment variable for version resolution in scripts
1 parent a2b3094 commit ebc4274

4 files changed

Lines changed: 34 additions & 19 deletions

File tree

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Die Skripte koennen aus dem neuesten GitHub Release-Tag geladen werden (statt vo
4242

4343
```bash
4444
LATEST_TAG=$(curl -fsSL https://api.github.com/repos/obcode/generate_startercode/releases/latest | python3 -c "import json,sys; print(json.load(sys.stdin)['tag_name'])")
45+
export GENERATE_STARTERCODE_VERSION="${LATEST_TAG#v}"
4546

4647
curl -fsSL "https://raw.githubusercontent.com/obcode/generate_startercode/${LATEST_TAG}/transform.py" -o /tmp/transform.py
4748
curl -fsSL "https://raw.githubusercontent.com/obcode/generate_startercode/${LATEST_TAG}/sync_issue.py" -o /tmp/sync_issue.py
@@ -59,11 +60,12 @@ sync-issue:
5960
stage: sync
6061
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/library/python:3.12-bookworm
6162
script:
63+
- set -eu
6264
- pip install "python-gitlab[graphql]" --quiet
63-
- |
64-
set -eu
65-
LATEST_TAG=$(curl -fsSL https://api.github.com/repos/obcode/generate_startercode/releases/latest | python3 -c "import json,sys; print(json.load(sys.stdin)['tag_name'])")
66-
curl -fsSL "https://raw.githubusercontent.com/obcode/generate_startercode/${LATEST_TAG}/sync_issue.py" -o /tmp/sync_issue.py
65+
- LATEST_TAG=$(curl -fsSL https://api.github.com/repos/obcode/generate_startercode/releases/latest | python3 -c "import json,sys; print(json.load(sys.stdin)['tag_name'])")
66+
- export GENERATE_STARTERCODE_VERSION="${LATEST_TAG#v}"
67+
- echo "[sync-issue] Using release ${LATEST_TAG}"
68+
- curl -fsSL "https://raw.githubusercontent.com/obcode/generate_startercode/${LATEST_TAG}/sync_issue.py" -o /tmp/sync_issue.py
6769
- python /tmp/sync_issue.py
6870
rules:
6971
- if: '$CI_COMMIT_BRANCH == "main"'
@@ -77,22 +79,20 @@ publish-branches:
7779
stage: publish
7880
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/library/python:3.12-bookworm
7981
before_script:
82+
- set -eu
8083
- pip install pyyaml --quiet
8184
- git config user.email "ci@gitlab"
8285
- git config user.name "CI"
8386
- git remote set-url origin "https://oauth2:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
8487
script:
85-
- |
86-
set -eu
87-
echo "[publish-branches] Download transform.py from latest release"
88-
LATEST_TAG=$(curl -fsSL https://api.github.com/repos/obcode/generate_startercode/releases/latest | python3 -c "import json,sys; print(json.load(sys.stdin)['tag_name'])")
89-
curl -fsSL "https://raw.githubusercontent.com/obcode/generate_startercode/${LATEST_TAG}/transform.py" -o /tmp/transform.py
90-
91-
echo "[publish-branches] Run target=solution"
92-
python /tmp/transform.py --target solution --repo-root "$CI_PROJECT_DIR" --config .gitlab/ci/config.yml --no-skip-ci
93-
94-
echo "[publish-branches] Run target=startercode"
95-
python /tmp/transform.py --target startercode --repo-root "$CI_PROJECT_DIR" --config .gitlab/ci/config.yml --no-skip-ci
88+
- LATEST_TAG=$(curl -fsSL https://api.github.com/repos/obcode/generate_startercode/releases/latest | python3 -c "import json,sys; print(json.load(sys.stdin)['tag_name'])")
89+
- export GENERATE_STARTERCODE_VERSION="${LATEST_TAG#v}"
90+
- echo "[publish-branches] Download transform.py from release ${LATEST_TAG}"
91+
- curl -fsSL "https://raw.githubusercontent.com/obcode/generate_startercode/${LATEST_TAG}/transform.py" -o /tmp/transform.py
92+
- echo "[publish-branches] Run target=solution"
93+
- python /tmp/transform.py --target solution --repo-root "$CI_PROJECT_DIR" --config .gitlab/ci/config.yml --no-skip-ci
94+
- echo "[publish-branches] Run target=startercode"
95+
- python /tmp/transform.py --target startercode --repo-root "$CI_PROJECT_DIR" --config .gitlab/ci/config.yml --no-skip-ci
9696
rules:
9797
- if: '$CI_COMMIT_BRANCH == "main"'
9898
changes:
@@ -104,7 +104,7 @@ publish-branches:
104104
- .gitlab-ci.yml
105105
```
106106
107-
Hinweis: Dafuer muss mindestens ein GitHub Release vorhanden sein. Falls noch kein Release existiert, initial einmalig gegen einen festen Tag laden (zum Beispiel v0.1.0) oder kurzzeitig gegen main.
107+
Hinweis: Dafuer muss mindestens ein GitHub Release vorhanden sein. Die zusaetzliche Umgebungsvariable GENERATE_STARTERCODE_VERSION sorgt dafuer, dass das heruntergeladene Einzel-Skript auch ohne lokales pyproject die richtige Release-Version anzeigt. Falls noch kein Release existiert, initial einmalig gegen einen festen Tag laden (zum Beispiel v1.0.0) oder kurzzeitig gegen main.
108108
109109
## GitHub Actions
110110

sync_issue.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@
1717
import gitlab # type: ignore
1818

1919

20+
VERSION_ENV_VAR = "GENERATE_STARTERCODE_VERSION"
21+
22+
2023
def _resolve_version() -> str:
21-
"""Liest die Version aus installierten Metadaten oder pyproject.toml."""
24+
"""Liest die Version aus CI, Paket-Metadaten oder pyproject.toml."""
25+
env_version = os.environ.get(VERSION_ENV_VAR, "").strip()
26+
if env_version:
27+
return env_version.removeprefix("v")
28+
2229
try:
2330
return pkg_version("generate-startercode")
2431
except PackageNotFoundError:

transform.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"""
2626

2727
import argparse
28+
import os
2829
import re
2930
import shutil
3031
import subprocess
@@ -34,8 +35,15 @@
3435
from pathlib import Path
3536

3637

38+
VERSION_ENV_VAR = "GENERATE_STARTERCODE_VERSION"
39+
40+
3741
def _resolve_version() -> str:
38-
"""Liest die Version aus installierten Metadaten oder pyproject.toml."""
42+
"""Liest die Version aus CI, Paket-Metadaten oder pyproject.toml."""
43+
env_version = os.environ.get(VERSION_ENV_VAR, "").strip()
44+
if env_version:
45+
return env_version.removeprefix("v")
46+
3947
try:
4048
return pkg_version("generate-startercode")
4149
except PackageNotFoundError:

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)