Skip to content

Commit

Permalink
github: include CI build number in firmware metadata
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dlech committed Jul 3, 2023
1 parent 1752bec commit 920bd47
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
10 changes: 6 additions & 4 deletions .github/build-each-commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="<hub>")
parser.add_argument("commit", metavar="<commit>")
Expand All @@ -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])
Expand Down
9 changes: 6 additions & 3 deletions .github/build-missing-commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions bricks/_common/arm_none_eabi.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 920bd47

Please sign in to comment.