Fix build system for correct version metadata

This commit is contained in:
Daniel 2024-04-16 15:46:56 +02:00
parent ed20c7f1b2
commit 493309ebb3
3 changed files with 75 additions and 40 deletions
.earthlyignoreEarthfile
cmds/portmaster-core

View file

@ -1,25 +1,63 @@
go.work
go.work.sum
dist/
node_modules/
# Ignore angular outputs.
desktop/angular/node_modules
desktop/angular/dist
desktop/angular/dist-lib
desktop/angular/dist-extension
desktop/angular/.angular
# Assets are ignored here because the symlink wouldn't work in
# the buildkit container so we copy the assets directly in Earthfile.
desktop/angular/assets
# Ignore tauri outputs.
desktop/tauri/src-tauri/target
.gitignore
AUTHORS
CODE_OF_CONDUCT.md
LICENSE
README.md
TESTING.md
TRADEMARKS
#######################
# Copy from .gitignore:
# Compiled binaries
*.exe
dist/
# Dist dir
dist
# Custom dev deops
go.mod.*
# vendor dir
vendor
# testing
testing
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# OS specifics
.DS_Store
# Custom dev scripts
win_dev_*
go.work
go.work.sum

View file

@ -56,37 +56,29 @@ go-deps:
go-base:
FROM +go-deps
# Only copy go-code related files to improve caching.
# (i.e. do not rebuild go if only the angular app changed)
COPY cmds ./cmds
COPY runtime ./runtime
COPY service ./service
COPY spn ./spn
# Copy the full repo, as Go embeds whether the state is clean.
COPY . .
# The cmds/notifier embeds some icons but go:embed is not allowed
# to leave the package directory so there's a small go-package in
# assets. Once we drop the notify in favor of the tauri replacement
# we can remove the following line and also remove all go-code from
# ./assets
COPY assets ./assets
# Copy the git folder and extract version information
COPY .git ./.git
LET version = $(git tag --points-at)
IF [ "${version}" = "" ]
SET version = "$(git describe --tags --abbrev=0)_dev_build"
LET version = "$(git tag --points-at || true)"
IF [ -z "${version}" ]
LET dev_version = "$(git describe --tags --first-parent --abbrev=0 || true)"
IF [ -n "${dev_version}" ]
SET version = "${dev_version}_dev_build"
END
END
IF [ "${version}" = "" ]
IF [ -z "${version}" ]
SET version = "dev_build"
END
ENV VERSION="${version}"
RUN echo "Version: $VERSION"
LET source = $( ( git remote -v | cut -f2 | cut -d" " -f1 | head -n 1 ) || echo "unknown" )
ENV SOURCE="${source}"
RUN echo "Source: $SOURCE"
LET build_time = $(date -u "+%Y-%m-%dT%H:%M:%SZ" || echo "unknown")
ENV BUILD_TIME = "${build_time}"
RUN echo "Build Time: $BUILD_TIME"
# Explicitly cache here.
SAVE IMAGE --cache-hint
@ -204,7 +196,6 @@ angular-deps:
COPY desktop/angular/package.json .
COPY desktop/angular/package-lock.json .
COPY assets/data ./assets
RUN npm install
@ -215,6 +206,9 @@ angular-base:
ARG configuration="production"
COPY desktop/angular/ .
# Remove symlink and copy assets directly.
RUN rm ./assets
COPY assets/data ./assets
IF [ "${configuration}" = "production" ]
RUN npm run build-libs

View file

@ -1,7 +1,10 @@
#!/bin/bash
# Gather build metadata.
VERSION="$(git tag --points-at)"; test -z "$VERSION" && VERSION="$(git describe --tags --abbrev=0)_dev_build"; test -z "$VERSION" && VERSION="dev_build"
VERSION="$(git tag --points-at)" || true
test -z "$VERSION" && DEV_VERSION="$(git describe --tags --first-parent --abbrev=0)" || true
test -n "$DEV_VERSION" && VERSION="${DEV_VERSION}_dev_build"
test -z "$VERSION" && VERSION="dev_build"
SOURCE=$( ( git remote -v | cut -f2 | cut -d" " -f1 | head -n 1 ) || echo "unknown" )
BUILD_TIME=$(date -u "+%Y-%m-%dT%H:%M:%SZ" || echo "unknown")