From 98ee62294d598298c133fa0635528436f2c1519e Mon Sep 17 00:00:00 2001 From: tristan Date: Fri, 6 Feb 2026 10:25:54 +0100 Subject: [PATCH] =?UTF-8?q?feat=20:=20ajout=20d'un=20num=C3=A9ro=20de=20ve?= =?UTF-8?q?rsion=20automatique=20via=20la=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/auto-tag-develop.yml | 57 +++++++++++++++++++-------- .idea/workspace.xml | 27 +++++++------ config/services.yaml | 3 ++ config/version.yaml | 2 + src/Dto/AppVersion.php | 26 ++++++++++++ src/State/AppVersionProvider.php | 26 ++++++++++++ 6 files changed, 111 insertions(+), 30 deletions(-) create mode 100644 config/version.yaml create mode 100644 src/Dto/AppVersion.php create mode 100644 src/State/AppVersionProvider.php diff --git a/.gitea/workflows/auto-tag-develop.yml b/.gitea/workflows/auto-tag-develop.yml index 5bb4ac5..4c4a631 100644 --- a/.gitea/workflows/auto-tag-develop.yml +++ b/.gitea/workflows/auto-tag-develop.yml @@ -16,30 +16,53 @@ jobs: token: ${{ secrets.RELEASE_TOKEN }} persist-credentials: true - - name: Create next tag v0.0.X + - name: Create next tag from config/version.yaml shell: bash run: | set -euo pipefail - # Skip if current commit already has a v0.0.* tag - if git tag --points-at HEAD | grep -qE '^v0\.0\.'; then + # Skip if current commit already has a vX.Y.Z tag + if git tag --points-at HEAD | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then echo "Tag already exists on this commit. Skipping." exit 0 fi - last_tag="$(git tag -l 'v0.0.*' --sort=-v:refname | head -n1 || true)" - if [ -z "$last_tag" ]; then - next_tag="v0.0.1" - else - patch="${last_tag##v0.0.}" - if ! [[ "$patch" =~ ^[0-9]+$ ]]; then - echo "Unexpected tag format: $last_tag" >&2 - exit 1 - fi - next_tag="v0.0.$((patch + 1))" + changed_version=false + if git diff --name-only "${{ github.event.before }}" "${{ github.sha }}" | grep -q '^config/version\.yaml$'; then + changed_version=true fi - git config user.name "gitea-actions" - git config user.email "gitea-actions@local" - git tag "$next_tag" - git push origin "$next_tag" + read_version() { + awk -F': *' '/app\.version:/{print $2}' config/version.yaml | tr -d '[:space:]' | tr -d "'\"" + } + + if $changed_version; then + version="$(read_version)" + if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Invalid version in version.yaml: $version" >&2 + exit 1 + fi + else + last_tag="$(git tag -l 'v*' --sort=-v:refname | head -n1 || true)" + if [ -z "$last_tag" ]; then + version="0.1.0" + else + base="${last_tag#v}" + IFS='.' read -r major minor patch <<< "$base" + version="${major}.${minor}.$((patch + 1))" + fi + + cat > config/version.yaml < - + + - + @@ -738,7 +739,6 @@ - @@ -763,7 +763,8 @@ - diff --git a/config/services.yaml b/config/services.yaml index 1c52e92..5cfcb7a 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -8,6 +8,9 @@ # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration parameters: +imports: + - { resource: version.yaml } + services: # default configuration for services in *this* file _defaults: diff --git a/config/version.yaml b/config/version.yaml new file mode 100644 index 0000000..acf5bfb --- /dev/null +++ b/config/version.yaml @@ -0,0 +1,2 @@ +parameters: + app.version: '0.0.29' diff --git a/src/Dto/AppVersion.php b/src/Dto/AppVersion.php new file mode 100644 index 0000000..66f7dea --- /dev/null +++ b/src/Dto/AppVersion.php @@ -0,0 +1,26 @@ + ['version:read']], + provider: AppVersionProvider::class, + ), + ], + security: "is_granted('ROLE_USER')", +)] +final class AppVersion +{ + #[Groups(['version:read'])] + public string $version = ''; +} diff --git a/src/State/AppVersionProvider.php b/src/State/AppVersionProvider.php new file mode 100644 index 0000000..9f14f64 --- /dev/null +++ b/src/State/AppVersionProvider.php @@ -0,0 +1,26 @@ +version = $this->version; + + return $dto; + } +}