From 920bd4712e123b9ea9382222e20022feaee0c656 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 3 Jul 2023 10:40:39 -0500 Subject: [PATCH] github: include CI build number in firmware metadata This adds the CI build number to the firmware version in the generated firmware.metadata.json file. The output of "git describe ..." is also added to the CI build "tag" so we aren't losing information. --- .github/build-each-commit.py | 10 ++++++---- .github/build-missing-commits.py | 9 ++++++--- .github/workflows/build.yml | 2 +- bricks/_common/arm_none_eabi.mk | 5 +++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/build-each-commit.py b/.github/build-each-commit.py index c92e29806..76cde9be6 100755 --- a/.github/build-each-commit.py +++ b/.github/build-each-commit.py @@ -18,10 +18,6 @@ GITHUB_RUN_NUMBER = os.environ.get("GITHUB_RUN_NUMBER") -if GITHUB_RUN_NUMBER: - os.putenv("MICROPY_GIT_TAG", f"ci-build-{GITHUB_RUN_NUMBER}") - - parser = argparse.ArgumentParser() parser.add_argument("hub", metavar="") parser.add_argument("commit", metavar="") @@ -38,6 +34,12 @@ credential=AzureNamedKeyCredential(STORAGE_ACCOUNT, STORAGE_KEY), ) +if GITHUB_RUN_NUMBER: + tag = pybricks.git.execute( + ["git", "describe", "--tags", "--dirty", "--always", "--exclude", "@pybricks/*"] + ) + os.putenv("MICROPY_GIT_TAG", f"ci-build-{GITHUB_RUN_NUMBER}-{tag}") + # build each commit starting with the oldest start_commit = ( subprocess.check_output(["git", "merge-base", "origin/master", args.commit]) diff --git a/.github/build-missing-commits.py b/.github/build-missing-commits.py index 3d6dae497..655dd6142 100755 --- a/.github/build-missing-commits.py +++ b/.github/build-missing-commits.py @@ -24,9 +24,6 @@ GITHUB_RUN_NUMBER = os.environ.get("GITHUB_RUN_NUMBER") -if GITHUB_RUN_NUMBER: - os.putenv("MICROPY_GIT_TAG", f"ci-build-{GITHUB_RUN_NUMBER}") - print("Building commits...") try: @@ -50,6 +47,12 @@ credential=AzureNamedKeyCredential(STORAGE_ACCOUNT, STORAGE_KEY), ) +if GITHUB_RUN_NUMBER: + tag = pybricks.git.execute( + ["git", "describe", "--tags", "--dirty", "--always", "--exclude", "@pybricks/*"] + ) + os.putenv("MICROPY_GIT_TAG", f"ci-build-{GITHUB_RUN_NUMBER}-{tag}") + start_hash = ci_status_table.get_entity("build", "lastHash")["hash"] if start_hash == pybricks.commit(PYBRICKS_BRANCH).hexsha: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0175a09b4..93b42a8ec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -210,7 +210,7 @@ jobs: - name: Build firmware (master branch) if: ${{ github.base_ref == null && github.ref == 'refs/heads/master' }} run: | - export MICROPY_GIT_TAG=ci-build-${{ github.run_number }} + export MICROPY_GIT_TAG=ci-build-${{ github.run_number }}-$(git describe --tags --dirty --always --exclude "@pybricks/*") export MICROPY_GIT_HASH=$(echo ${{ github.sha }} | cut -c1-8) make -C bricks/${{ matrix.hub }} - name: Extract firmware.zip for upload diff --git a/bricks/_common/arm_none_eabi.mk b/bricks/_common/arm_none_eabi.mk index 563f9c48b..c0f0cd32b 100644 --- a/bricks/_common/arm_none_eabi.mk +++ b/bricks/_common/arm_none_eabi.mk @@ -483,7 +483,12 @@ $(BUILD)/genhdr/%.h: $(PBTOP)/lib/pbio/drv/bluetooth/%.gatt endif +ifeq ($(MICROPY_GIT_TAG),) FW_VERSION := $(shell $(GIT) describe --tags --dirty --always --exclude "@pybricks/*") +else +# CI builds use build number + git hash as tag/firmware version +FW_VERSION := $(MICROPY_GIT_TAG) +endif ifeq ($(PB_MCU_FAMILY),STM32) FW_SECTIONS := -j .isr_vector -j .text -j .data -j .name