Skip to content

Commit ed2e4a1

Browse files
authored
disable git versioning if status, version, or revision are set in the YAML front block (#241)
1 parent 5a8f24a commit ed2e4a1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ RUN apt install -y \
109109
rsync \
110110
sed \
111111
software-properties-common \
112-
wget
112+
wget \
113+
yq
113114

114115
# Install Chromium via custom repo
115116
# https://askubuntu.com/questions/1204571/how-to-install-chromium-without-snap/1511695#1511695

build.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ done
210210

211211
# Mark globals set from the command line as readonly when we're done updating them.
212212
readonly RESOURCE_DIR
213-
readonly DO_GITVERSION
214213
readonly DO_GITSTATUS
215214
readonly VERSIONED_FILENAMES
216215
readonly PR_NUMBER
@@ -297,6 +296,27 @@ if ! browser=$(command -v "chromium-browser"); then
297296
fi
298297
fi
299298

299+
# If any of the following values are provided in the YAML metadata block,
300+
# use the values from the metadata block instead of doing git-based versioning:
301+
# * version
302+
# * revision
303+
# * status
304+
# NOTE: While Pandoc allows the YAML metadata to be anywhere in the document,
305+
# we require it to be up at the top.
306+
# Use sed to strip the '...' at the end of the YAML metadata block, and yq to
307+
# parse it for fields of interest.
308+
yaml_version=$(sed '/\.\.\./Q' ${INPUT_FILE} | yq '.version')
309+
yaml_revision=$(sed '/\.\.\./Q' ${INPUT_FILE} | yq '.revision')
310+
yaml_status=$(sed '/\.\.\./Q' ${INPUT_FILE} | yq '.status')
311+
echo "YAML version: ${yaml_version}"
312+
echo "YAML revision: ${yaml_revision}"
313+
echo "YAML status: ${yaml_status}"
314+
if [[ "${yaml_version}" != "null" ]] || [[ "${yaml_revision}" != "null" ]] || [[ "${yaml_status}" != "null" ]]; then
315+
echo "Disabling Git-based versioning because version information was found in the YAML metadata block."
316+
DO_GITVERSION=false
317+
fi
318+
readonly DO_GITVERSION
319+
300320
# figure out git version and revision if needed.
301321
EXTRA_PANDOC_OPTIONS=""
302322
if test "${DO_GITVERSION}" == "yes"; then

0 commit comments

Comments
 (0)