diff --git a/.gitea/PULL_REQUEST_TEMPLATE.md b/.gitea/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..aed2bc5 --- /dev/null +++ b/.gitea/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,23 @@ +--- + +name: "Merge Request" +about: "Template de MR" +title: "[#NUMERO_TICKET] TITRE TICKET" +ref: "main" + +--- + +| Numéro du ticket | Titre du ticket | +|------------------|-----------------| +| | | + +## Description de la PR + +## Modification du .env + +## Check list + +- [ ] Pas de régression +- [ ] TU/TI/TF rédigée +- [ ] TU/TI/TF OK +- [ ] CHANGELOG modifié diff --git a/.gitea/workflows/auto-tag-develop.yml b/.gitea/workflows/auto-tag-develop.yml new file mode 100644 index 0000000..48f28d5 --- /dev/null +++ b/.gitea/workflows/auto-tag-develop.yml @@ -0,0 +1,65 @@ +name: Auto Tag Develop + +on: + push: + branches: + - develop + +jobs: + tag: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.RELEASE_TOKEN }} + persist-credentials: true + + - name: Create next tag from config/version.yaml + shell: bash + run: | + set -euo pipefail + + # 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 + + changed_version=false + if git diff --name-only "${{ gitea.event.before }}" "${{ gitea.event.after }}" | grep -q '^config/version\.yaml$'; then + changed_version=true + fi + + 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 + + printf "parameters:\\n app.version: '%s'\\n" "$version" > config/version.yaml + git config user.name "gitea-actions" + git config user.email "gitea-actions@local" + git add config/version.yaml + git commit -m "chore: bump version to v$version" || true + git push origin develop || true + fi + + tag="v$version" + git tag "$tag" + git push origin "$tag" diff --git a/.gitea/workflows/release-artefact.yml b/.gitea/workflows/release-artefact.yml new file mode 100644 index 0000000..127e56f --- /dev/null +++ b/.gitea/workflows/release-artefact.yml @@ -0,0 +1,65 @@ +name: Build Release Artefact + +on: + push: + tags: + - "v0.0.*" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.4" + extensions: mbstring, intl, pdo_pgsql, xml, curl, zip, gd + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "lts/*" + + - name: Install backend deps (prod) + env: + APP_ENV: prod + APP_DEBUG: "0" + run: composer install --no-dev --optimize-autoloader --no-interaction --no-scripts + + - name: Build frontend (static) + run: | + cd frontend + npm ci + CI=1 NUXT_TELEMETRY_DISABLED=1 NUXT_PUBLIC_API_BASE=/api NUXT_PUBLIC_APP_BASE=/ npm run generate + test -f .output/public/index.html + + - name: Build artefact + shell: bash + run: | + set -euo pipefail + mkdir -p release + tar -czf "release/sirh-${GITHUB_REF_NAME}.tar.gz" \ + bin \ + config \ + migrations \ + public \ + src \ + templates \ + vendor \ + composer.json \ + composer.lock \ + symfony.lock \ + frontend/.output + + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + files: release/sirh-${{ github.ref_name }}.tar.gz + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 4dca2fa..17f38d2 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -48,6 +48,8 @@ security: access_control: - { path: ^/login_check, roles: PUBLIC_ACCESS } - { path: ^/api/docs, roles: PUBLIC_ACCESS } + # Version de l'application en public + - { path: ^/api/version, roles: PUBLIC_ACCESS, methods: [ GET ] } - { path: ^/api, roles: IS_AUTHENTICATED_FULLY } when@test: diff --git a/config/services.yaml b/config/services.yaml index 79b8ce2..49aba49 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..a7d0bd7 --- /dev/null +++ b/config/version.yaml @@ -0,0 +1,2 @@ +parameters: + app.version: '0.0.1' diff --git a/frontend/app.vue b/frontend/app.vue index 5e39f2a..b0e0080 100644 --- a/frontend/app.vue +++ b/frontend/app.vue @@ -3,3 +3,11 @@ + + diff --git a/frontend/composables/useAppVersion.ts b/frontend/composables/useAppVersion.ts new file mode 100644 index 0000000..803278d --- /dev/null +++ b/frontend/composables/useAppVersion.ts @@ -0,0 +1,17 @@ +export const useAppVersion = () => { + const api = useApi() + const version = useState('app-version', () => null) + + const load = async () => { + if (version.value) { + return version.value + } + const response = await api.get<{ version: string }>('version', {}, { + toast: false + }) + version.value = response.version + return version.value + } + + return { version, load } +} diff --git a/frontend/layouts/auth.vue b/frontend/layouts/auth.vue index d208b25..97d9275 100644 --- a/frontend/layouts/auth.vue +++ b/frontend/layouts/auth.vue @@ -5,3 +5,7 @@ + + diff --git a/frontend/layouts/default.vue b/frontend/layouts/default.vue index 472e5ff..4a7deb0 100644 --- a/frontend/layouts/default.vue +++ b/frontend/layouts/default.vue @@ -43,7 +43,7 @@ -
+
+

v{{ version }}

@@ -63,6 +64,7 @@ diff --git a/src/ApiResource/AppVersion.php b/src/ApiResource/AppVersion.php new file mode 100644 index 0000000..ba3c071 --- /dev/null +++ b/src/ApiResource/AppVersion.php @@ -0,0 +1,25 @@ + ['version:read']], + provider: AppVersionProvider::class, + ), + ], +)] +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..cc65752 --- /dev/null +++ b/src/State/AppVersionProvider.php @@ -0,0 +1,26 @@ +version = $this->version; + + return $dto; + } +}