Skip to content

Commit 46668a4

Browse files
1612 patch version deduction (#1634)
* use git to deduce version before build * prep version file with git before configuring build remove the current version from source tree and ignore it, have it generated by building procedure * format justfile and cleanup comments * do a full clone and then use git describe --tags for versioning - deduce label for gold by inspecting last commit that edited the validation sample files - set VERSION in production container by copying over just prep-version - use fetch-depth: 0 whenever we actions/checkout so that we can successfully git describe --tags whenever we need to * need a clone of ldmx-sw when validating
1 parent 850a5b5 commit 46668a4

11 files changed

+49
-34
lines changed

.github/actions/common.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222

2323
# Print the gold label
2424
ldmx_gold_label() {
25-
cat ${LDMX_VERSION_FILE}
25+
# git the commit that last edited any of the validation samples
26+
# use git describe --tags to deduce the tag it is closest to
27+
# cut out the first field which is the name of the closest tag
28+
git log -n 1 --pretty=format:"%h" -- ${LDMX_BASE}/ldmx-sw/.github/validation_samples/*/** |\
29+
xargs git describe --tags |\
30+
cut -f 1 -d -
2631
}
2732

2833
# container running command
@@ -67,8 +72,6 @@ warn() {
6772

6873
start_group Deduce Common Environment Variables
6974
export LDMX_BASE=$(cd ${GITHUB_WORKSPACE}/../ && pwd)
70-
export LDMX_VERSION_FILE=${LDMX_BASE}/ldmx-sw/VERSION
71-
echo "LDMX_VERSION_FILE=${LDMX_VERSION_FILE}"
7275
echo "LDMX_BASE=${LDMX_BASE}"
7376
end_group
7477

.github/workflows/basic_test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
uses: actions/checkout@v4
1818
with:
1919
submodules: 'recursive'
20+
fetch-depth: 0
2021

2122
- name: Install just
2223
uses: extractions/setup-just@v2

.github/workflows/build_production_image.yml

+4
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ jobs:
4040
uses: actions/checkout@v4
4141
with:
4242
submodules: recursive
43+
fetch-depth: 0
4344
ref: ${{ github.event.inputs.branch }}
4445
-
4546
name: Determine Image Tags
4647
id: generate_tag
4748
run: |
49+
# this part is just a copy of just prep-version
50+
# TODO: transfer building of the production image to a just recipe
51+
git fetch --tags && git describe --tags | cut -f 1 -d '-' > VERSION
4852
source ${GITHUB_WORKSPACE}/.github/actions/common.sh
4953
_tags=""
5054
if [[ $GITHUB_EVENT_NAME == "workflow_dispatch" ]]; then

.github/workflows/compile_clang_lto.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
uses: actions/checkout@v4
1919
with:
2020
submodules: 'recursive'
21+
fetch-depth: 0
2122

2223
- name: Install just
2324
uses: extractions/setup-just@v2

.github/workflows/docs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
uses: actions/checkout@v4
3030
with:
3131
submodules: 'recursive'
32+
fetch-depth: 0
3233

3334
- name: Install just
3435
uses: extractions/setup-just@v2

.github/workflows/generate_pr_gold.yml

+2-13
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@ jobs:
1919
uses: actions/checkout@v4
2020
with:
2121
submodules: 'recursive'
22+
fetch-depth: 0
2223

2324
- name : Install just
2425
uses: extractions/setup-just@v2
2526
with:
2627
just-version: 1.26.0
2728

28-
- name: Take care of versioning
29-
run: |
30-
source ${GITHUB_WORKSPACE}/.github/actions/common.sh
31-
echo "Old Label: $(ldmx_gold_label)"
32-
echo "${GITHUB_REF##refs/tags/}" > ${LDMX_VERSION_FILE}
33-
echo "New Label: $(ldmx_gold_label)"
34-
3529
- name: Compile and Install ldmx-sw
3630
run: |
3731
just install-denv init configure-force-error
@@ -92,6 +86,7 @@ jobs:
9286
uses: actions/checkout@v4
9387
with:
9488
submodules: 'recursive'
89+
fetch-depth: 0
9590
ref: trunk
9691

9792
- name: Download All the Gold
@@ -106,12 +101,6 @@ jobs:
106101
id: update-gold
107102
run: |
108103
source ${GITHUB_WORKSPACE}/.github/actions/common.sh
109-
start_group Update Gold Label
110-
echo "Old Label: $(ldmx_gold_label)"
111-
echo "${GITHUB_REF##refs/tags/}" > ${LDMX_VERSION_FILE}
112-
echo "New Label: $(ldmx_gold_label)"
113-
git add ${LDMX_GOLD_LABEL_FILE}
114-
end_group
115104
start_group Copy over new Gold Histograms
116105
artifacts_d=${{steps.download.outputs.download-path}}
117106
echo ${artifacts_d}

.github/workflows/new_pre_release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
with:
2828
submodules: 'recursive'
2929
ref: ${{ github.event.inputs.branch }}
30+
fetch-depth: 0
3031

3132
- name: Install just
3233
uses: extractions/setup-just@v2

.github/workflows/pr_validation.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ jobs:
6363
shell: bash
6464

6565
- name: Git Gold Histograms from trunk
66-
run: git checkout origin/trunk -- .github/validation_samples/*/gold.root VERSION
66+
run: git checkout origin/trunk -- .github/validation_samples/*/**
6767
shell: bash
6868

6969
- name: Package ldmx-sw Into Artifact
70-
run: tar cf ldmx-sw-package.tar install/ .github/ VERSION
70+
run: tar cf ldmx-sw-package.tar install/ .github/
7171

7272
- name: Upload ldmx-sw Package
7373
uses: actions/upload-artifact@v4
@@ -101,7 +101,14 @@ jobs:
101101
fi
102102
echo "HEAD_REF=$HEAD_REF" >> $GITHUB_ENV
103103
104-
104+
# need clone of ldmx-sw for getting gold tag
105+
- name: Checkout ldmx-sw
106+
uses: actions/checkout@v4
107+
with:
108+
submodules: 'recursive'
109+
fetch-depth: 0
110+
ref: ${{ env.HEAD_REF }}
111+
105112
- name: Download ldmx-sw Package
106113
uses: actions/download-artifact@v4
107114
with:

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# file storing git VERSION for build
2+
VERSION
13

24
# Byte-compiled files
35
__pycache__/

VERSION

-1
This file was deleted.

justfile

+21-14
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,29 @@ export APPTAINER_CACHEDIR := env("APPTAINER_CACHEDIR", LDMX_BASE / ".apptainer")
5050
_default:
5151
@just --list --justfile {{ justfile() }} --list-heading "{{ help_message }}"
5252

53-
# this install is private since I'd prefer users knowing what tools they are installing;
54-
55-
# however, the CI needs to install denv before it can run any testing
53+
# install recipe for the CI, private so users know what tools they have on their computers
5654
[private]
5755
install-denv:
5856
curl -s https://raw.githubusercontent.com/tomeichlersmith/denv/main/install | sh
5957

58+
# prep version file
59+
[private]
60+
prep-version:
61+
git fetch --tags && git describe --tags | cut -f 1 -d '-' > VERSION
62+
6063
# configure how ldmx-sw will be built
6164
# added ADDITIONAL_WARNINGS and CLANG_TIDY to help improve code quality
65+
6266
# base configure command defining how cmake is called, private so only experts call it
6367
[private]
64-
configure-base *CONFIG:
68+
configure-base *CONFIG: prep-version
6569
denv cmake -B build -S . {{ CONFIG }}
6670

6771
# default configure of build when developing
6872
configure *CONFIG: (configure-base "-DADDITIONAL_WARNINGS=ON -DENABLE_CLANG_TIDY=ON" CONFIG)
6973

7074
# configure minimal option for faster compilation
71-
configure-quick: (configure-base)
75+
configure-quick: configure-base
7276

7377
# configure with Address Sanitizer (ASAN) and UndefinedBehaviorSanitizer (UBSan)
7478
configure-asan-ubsan: (configure-base "-DENABLE_SANITIZER_UNDEFINED_BEHAVIOR=ON -DENABLE_SANITIZER_ADDRESS=ON")
@@ -77,11 +81,13 @@ configure-asan-ubsan: (configure-base "-DENABLE_SANITIZER_UNDEFINED_BEHAVIOR=ON
7781
configure-force-error: (configure "-DWARNINGS_AS_ERRORS=ON")
7882

7983
# Use alternative compiler and enable LTO (test compiling only, won't run properly)
80-
configure-clang-lto: (configure "-DENABLE_LTO=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang")
84+
configure-clang-lto: (configure "-DENABLE_LTO=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang")
8185

8286
configure-clang-lto-fail-on-warning: (configure "-DENABLE_LTO=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DWARNINGS_AS_ERRORS=ON")
87+
8388
# Keep debug symbols so running with gdb provides more helpful detail
8489
configure-gdb: (configure-base "-DCMAKE_BUILD_TYPE=Debug")
90+
8591
# compile and install ldmx-sw
8692
build ncpu=num_cpus():
8793
denv cmake --build build --target install -- -j{{ ncpu }}
@@ -145,7 +151,7 @@ check:
145151
# remove the build and install directories of ldmx-sw
146152
[confirm("This will remove the build and install directories. Are you sure?")]
147153
clean:
148-
rm -r build install
154+
rm -r build install VERSION
149155

150156
# format the ldmx-sw source code
151157
format: format-cpp format-just
@@ -226,12 +232,13 @@ recompFire config_py *ARGS: compile (fire config_py ARGS)
226232
# install the validation module
227233
# `python3 -m pip install Validation/` is the standard `pip` install method.
228234
# We add `--upgrade` to tell `pip` it should overwrite the package if it already has been
229-
# # installed before which is helpful in the case where someone is updating the code and running
230-
# # the new code within the container. The `--target install/python/` arguments tell `pip`
231-
# # where to install the package. This directory is where we currently store our python modules
232-
# # and is where the container expects them to be. The `--no-cache` argument tells `pip` to
233-
# # not use a cache for downloading any dependencies from the internet which is necessary since
234-
# # `pip` will not be able to write to the cache location within the container.
235-
# # install the python Validation plotting module
235+
# installed before which is helpful in the case where someone is updating the code and running
236+
# the new code within the container. The `--target install/python/` arguments tell `pip`
237+
# where to install the package. This directory is where we currently store our python modules
238+
# and is where the container expects them to be. The `--no-cache` argument tells `pip` to
239+
# not use a cache for downloading any dependencies from the internet which is necessary since
240+
# `pip` will not be able to write to the cache location within the container.
241+
242+
# install the python Validation plotting module
236243
install-validation:
237244
denv python3 -m pip install Validation/ --upgrade --target install/python/ --no-cache

0 commit comments

Comments
 (0)