Skip to content

Commit

Permalink
(#256) CI: fix Docker tagging
Browse files Browse the repository at this point in the history
General approach copied from https://github.com/ForNeVeR/fornever.me
  • Loading branch information
ForNeVeR committed Dec 2, 2024
1 parent bdd24bc commit b8ef8e1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand All @@ -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' }}
1 change: 1 addition & 0 deletions Emulsion.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
25 changes: 25 additions & 0 deletions scripts/Get-Version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-FileCopyrightText: 2024 Friedrich von Never <[email protected]>
#
# 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

0 comments on commit b8ef8e1

Please sign in to comment.