From 2216108f817d6e8b10837f5de81eb067b0ee22c7 Mon Sep 17 00:00:00 2001 From: Daniel Finimundi Date: Thu, 17 Feb 2022 02:39:20 +0000 Subject: [PATCH 1/3] Add actual kernel version to info Signed-off-by: Daniel Finimundi --- export-image/04-finalise/01-run.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/export-image/04-finalise/01-run.sh b/export-image/04-finalise/01-run.sh index 8556c3a9e2..bb7409f1c2 100755 --- a/export-image/04-finalise/01-run.sh +++ b/export-image/04-finalise/01-run.sh @@ -69,8 +69,14 @@ cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE" #kernel="$(curl -s -L "https://github.com/raspberrypi/firmware/raw/$firmware/extra/git_hash")" #printf "Kernel: https://github.com/raspberrypi/linux/tree/%s\n" "$kernel" - uname="$(curl -s -L "https://github.com/raspberrypi/firmware/raw/$firmware/extra/uname_string7")" - printf "Uname string: %s\n" "$uname" + #uname="$(curl -s -L "https://github.com/raspberrypi/firmware/raw/$firmware/extra/uname_string7")" + fi + + if [ -f "$ROOTFS_DIR/usr/share/doc/wlanpi-kernel/changelog.Debian.gz" ]; then + kernel=$(zgrep "Kernel version" \ + "$ROOTFS_DIR/usr/share/doc/wlanpi-kernel/changelog.Debian.gz" | \ + head -n1 | sed -n 's|.* \([^ ]*\)$|\1|p') + printf "Kernel: %s\n" "$uname" fi printf "\nPackages:\n" From d9be6808d23c9b1b146213343eaddc57e9ad7530 Mon Sep 17 00:00:00 2001 From: Daniel Finimundi Date: Thu, 17 Feb 2022 05:32:58 +0000 Subject: [PATCH 2/3] Increment version based on tags There are two conditions which will generate a release and increment the build version: 1. Daily builds: automatically try to identify which version bump to use 2. Manually triggered: chose which version to bump, or leave as auto All builds generated will have a different version and be tagged with this version. Signed-off-by: Daniel Finimundi --- .github/workflows/build-image.yml | 32 ++++++++------ build-docker.sh | 2 +- build.sh | 7 ++- export-image/04-finalise/01-run.sh | 4 ++ scripts/update_version.sh | 68 ++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 14 deletions(-) create mode 100755 scripts/update_version.sh diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 5e729cb324..5cb4499a15 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -4,6 +4,18 @@ name: Build image on: # Allow manual runs of workflow from Actions tab workflow_dispatch: + inputs: + version-bump: + description: Version bump + required: true + type: choice + options: + - Auto + - Major + - Minor + - Patch + - RC + default: Auto schedule: - cron: '37 5 * * *' @@ -18,8 +30,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + with: + fetch-depth: '0' - name: Build image + id: build-image run: | last_commit_date=$(git log -1 --format=%cd --date=unix) last_day=$(date -d '-1 day' +%s) @@ -32,23 +47,18 @@ jobs: fi sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - sudo ./build-docker.sh - - - name: Get current date - if: always() - id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%d')" + sudo ./build-docker.sh -v ${{ github.event.input.version-bump }} - name: Upload image uses: actions/upload-artifact@v2 with: - name: wlanpi-nightly-release-${{ steps.date.outputs.date }} + name: wlanpi-nightly-release-${{ steps.build-image.outputs.version }} path: deploy/*.zip - name: Upload image info uses: actions/upload-artifact@v2 with: - name: wlanpi-nightly-release-${{ steps.date.outputs.date }}-info + name: wlanpi-nightly-release-${{ steps.build-image.outputs.version }}-info path: deploy/*.info - name: Create Pre-Release @@ -56,20 +66,18 @@ jobs: uses: "marvinpinto/action-automatic-releases@latest" with: repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "latest" + automatic_release_tag: ${{ steps.build-image.outputs.version }} prerelease: true - title: "Development Build" files: | deploy/*.zip deploy/*.info deploy/wlanpi-os/os.json - deploy/wlanpi-os/os-list.json - name: Upload logs if: always() uses: actions/upload-artifact@v2 with: - name: wlanpi-nightly-release-${{ steps.date.outputs.date }}-buildlogs + name: wlanpi-nightly-release-${{ steps.build-image.outputs.version }}-buildlogs path: deploy/*.log slack-workflow-status: diff --git a/build-docker.sh b/build-docker.sh index 961e1d0c8a..e5f053ffc7 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -20,7 +20,7 @@ if [ -f "${DIR}/config" ]; then CONFIG_FILE="${DIR}/config" fi -while getopts "c:" flag +while getopts "c:v:" flag do case "${flag}" in c) diff --git a/build.sh b/build.sh index 9d4ca8f680..403a3cc32d 100755 --- a/build.sh +++ b/build.sh @@ -170,7 +170,7 @@ if [ -f config ]; then source config fi -while getopts "c:" flag +while getopts "c:v:" flag do case "$flag" in c) @@ -178,6 +178,9 @@ do # shellcheck disable=SC1090 source "$EXTRA_CONFIG" ;; + v) + VERSION_BUMP="${OPTARG}" + ;; *) ;; esac @@ -231,6 +234,8 @@ export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/London}" export GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"} +export VERSION_BUMP=${VERSION_BUMP:-auto} + export PUBKEY_SSH_FIRST_USER export CLEAN diff --git a/export-image/04-finalise/01-run.sh b/export-image/04-finalise/01-run.sh index bb7409f1c2..fe55317328 100755 --- a/export-image/04-finalise/01-run.sh +++ b/export-image/04-finalise/01-run.sh @@ -83,6 +83,10 @@ cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE" dpkg -l --root "$ROOTFS_DIR" } >> "$INFO_FILE" +new_version=$("${SCRIPT_DIR}/update_version.sh" "${VERSION_BUMP}") +echo "VERSION=${new_version}" > "${ROOTFS_DIR}/etc/wlanpi-release" +echo "::set-output name=version::${new_version}" + mkdir -p "${DEPLOY_DIR}" rm -f "${DEPLOY_DIR}/${ZIP_FILENAME}${IMG_SUFFIX}.zip" diff --git a/scripts/update_version.sh b/scripts/update_version.sh new file mode 100755 index 0000000000..cc2e0b5c43 --- /dev/null +++ b/scripts/update_version.sh @@ -0,0 +1,68 @@ +#!/bin/bash -e + +REQUEST_BUMP="$1" + +setup_version() { + if [ -f "/tmp/semver" ]; then + return 0 + fi + + wget -O /tmp/semver \ + https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver + chmod +x /tmp/semver +} + +# Print version with "v" prefix +get_latest_tag() { + tag="$(git describe --tags --abbrev=0 --match="v[0-9].[0-9].[0-9]*")" + echo "${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}" + exit 0 + fi + + REQUEST_BUMP="$(echo "${REQUEST_BUMP}" | tr '[:upper:]' '[:lower:]')" + + case "${REQUEST_BUMP}" in + break|major) is_breaking=1 ;; + feat|minor) is_feature=1 ;; + rc) is_rc=1 ;; + patch) is_patch=1 ;; + *) + # Guess the bump from commit history + commits="$(git log --oneline "${last_version}"..HEAD)" + + is_breaking="$(echo "${commits}" | awk '{ print $2; }' | { grep "BREAK:" || :; })" + is_feature="$(echo "${commits}" | awk '{ print $2; }' | { grep "feat:" || :; })" + is_rc="$(echo "${last_version}" | { grep -- "-rc" || :; })" + ;; + esac + + if [ -n "${is_breaking}" ]; then + ver_bump="major" + elif [ -n "${is_feature}" ]; then + ver_bump="minor" + elif [ -n "${is_rc}" ]; then + ver_bump="prerel rc." + else + ver_bump="patch" + fi + + # Update version according to commit history + new_version=$(/tmp/semver bump ${ver_bump} "${last_version}") + + # Add -rc to the new version code + if [ -n "${is_rc}" ] && [ "${ver_bump}" != "prerel rc." ]; then + new_version=$(/tmp/semver bump ${ver_bump} "${new_version}") + fi + + echo "v${new_version}" +} + +update_version From c3055fdee4cdb84e397e74531d379f4802efd356 Mon Sep 17 00:00:00 2001 From: Daniel Finimundi Date: Thu, 17 Feb 2022 06:28:47 +0000 Subject: [PATCH 3/3] Move git operations earlier on script Git operations need to be performed outside docker. Signed-off-by: Daniel Finimundi --- build-docker.sh | 9 +++++++++ build.sh | 3 +++ export-image/04-finalise/01-run.sh | 2 +- scripts/update_version.sh | 10 +++++----- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/build-docker.sh b/build-docker.sh index e5f053ffc7..f9b00c6165 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -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) @@ -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 && @@ -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 diff --git a/build.sh b/build.sh index 403a3cc32d..e831709711 100755 --- a/build.sh +++ b/build.sh @@ -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 diff --git a/export-image/04-finalise/01-run.sh b/export-image/04-finalise/01-run.sh index fe55317328..a6c94a105f 100755 --- a/export-image/04-finalise/01-run.sh +++ b/export-image/04-finalise/01-run.sh @@ -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}" diff --git a/scripts/update_version.sh b/scripts/update_version.sh index cc2e0b5c43..e8783d0f35 100755 --- a/scripts/update_version.sh +++ b/scripts/update_version.sh @@ -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 } @@ -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 @@ -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:" || :; })"