Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI build job #146

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ jobs:
- name: Analyze
shell: bash
run: ./ci/analyze.sh --analyzer shellcheck

build:
name: Build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Install dependencies
shell: bash
run: sudo apt update && sudo apt install avr-libc avrdude gcc-avr
- name: Build
shell: bash
run: ./ci/build.sh
121 changes: 121 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env bash

# toolchain-avr-gcc
#
# Copyright 2019-2024, Andrew Countryman <apcountryman@gmail.com> and the
# toolchain-avr-gcc contributors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
# file except in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the specific language governing
# permissions and limitations under the License.

# Description: CI build script.

function error()
{
local -r message="$1"

( >&2 echo "$mnemonic: $message" )
}

function abort()
{
if [[ "$#" -gt 0 ]]; then
local -r message="$1"

error "$message, aborting"
fi

exit 1
}

function validate_script()
{
if ! shellcheck "$script"; then
abort
fi
}

function display_help_text()
{
printf "%b" \
"NAME\n" \
" $mnemonic - Ensure no build errors are present.\n" \
"SYNOPSIS\n" \
" $mnemonic --help\n" \
" $mnemonic --version\n" \
" $mnemonic\n" \
"OPTIONS\n" \
" --help\n" \
" Display this help text.\n" \
" --version\n" \
" Display the version of this script.\n" \
"EXAMPLES\n" \
" $mnemonic --help\n" \
" $mnemonic --version\n" \
" $mnemonic\n" \
""
}

function display_version()
{
echo "$mnemonic, version $version"
}

function ensure_no_build_errors_are_present()
{
local -r toolchain_file="$repository/toolchain.cmake"
local -r build_directory="$repository/build"

if ! cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" -S "$repository" -B "$build_directory"; then
abort
fi

if ! cmake --build "$build_directory" -j "$( nproc )"; then
abort
fi
}

function main()
{
local -r script=$( readlink -f "$0" )
local -r mnemonic=$( basename "$script" )

validate_script

local -r repository=$( readlink -f "$( dirname "$script" )/.." )
local -r version=$( git -C "$repository" describe --match=none --always --dirty --broken )

while [[ "$#" -gt 0 ]]; do
local argument="$1"; shift

case "$argument" in
--help)
display_help_text
exit
;;
--version)
display_version
exit
;;
--*)
;&
-*)
abort "'$argument' is not a supported option"
;;
*)
abort "'$argument' is not a valid argument"
;;
esac
done

ensure_no_build_errors_are_present
}

main "$@"