From 8cb1eee60b82b0bfe00f3260ece281b269cd04fb Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 22 Feb 2025 11:06:46 +0100 Subject: [PATCH] docker, ci: fix --version output When building the docker image manually, MINEDMAP_VERSION needs to be set explicitly to get a proper version string. --- .github/workflows/MinedMap.yml | 12 ++++++++++++ Dockerfile | 2 ++ src/core/mod.rs | 18 ++++++++++++------ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.github/workflows/MinedMap.yml b/.github/workflows/MinedMap.yml index 2aef1ec..24895c9 100644 --- a/.github/workflows/MinedMap.yml +++ b/.github/workflows/MinedMap.yml @@ -154,6 +154,16 @@ jobs: needs: - test steps: + - name: 'Checkout' + uses: 'actions/checkout@v4' + + - name: 'Get version' + id: 'tag' + run: | + set -o pipefail + git fetch --prune --unshallow --tags -f + echo "tag=$(git describe --abbrev=7 --match='v*' | sed 's/^v//')" >> $GITHUB_OUTPUT + - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -182,6 +192,8 @@ jobs: - name: Build uses: docker/build-push-action@v6 with: + build-args: | + MINEDMAP_VERSION=${{ steps.tag.outputs.tag }} push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index bb0e0ad..49965db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM docker.io/library/alpine:latest AS builder +ARG MINEDMAP_VERSION + WORKDIR /build RUN apk add --no-cache build-base cmake cargo diff --git a/src/core/mod.rs b/src/core/mod.rs index 202d017..a16f620 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -33,17 +33,23 @@ use tracing::{info, warn}; use self::entity_collector::EntityCollector; -/// MinedMap version number -const VERSION: &str = git_version!( - args = ["--abbrev=7", "--match=v*", "--dirty=-modified"], - cargo_prefix = "v", -); +/// Returns the MinedMap version number +fn version() -> &'static str { + option_env!("MINEDMAP_VERSION").unwrap_or( + git_version!( + args = ["--abbrev=7", "--match=v*", "--dirty=-modified"], + cargo_prefix = "v", + ) + .strip_prefix("v") + .unwrap(), + ) +} /// Command line arguments for minedmap CLI #[derive(Debug, Parser)] #[command( about, - version = VERSION.strip_prefix("v").unwrap(), + version = version(), max_term_width = 100, )] pub struct Args {