Skip to content

Commit

Permalink
feat: add github workflow with semver and release
Browse files Browse the repository at this point in the history
  • Loading branch information
anujdeshpande committed Jul 31, 2023
1 parent 36602d0 commit 8a04ca3
Show file tree
Hide file tree
Showing 44 changed files with 833 additions and 2 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: SemVer Release & Build

on:
pull_request:
types: [opened, synchronize, closed]
branches: main

jobs:
version:
outputs:
next: ${{steps.semver.outputs.next}}
nextStrict: ${{steps.semver.outputs.nextStrict}}

runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Get Next Version
id: semver
uses: ietf-tools/semver-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: main

build:
runs-on: ubuntu-22.04
container: ghcr.io/zephyrproject-rtos/ci:v0.26.2
env:
CMAKE_PREFIX_PATH: /opt/toolchains
steps:
- name: Checkout
uses: actions/checkout@v3
with:
path: example-application

- name: Initialize
working-directory: example-application
run: |
west init -l .
west update
- name: Build firmware
working-directory: example-application
run: |
west twister -T app -v --inline-logs --integration
- name: Twister Tests
working-directory: example-application
run: |
west twister -T tests --integration
release:
runs-on: ubuntu-latest
needs: [version,build]
steps:
- name: Create Release
uses: ncipollo/[email protected]
with:
allowUpdates: true
draft: false
makeLatest: true
generateReleaseNotes: true
name: ${{ needs.version.outputs.next }}
body: Changelog Contents
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: "README.md,LICENSE,app/build/zephyr/${{ github.repository }}-${{ needs.version.outputs.nextStrict }}.uf2"
commit: ${{ github.sha }}
tag: ${{ needs.version.outputs.next }}
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editors
.vscode
*.swp
*~

# python
.venv

# build
/build*
/twister-out*

__pycache__/
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
#
# This CMake file is picked by the Zephyr build system because it is defined
# as the module CMake entry point (see zephyr/module.yml).

zephyr_include_directories(include)

add_subdirectory(drivers)
add_subdirectory(lib)
9 changes: 9 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
#
# This Kconfig file is picked by the Zephyr build system because it is defined
# as the module Kconfig entry point (see zephyr/module.yml). You can browse
# module options by going to Zephyr -> Modules in Kconfig.

rsource "drivers/Kconfig"
rsource "lib/Kconfig"
82 changes: 80 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,80 @@
# example-application
Example out-of-tree application that is also a module
# Zephyr Example Application

This repository contains a Zephyr example application. The main purpose of this
repository is to serve as a reference on how to structure Zephyr-based
applications. Some of the features demonstrated in this example are:

- Basic [Zephyr application][app_dev] skeleton
- [Zephyr workspace applications][workspace_app]
- [Zephyr modules][modules]
- [West T2 topology][west_t2]
- [Custom boards][board_porting]
- Custom [devicetree bindings][bindings]
- Out-of-tree [drivers][drivers]
- Out-of-tree libraries
- Example CI configuration (using Github Actions)
- Custom [west extension][west_ext]

This repository is versioned together with the [Zephyr main tree][zephyr]. This
means that every time that Zephyr is tagged, this repository is tagged as well
with the same version number, and the [manifest](west.yml) entry for `zephyr`
will point to the corresponding Zephyr tag. For example, the `example-application`
v2.6.0 will point to Zephyr v2.6.0. Note that the `main` branch always
points to the development branch of Zephyr, also `main`.

[app_dev]: https://docs.zephyrproject.org/latest/develop/application/index.html
[workspace_app]: https://docs.zephyrproject.org/latest/develop/application/index.html#zephyr-workspace-app
[modules]: https://docs.zephyrproject.org/latest/develop/modules.html
[west_t2]: https://docs.zephyrproject.org/latest/develop/west/workspaces.html#west-t2
[board_porting]: https://docs.zephyrproject.org/latest/guides/porting/board_porting.html
[bindings]: https://docs.zephyrproject.org/latest/guides/dts/bindings.html
[drivers]: https://docs.zephyrproject.org/latest/reference/drivers/index.html
[zephyr]: https://github.com/zephyrproject-rtos/zephyr
[west_ext]: https://docs.zephyrproject.org/latest/develop/west/extensions.html

## Getting Started

