Skip to content

Commit

Permalink
CI/CD basic implementation based on GitHub Actions (#167)
Browse files Browse the repository at this point in the history
CI/CD basic implementation based on GitHub Actions
  • Loading branch information
ia authored Apr 8, 2024
1 parent 80e8bb7 commit ecfb2cc
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI


on:
push:
branches:
- master
pull_request:
branches:
- master


jobs:
build:
runs-on: ubuntu-22.04
strategy:
matrix:
model: [ "hydrafw" ]
fail-fast: true

steps:
- name: Update package cache
run: sudo apt update -y

- name: Install packages
run: sudo apt install -y --no-install-recommends --no-install-suggests bash coreutils tar bzip2 git make python3 python3-pip

- name: Install python modules
run: python3 -m pip install GitPython intelhex --upgrade

- uses: actions/checkout@v4
with:
submodules: true
fetch-tags: true
fetch-depth: 0

- name: Set git meta info
run: echo "GITHUB_CI_PR_SHA=${{github.event.pull_request.head.sha}}" >> "${GITHUB_ENV}"

- name: Install standalone reference GCC toolchain
run: bash scripts/env.sh

- name: Build ${{ matrix.model }}
run: source build.env && arm-none-eabi-gcc --version && arm-none-eabi-gcc -print-search-dirs && make V=1 -j$(nproc) -C src/

- name: Archive ${{ matrix.model }} artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.model }}
path: |
src/build/${{ matrix.model }}.dfu
if-no-files-found: error


33 changes: 33 additions & 0 deletions scripts/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
#set -x
set -e

# This script is used to enroll toolchain with GitHub Actions for CI/CD purposes
# But this script can be used as reference to install recommended toolchain for building hydrafw.dfu locally as well

MD5SUM=8a4a74872830f80c788c944877d3ad8c
TARBALL=gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2
TARDIR=gcc-arm-none-eabi-4_9-2015q3
LINK=https://launchpad.net/gcc-arm-embedded/4.9/4.9-2015-q3-update/+download/"${TARBALL}"
CURDIR="$(pwd)"

echo "${MD5SUM} ${TARBALL}" > md5.txt
wget "${LINK}"
md5sum -c md5.txt
rm md5.txt

tar xvjf "${TARBALL}"
rm "${TARBALL}"

if [ -n "${GITHUB_CI_PR_SHA}" ]; then
# This is for GitHub Actions CI/CD tooling only
echo "export PATH=\"${CURDIR}/${TARDIR}/bin\":\"\${PATH}\"" > build.env
else
# And this is for local install
echo ""
echo "Add a line like"
echo "export PATH=\"${CURDIR}/${TARDIR}/bin\":\"\${PATH}\""
echo "to your ~/.profile and/or ~/.bashrc and run the line to enable toolchain as default one for arm-none-eabi-* target"
echo ""
fi;

5 changes: 4 additions & 1 deletion src/build-scripts/hydrafw-revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@

git=Repo(search_parent_directories=True).git
version = git.describe(tags=True,always=True,dirty=True,long=True)
print(r.search(version).group(1))
if r.search(version):
print(r.search(version).group(1))
else:
print("0.0")
11 changes: 10 additions & 1 deletion src/build-scripts/hydrafw-version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3

import sys
import os
import re
from optparse import OptionParser
from datetime import *
from git import *
Expand All @@ -14,7 +16,14 @@
if len(args)==1:
sys.stdout = open(args[0], 'w')
git=Repo(search_parent_directories=True).git
print('#define HYDRAFW_GIT_TAG "' + git.describe(tags=True,always=True,dirty=True,long=True) + '"')
vermagic=git.describe(tags=True,always=True,dirty=True,long=True)
if os.environ.get("GITHUB_CI_PR_SHA", "") != "":
# if GITHUB_CI_PR_SHA is set, then it's GitHub Actions build, so workaround to set a valid tag is required
sha_id=os.environ["GITHUB_CI_PR_SHA"][:7]
print('#define HYDRAFW_GIT_TAG "' + re.sub('-g.*$', '-g' + sha_id, vermagic) + '"')
else:
# If it's local build, then set "normal" tag
print('#define HYDRAFW_GIT_TAG "' + vermagic + '"')
print('#define HYDRAFW_CHECKIN_DATE "' + git.show(['-s', '--pretty=format:%ai']).partition(' ')[0] + '"')
else:
parser.print_help()
Expand Down

0 comments on commit ecfb2cc

Please sign in to comment.