Skip to content

Commit

Permalink
build: fix providing release version to build inside docker (#439)
Browse files Browse the repository at this point in the history
* build: fix providing release version to build inside docker

* ci: optimize github actions
  • Loading branch information
subotic authored Apr 9, 2024
1 parent aec9de3 commit 3803418
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: docker-build

on:
schedule:
# run on midnight every day
- cron: '0 0 * * *'
pull_request:

jobs:
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
name: publish

on:
push:
branches:
- main
# This triggers for any tag or branch creation. We'll filter for tags in the job.
create:
# This triggers for any tag or branch creation. We'll filter for tags in the job.

jobs:
# Build for release and publish amd64
amd64:
if: github.ref == 'refs/heads/main' || (github.event_name == 'create' && startsWith(github.ref, 'refs/tags/'))
if: startsWith(github.ref, 'refs/tags/')
runs-on: buildjet-4vcpu-ubuntu-2204
concurrency:
group: ${{ github.ref }}-publish-amd64
Expand All @@ -33,7 +30,7 @@ jobs:

# Build for release and publish aarch64
aarch64:
if: github.ref == 'refs/heads/main' || (github.event_name == 'create' && startsWith(github.ref, 'refs/tags/'))
if: startsWith(github.ref, 'refs/tags/')
runs-on: buildjet-4vcpu-ubuntu-2204-arm
concurrency:
group: ${{ github.ref }}-publish-aarch64
Expand All @@ -58,7 +55,7 @@ jobs:
manifest:
runs-on: ubuntu-latest
needs: [ amd64, aarch64 ]
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags'))
if: startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -78,13 +75,15 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: |
echo "RELEASE_VERSION=$(git describe --tag --dirty --abbrev=7)" >> $GITHUB_ENV
- uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
version: ${{ github.ref_name }}
version: ${{ env.RELEASE_VERSION }}

# Publish documentation
docs:
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ on:
push:
branches:
- main
create:
# This triggers for any tag or branch creation. We'll filter for tags in the job.

jobs:
# Do the release-please thing
release-please:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || (github.event_name == 'create' && startsWith(github.ref, 'refs/tags'))
steps:
- uses: google-github-actions/release-please-action@v4
with:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ on:
schedule:
# run on midnight every day
- cron: '0 0 * * *'
push:
branches: [ main ]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down
54 changes: 29 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,32 +318,36 @@ if (DOXYGEN_FOUND)
)
endif (DOXYGEN_FOUND)


#
# get version from git
#
if (EXISTS ${PROJECT_SOURCE_DIR}/.git)
find_package(Git)
if (GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tag --dirty --abbrev=7
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE BUILD_SCM_TAG
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE BUILD_SCM_REVISION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
else (GIT_FOUND)
SET(BUILD_SCM_REVISION 0)
SET(BUILD_SCM_TAG 0)
endif (GIT_FOUND)
endif (EXISTS ${PROJECT_SOURCE_DIR}/.git)

option(BUILD_SCM_TAG "Build SCM tag" "$ENV{BUILD_TAG}")
# get version from git if not provided externally
#
if (EXT_PROVIDED_VERSION STREQUAL "OFF")
message(STATUS "Getting version from git")
if (EXISTS ${PROJECT_SOURCE_DIR}/.git)
find_package(Git)
if (GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tag --dirty --abbrev=7
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE BUILD_SCM_TAG
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE BUILD_SCM_REVISION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
else (GIT_FOUND)
SET(BUILD_SCM_REVISION 0)
SET(BUILD_SCM_TAG 0)
endif (GIT_FOUND)
endif (EXISTS ${PROJECT_SOURCE_DIR}/.git)
else ()
message(STATUS "Using externally provided version")
SET(BUILD_SCM_REVISION 0)
SET(BUILD_SCM_TAG ${EXT_PROVIDED_VERSION})
endif (EXT_PROVIDED_VERSION STREQUAL "OFF")

message(STATUS "Build SCM tag: ${BUILD_SCM_TAG}")
message(STATUS "Build SCM revision: ${BUILD_SCM_REVISION}")
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ WORKDIR /tmp/sipi
# Add everything to image.
COPY . .

ARG BUILD_TAG
ENV BUILD_TAG=${BUILD_TAG}
# this can be provided when the image is built
ARG VERSION=OFF

# Build SIPI and run unit tests.
RUN cmake -S . -B ./build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release --log-context
RUN cmake -S . -B ./build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DEXT_PROVIDED_VERSION=$VERSION --log-context
RUN cmake --build ./build --parallel 4
RUN cd build && ctest --output-on-failure

Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ docker-build: ## build and publish Sipi Docker image locally
--progress auto \
--build-arg SIPI_BASE=$(SIPI_BASE) \
--build-arg UBUNTU_BASE=$(UBUNTU_BASE) \
--build-arg BUILD_TAG=$(BUILD_TAG) \
--build-arg VERSION=$(BUILD_TAG) \
-t $(DOCKER_IMAGE) -t $(DOCKER_REPO):latest \
--load \
.
Expand All @@ -48,7 +48,7 @@ docker-test-build-aarch64: ## locally (unit) test and publish aarch64 Sipi Docke
--platform linux/arm64 \
--build-arg SIPI_BASE=$(SIPI_BASE) \
--build-arg UBUNTU_BASE=$(UBUNTU_BASE) \
--build-arg BUILD_TAG=$(BUILD_TAG) \
--build-arg VERSION=$(BUILD_TAG) \
-t $(DOCKER_IMAGE)-aarch64 -t $(DOCKER_REPO):latest \
--load \
.
Expand All @@ -64,7 +64,7 @@ docker-test-build-amd64: ## locally (unit) test and publish x86 Sipi Docker imag
--platform linux/amd64 \
--build-arg SIPI_BASE=$(SIPI_BASE) \
--build-arg UBUNTU_BASE=$(UBUNTU_BASE) \
--build-arg BUILD_TAG=$(BUILD_TAG) \
--build-arg VERSION=$(BUILD_TAG) \
-t $(DOCKER_IMAGE)-amd64 -t $(DOCKER_REPO):latest \
--load \
.
Expand Down
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ run:
# start SIPI with Valgrind (inside NIX develop shell, e.g., 'nix clang')
valgrind:
valgrind --leak-check=yes --track-origins=yes ./build/sipi --config=/sipi/config/sipi.config.lua

# query version of the project
version:
cmake -P query_version.cmake
38 changes: 38 additions & 0 deletions query_version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# query_version.cmake
#
# This script is used to query the value for the version of the project.
# It starts by trying to retrieve the git tag of the project. If the tag
# is the same as the version found in version.txt, then the this version
# is used. Otherwise, the version is set to the tag plus
#

# Assuming this script is located in /my_project/query_variable.cmake
cmake_minimum_required(VERSION 3.28)


# get version from git
#
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/.git)
find_package(Git QUIET)
if (Git_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tag --dirty --abbrev=7
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE BUILD_SCM_TAG
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE BUILD_SCM_REVISION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
else (Git_FOUND)
SET(BUILD_SCM_REVISION 0)
SET(BUILD_SCM_TAG 0)
endif (Git_FOUND)
endif (EXISTS ${CMAKE_CURRENT_LIST_DIR}/.git)

# Output the variable of interest
message("${BUILD_SCM_TAG}")

0 comments on commit 3803418

Please sign in to comment.