Before getting started, make sure you have a proper Zephyr development
environment. Follow the official
[Zephyr Getting Started Guide](https://docs.zephyrproject.org/latest/getting_started/index.html).

### Initialization

The first step is to initialize the workspace folder (``my-workspace``) where
the ``example-application`` and all Zephyr modules will be cloned. Run the following
command:

```shell
# initialize my-workspace for the example-application (main branch)
west init -m https://github.com/zephyrproject-rtos/example-application --mr main my-workspace
# update Zephyr modules
cd my-workspace
west update
```

### Building and running

To build the application, run the following command:

```shell
west build -b $BOARD app
```

where `$BOARD` is the target board.

You can use the `custom_plank` board found in this
repository. Note that Zephyr sample boards may be used if an
appropriate overlay is provided (see `app/boards`).

A sample debug configuration is also provided. To apply it, run the following
command:

```shell
west build -b $BOARD app -- -DOVERLAY_CONFIG=debug.conf
```

Once you have built the application, run the following command to flash it:

```shell
west flash
```
12 changes: 12 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#-------------------------------------------------------------------------------
# Zephyr Example Application
#
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(app LANGUAGES C)

target_sources(app PRIVATE src/main.c)
15 changes: 15 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
#
# This file is the application Kconfig entry point. All application Kconfig
# options can be defined here or included via other application Kconfig files.
# You can browse these options using the west targets menuconfig (terminal) or
# guiconfig (GUI).

menu "Zephyr"
source "Kconfig.zephyr"
endmenu

module = APP
module-str = APP
source "subsys/logging/Kconfig.template.log_config"
5 changes: 5 additions & 0 deletions app/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VERSION_MAJOR = 1
VERSION_MINOR = 0
PATCHLEVEL = 0
VERSION_TWEAK = 0
EXTRAVERSION =
21 changes: 21 additions & 0 deletions app/boards/nucleo_f302r8.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/

/* This devicetree overlay file will be automatically picked by the Zephyr
* build system when building the sample for the nucleo_f302r8 board. It shows
* how the example-application can be built on sample boards already provided
* by Zephyr.
*/

/ {
examplesensor0: examplesensor_0 {
compatible = "zephyr,examplesensor";
input-gpios = <&gpioc 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
};
};

&gpioc {
status = "okay";
};
19 changes: 19 additions & 0 deletions app/debug.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
#
# This is a Kconfig fragment which can be used to enable debug-related options
# in the application. See the README for more details.

# compiler
CONFIG_DEBUG_OPTIMIZATIONS=y

# console
CONFIG_CONSOLE=y

# UART console
CONFIG_SERIAL=y
CONFIG_UART_CONSOLE=y

# logging
CONFIG_LOG=y
CONFIG_APP_LOG_LEVEL_DBG=y
6 changes: 6 additions & 0 deletions app/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
#
# This file contains selected Kconfig options for the application.

CONFIG_SENSOR=y
16 changes: 16 additions & 0 deletions app/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is provided so that the application can be compiled using Twister,
# the Zephyr testing tool. In this file, multiple combinations can be specified,
# so that you can easily test all of them locally or in CI.
sample:
description: Example application
name: example-application
common:
build_only: true
integration_platforms:
- custom_plank
- nucleo_f302r8
tests:
app.default: {}
app.debug:
extra_overlay_confs:
- debug.conf
48 changes: 48 additions & 0 deletions app/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/drivers/sensor.h>
#include <app_version.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);

int main(void)
{
int ret;
const struct device *sensor;

printk("Zephyr Example Application %s\n", APP_VERSION_STRING);

sensor = DEVICE_DT_GET(DT_NODELABEL(examplesensor0));
if (!device_is_ready(sensor)) {
LOG_ERR("Sensor not ready");
return 0;
}

while (1) {
struct sensor_value val;

ret = sensor_sample_fetch(sensor);
if (ret < 0) {
LOG_ERR("Could not fetch sample (%d)", ret);
return 0;
}

ret = sensor_channel_get(sensor, SENSOR_CHAN_PROX, &val);
if (ret < 0) {
LOG_ERR("Could not get sample (%d)", ret);
return 0;
}

printk("Sensor value: %d\n", val.val1);

k_sleep(K_MSEC(1000));
}

return 0;
}

8 changes: 8 additions & 0 deletions boards/arm/custom_plank/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

config BOARD_ENABLE_DCDC
bool "Enable DCDC mode"
select SOC_DCDC_NRF52X
default y
depends on BOARD_CUSTOM_PLANK
6 changes: 6 additions & 0 deletions boards/arm/custom_plank/Kconfig.board
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

config BOARD_CUSTOM_PLANK
bool "Custom Plank Board"
depends on SOC_NRF52840_QIAA
9 changes: 9 additions & 0 deletions boards/arm/custom_plank/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

if BOARD_CUSTOM_PLANK

config BOARD
default "custom_plank"

endif # BOARD_CUSTOM_PLANK
6 changes: 6 additions & 0 deletions boards/arm/custom_plank/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Custom Plank Board

`custom_plank` board is used to demonstrate how to create custom boards. It is
in fact a simplified version of the nRF52840-DK board, so the
`example-application` can be run on that development kit when using
`custom_plank`.
12 changes: 12 additions & 0 deletions boards/arm/custom_plank/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

board_runner_args(jlink "--device=nrf52" "--speed=4000")
board_runner_args(pyocd "--target=nrf52840" "--frequency=4000000")

set(OPENOCD_NRF5_SUBFAMILY "nrf52")

include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake)
Loading

0 comments on commit 8a04ca3

Please sign in to comment.