-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(build): add new matrix workflow
This adds a new behavior of buildcheck and release workflow. The previous generated array for the matrix step, will now be generated from `setup_matrix.py`, this script reads `.github/workflow_config.yml` and generates the array according to it's setup. This allows an easy to maintain entrypoint to choose which SBC will be build on test builds and releases. It also includes version bump from `action/checkout@v3` to `action/checkout@v4` Updated `.gitignore` to ignore possible `.vscode` directory Signed-off-by: Stephan Wendel <[email protected]>
- Loading branch information
Showing
5 changed files
with
166 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#### Configure workflow matrix | ||
#### | ||
#### Written by Stephan Wendel aka KwadFan <[email protected]> | ||
#### Copyright 2023 - till today | ||
#### https://github.com/mainsail-crew/MainsailOS | ||
#### | ||
#### This File is distributed under GPLv3 | ||
#### | ||
|
||
#### NOTE: Use entries according to their directory/file structure in 'config' | ||
#### e.g. raspberry/rpi32 armbian/orangepi3lts ... | ||
|
||
# Use this categorie to configure behaviour on pushes/pull requests against | ||
# develop branch | ||
# Each entry will be used in setup matrix | ||
|
||
buildtest: | ||
# armbian based images | ||
- armbian/bananapim2zero | ||
- armbian/orangepi3lts | ||
- armbian/orangepi4lts | ||
# Orange Pi OS based images | ||
- orangepi/orangepi_zero2 | ||
# Raspberry Pi OS based images | ||
- raspberry/rpi32 | ||
- raspberry/rpi64 | ||
|
||
# This is used to setup release build chain. | ||
# Each entry will be used in setup matrix for releases | ||
|
||
release: | ||
# armbian based images | ||
- armbian/orangepi3lts | ||
- armbian/orangepi4lts | ||
# Orange Pi OS based images | ||
- orangepi/orangepi_zero2 | ||
# Raspberry Pi OS based images | ||
- raspberry/rpi32 | ||
- raspberry/rpi64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,10 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- name: Clone develop repository | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.PAT }} | ||
ref: 'develop' | ||
ref: "develop" | ||
|
||
- name: Get current version | ||
id: current-version | ||
|
@@ -36,9 +36,9 @@ jobs: | |
if: steps.current-version.outputs.version != github.event.inputs.version | ||
uses: EndBug/add-and-commit@v9 | ||
with: | ||
add: './src/version' | ||
add: "./src/version" | ||
default_author: github_actions | ||
message: 'chore: push version number to v${{ github.event.inputs.version }}' | ||
message: "chore: push version number to v${{ github.event.inputs.version }}" | ||
push: true | ||
|
||
update-master-branch: | ||
|
@@ -49,9 +49,9 @@ jobs: | |
- uses: everlytic/[email protected] | ||
with: | ||
github_token: ${{ secrets.PAT }} | ||
source_ref: 'develop' | ||
target_branch: 'master' | ||
commit_message_template: '[Automated] Merged {source_ref} into target {target_branch}' | ||
source_ref: "develop" | ||
target_branch: "master" | ||
commit_message_template: "[Automated] Merged {source_ref} into target {target_branch}" | ||
|
||
release: | ||
name: Create Release | ||
|
@@ -62,9 +62,9 @@ jobs: | |
date: ${{ steps.base-name.outputs.date }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: 'master' | ||
ref: "master" | ||
fetch-depth: 0 | ||
|
||
- name: Get latest tag | ||
|
@@ -85,7 +85,7 @@ jobs: | |
uses: softprops/action-gh-release@v1 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
name: 'MainsailOS ${{ github.event.inputs.version }}' | ||
name: "MainsailOS ${{ github.event.inputs.version }}" | ||
tag_name: ${{ github.event.inputs.version }} | ||
body: ${{ steps.changelog.outputs.content }} | ||
draft: true | ||
|
@@ -106,18 +106,20 @@ jobs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: master | ||
|
||
- name: Create Matrix | ||
id: set-matrix | ||
run: | | ||
ARRAY=$(find ${{ github.workspace }}/config -type f -printf '%P\n' | sed '/default/d' | sort | jq -R -s -c 'split("\n")[:-1]') | ||
echo "matrix=${ARRAY}" >> $GITHUB_OUTPUT | ||
PY_INT=$(command -v python3) | ||
CONFIG="${{ github.workspace }}/.github/workflow_config.yml" | ||
GROUP="release" | ||
$PY_INT ${{ github.workspace }}/scripts/setup_matrix.py -c $CONFIG -g $GROUP --git | ||
build: | ||
needs: [ release, matrix ] | ||
needs: [release, matrix] | ||
runs-on: ubuntu-latest | ||
outputs: | ||
base_name: ${{ steps.move-image.outputs.base_name }} | ||
|
@@ -271,7 +273,7 @@ jobs: | |
|
||
finish: | ||
name: Finish Release | ||
needs: [ release, build ] | ||
needs: [release, build] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Publish Release | ||
|
@@ -283,7 +285,7 @@ jobs: | |
|
||
update-rpi-imager: | ||
name: Update rpi-imager json | ||
needs: [ release, build, finish ] | ||
needs: [release, build, finish] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download snipes | ||
|
@@ -345,7 +347,7 @@ jobs: | |
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: 'develop' | ||
ref: "develop" | ||
token: ${{ secrets.PAT }} | ||
fetch-depth: 0 | ||
|
||
|
@@ -369,5 +371,5 @@ jobs: | |
cat CHANGELOG.md | ||
- uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
commit_message: 'docs(changelog): update changelog' | ||
commit_message: "docs(changelog): update changelog" | ||
file_pattern: CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,7 @@ src/image/** | |
|
||
# Ignore build.log | ||
src/build.log | ||
|
||
# Ignore vscode settings | ||
.vscode | ||
.vscode/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env python3 | ||
# Generate matrix string from workflow_config.yml | ||
#### | ||
# Written by Stephan Wendel aka KwadFan <[email protected]> | ||
# Copyright 2023 - till today | ||
# https://github.com/mainsail-crew/MainsailOS | ||
#### | ||
# This File is distributed under GPLv3 | ||
#### | ||
|
||
import os | ||
import sys | ||
import yaml | ||
|
||
from pathlib import Path | ||
from argparse import ArgumentParser, RawTextHelpFormatter | ||
|
||
|
||
def main(): | ||
# Parse args | ||
parser = ArgumentParser( | ||
description='Returns list for setup matrix', | ||
formatter_class=RawTextHelpFormatter) | ||
parser.add_argument('-c', '--config', | ||
help='Specify the /path/to/configuration/file', | ||
required=True) | ||
parser.add_argument('-g', '--group', | ||
help='Specify group in your configuration file.\ | ||
\nFor example \'-g buildtest\'', | ||
required=True) | ||
parser.add_argument('--git', | ||
action='store_true', | ||
help='Push output to git environment variables') | ||
args = parser.parse_args() | ||
# Split Namespaces | ||
config_file, setup_group = args.config, args.group | ||
if args.git: | ||
try: | ||
with open(config_file, 'r') as config: | ||
data = yaml.safe_load(config) | ||
# Check if group is present | ||
if not setup_group in data: | ||
with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as gitsum: | ||
gitsum_header_msg(gitsum) | ||
gitsum_err_msg( | ||
f"The given group '{setup_group}' doesn't exist!", | ||
gitsum) | ||
sys.exit(1) | ||
else: | ||
with open(os.environ['GITHUB_OUTPUT'], 'a') as gitout: | ||
print(f'matrix={data[setup_group]}', file=gitout) | ||
with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as gitsum: | ||
gitsum_header_msg(gitsum) | ||
print(f'## Build images for these SBC\'s:', file=gitsum) | ||
for sbc in data[setup_group]: | ||
print(f"- {sbc}", file=gitsum) | ||
except Exception as e: | ||
with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as gitsum: | ||
gitsum_err_msg(e, gitsum) | ||
sys.exit(1) | ||
else: | ||
try: | ||
# Checks if file exists, else raises error. | ||
with open(config_file, 'r') as config: | ||
data = yaml.safe_load(config) | ||
# Check if group is present | ||
if not setup_group in data: | ||
raise Exception( | ||
f"The given group '{setup_group}' doesn't exist!" | ||
) | ||
else: | ||
print(data[setup_group]) | ||
except Exception as e: | ||
err_msg(e) | ||
sys.exit(1) | ||
|
||
|
||
def err_msg(err): | ||
name = Path(__file__).stem | ||
print(f'{name}: OOOPS, something went wrong!\n{err}') | ||
|
||
|
||
def gitsum_header_msg(env_var): | ||
print(f'# Setup Matrix:', file=env_var) | ||
|
||
|
||
def gitsum_err_msg(err, env_var): | ||
gitsum_header_msg(env_var) | ||
print(f'## Error:\n{err}') | ||
|
||
|
||
# MAIN | ||
if __name__ == "__main__": | ||
main() |