Skip to content

Commit

Permalink
Move git operations earlier on script
Browse files Browse the repository at this point in the history
Git operations need to be performed outside docker.

Signed-off-by: Daniel Finimundi <daniel@finimundi.com>
  • Loading branch information
danielmundi committed Feb 17, 2022
1 parent d9be680 commit c3055fd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
9 changes: 9 additions & 0 deletions build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ fi

# Ensure the Git Hash is recorded before entering the docker container
GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"}
LAST_VERSION="$(git describe --tags --abbrev=0 --match="v[0-9].[0-9].[0-9]*")"
LAST_VERSION_HASH="$(git rev-parse "${LAST_VERSION}")"
COMMITS_FROM_LAST="$(git log --oneline "${LAST_VERSION}"..${GIT_HASH})"

CONTAINER_EXISTS=$(${DOCKER} ps -a --filter name="${CONTAINER_NAME}" -q)
CONTAINER_RUNNING=$(${DOCKER} ps --filter name="${CONTAINER_NAME}" -q)
Expand Down Expand Up @@ -95,6 +98,9 @@ if [ "${CONTAINER_EXISTS}" != "" ]; then
${PIGEN_DOCKER_OPTS} \
--volume "${CONFIG_FILE}":/config:ro \
-e "GIT_HASH=${GIT_HASH}" \
-e "LAST_VERSION=${LAST_VERSION}" \
-e "LAST_VERSION_HASH=${LAST_VERSION_HASH}" \
-e "COMMITS_FROM_LAST=${COMMITS_FROM_LAST}" \
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
Expand All @@ -113,6 +119,9 @@ else
${PIGEN_DOCKER_OPTS} \
--volume "${CONFIG_FILE}":/config:ro \
-e "GIT_HASH=${GIT_HASH}" \
-e "LAST_VERSION=${LAST_VERSION}" \
-e "LAST_VERSION_HASH=${LAST_VERSION_HASH}" \
-e "COMMITS_FROM_LAST=${COMMITS_FROM_LAST}" \
pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
# binfmt_misc is sometimes not mounted with debian bullseye image
Expand Down
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/London}"
export GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"}

export VERSION_BUMP=${VERSION_BUMP:-auto}
export LAST_VERSION=${LAST_VERSION:-"$(git describe --tags --abbrev=0 --match="v[0-9].[0-9].[0-9]*")"}
export LAST_VERSION_HASH=${LAST_VERSION_HASH:-"$(git rev-parse "${LAST_VERSION}")"}
export COMMITS_FROM_LAST=${COMMITS_FROM_LAST:-"$(git log --oneline "${LAST_VERSION}"..${GIT_HASH})"}

export PUBKEY_SSH_FIRST_USER

Expand Down
2 changes: 1 addition & 1 deletion export-image/04-finalise/01-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE"
dpkg -l --root "$ROOTFS_DIR"
} >> "$INFO_FILE"

new_version=$("${SCRIPT_DIR}/update_version.sh" "${VERSION_BUMP}")
new_version=$(source "${SCRIPT_DIR}/update_version.sh" "${VERSION_BUMP}")
echo "VERSION=${new_version}" > "${ROOTFS_DIR}/etc/wlanpi-release"
echo "::set-output name=version::${new_version}"

Expand Down
10 changes: 5 additions & 5 deletions scripts/update_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ setup_version() {
return 0
fi

wget -O /tmp/semver \
wget -q -O /tmp/semver \
https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver
chmod +x /tmp/semver
}
Expand All @@ -21,9 +21,9 @@ get_latest_tag() {
update_version() {
setup_version

last_version="$(get_latest_tag)"
if [ "$(git rev-parse "${latest_version}") == "$(git rev-parse HEAD) ]; then
echo "v${latest_version}"
last_version="${LAST_VERSION}"
if [ "${GIT_HASH}" == "${LAST_VERSION_HASH}" ]; then
echo "${last_version}"
exit 0
fi

Expand All @@ -36,7 +36,7 @@ update_version() {
patch) is_patch=1 ;;
*)
# Guess the bump from commit history
commits="$(git log --oneline "${last_version}"..HEAD)"
commits="${COMMITS_FROM_LAST}"

is_breaking="$(echo "${commits}" | awk '{ print $2; }' | { grep "BREAK:" || :; })"
is_feature="$(echo "${commits}" | awk '{ print $2; }' | { grep "feat:" || :; })"
Expand Down

0 comments on commit c3055fd

Please sign in to comment.