From b8ef8e1754ef62d148ff9db830dfe7138f71764e Mon Sep 17 00:00:00 2001 From: Friedrich von Never Date: Mon, 2 Dec 2024 23:11:19 +0100 Subject: [PATCH] (#256) CI: fix Docker tagging General approach copied from https://github.com/ForNeVeR/fornever.me --- .github/workflows/docker.yml | 20 ++++++++------------ Emulsion.sln | 1 + scripts/Get-Version.ps1 | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 scripts/Get-Version.ps1 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ffacc338..89ad405c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -19,15 +19,13 @@ jobs: publish: runs-on: ubuntu-22.04 steps: - - name: Extract metadata for Docker - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - id: meta - uses: docker/metadata-action@v5 - with: - images: | - codingteam/emulsion - tags: | - type=ref,event=branch + - name: Clone the repository + uses: actions/checkout@v4 + + - name: Read version from ref + id: version + shell: pwsh + run: echo "version=$(./scripts/Get-Version.ps1 -RefName $env:GITHUB_REF)" >> $env:GITHUB_OUTPUT - name: Login to Docker Hub if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') @@ -39,7 +37,5 @@ jobs: - name: Build and Push Docker Images uses: docker/build-push-action@v6 with: - tags: | - ${{ steps.meta.outputs.tags }} - codingteam/emulsion:latest + tags: codingteam/emulsion:latest,codingteam/emulsion:v${{ steps.version.outputs.version }} push: ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') && 'true' || 'false' }} diff --git a/Emulsion.sln b/Emulsion.sln index d49c6e31..b8debc3d 100644 --- a/Emulsion.sln +++ b/Emulsion.sln @@ -68,6 +68,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{E3091B22-752A-4260-B4F3-903B9043479F}" ProjectSection(SolutionItems) = preProject scripts\Test-Encoding.ps1 = scripts\Test-Encoding.ps1 + scripts\Get-Version.ps1 = scripts\Get-Version.ps1 EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LICENSES", "LICENSES", "{BBA60ACE-9FB4-4F3B-89EC-16A5BB9F5686}" diff --git a/scripts/Get-Version.ps1 b/scripts/Get-Version.ps1 new file mode 100644 index 00000000..47678f33 --- /dev/null +++ b/scripts/Get-Version.ps1 @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: 2024 Friedrich von Never +# +# SPDX-License-Identifier: MIT + +param( + [string] $RefName, + [string] $RepositoryRoot = "$PSScriptRoot/..", + + $ProjectFile = "$RepositoryRoot/Emulsion/Emulsion.fsproj" +) + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version Latest + +Write-Host "Determining version from ref `"$RefName`"…" +if ($RefName -match '^refs/tags/v') { + $version = $RefName -replace '^refs/tags/v', '' + Write-Host "Pushed ref is a version tag, version: $version" +} else { + [xml] $props = Get-Content $ProjectFile + $version = $props.Project.PropertyGroup.Version + Write-Host "Pushed ref is a not version tag, get version from $($ProjectFile): $version" +} + +Write-Output $version