Skip to content

Commit e1f181d

Browse files
committed
(#256) CI: fix Docker tagging
General approach copied from https://github.com/ForNeVeR/fornever.me
1 parent bdd24bc commit e1f181d

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

.github/workflows/docker.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ jobs:
1919
publish:
2020
runs-on: ubuntu-22.04
2121
steps:
22-
- name: Extract metadata for Docker
23-
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
24-
id: meta
25-
uses: docker/metadata-action@v5
26-
with:
27-
images: |
28-
codingteam/emulsion
29-
tags: |
30-
type=ref,event=branch
22+
- name: Clone the repository
23+
uses: actions/checkout@v4
24+
25+
- name: Read version from ref
26+
id: version
27+
shell: pwsh
28+
run: echo "version=$(./Scripts/Get-Version.ps1 -RefName $env:GITHUB_REF)" >> $env:GITHUB_OUTPUT
3129

3230
- name: Login to Docker Hub
3331
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
@@ -39,7 +37,5 @@ jobs:
3937
- name: Build and Push Docker Images
4038
uses: docker/build-push-action@v6
4139
with:
42-
tags: |
43-
${{ steps.meta.outputs.tags }}
44-
codingteam/emulsion:latest
40+
tags: codingteam/emulsion:latest,codingteam/emulsion:v${{ steps.version.outputs.version }}
4541
push: ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') && 'true' || 'false' }}

Emulsion.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ EndProject
6868
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{E3091B22-752A-4260-B4F3-903B9043479F}"
6969
ProjectSection(SolutionItems) = preProject
7070
scripts\Test-Encoding.ps1 = scripts\Test-Encoding.ps1
71+
scripts\Get-Version.ps1 = scripts\Get-Version.ps1
7172
EndProjectSection
7273
EndProject
7374
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LICENSES", "LICENSES", "{BBA60ACE-9FB4-4F3B-89EC-16A5BB9F5686}"

scripts/Get-Version.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-FileCopyrightText: 2024 Friedrich von Never <friedrich@fornever.me>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
param(
6+
[string] $RefName,
7+
[string] $RepositoryRoot = "$PSScriptRoot/..",
8+
9+
$ProjectFile = "$RepositoryRoot/Emulsion/Emulsion.fsproj"
10+
)
11+
12+
$ErrorActionPreference = 'Stop'
13+
Set-StrictMode -Version Latest
14+
15+
Write-Host "Determining version from ref `"$RefName`""
16+
if ($RefName -match '^refs/tags/v') {
17+
$version = $RefName -replace '^refs/tags/v', ''
18+
Write-Host "Pushed ref is a version tag, version: $version"
19+
} else {
20+
[xml] $props = Get-Content $ProjectFile
21+
$version = $props.Project.PropertyGroup.Version
22+
Write-Host "Pushed ref is a not version tag, get version from $($ProjectFile): $version"
23+
}
24+
25+
Write-Output $version

0 commit comments

Comments
 (0)