Skip to content

Commit

Permalink
[Automated] Merged develop into target master
Browse files Browse the repository at this point in the history
  • Loading branch information
meteyou authored Jan 20, 2024
2 parents ab690d7 + 32cacd9 commit 1304bdb
Show file tree
Hide file tree
Showing 38 changed files with 757 additions and 181 deletions.
132 changes: 132 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: 'MainsailOS/build'
author: 'Stefan Dej'
description: 'Build MainsailOS images'
inputs:
config:
description: 'Board config name'
required: true
custompios-repository:
description: 'Repository for CustomPiOS'
required: false
default: 'guysoft/CustomPiOS'
custompios-ref:
description: 'Branch / Tag / SHA to checkout CustomPiOS'
required: false
default: 'devel'
outputs:
type:
description: SBC type (raspberry/armbian/...)
value: ${{ steps.config.outputs.TYPE }}
sbc:
description: SBC model (rpi32/orangepi4lts/...)
value: ${{ steps.config.outputs.SBC }}

runs:
using: 'composite'
steps:
- name: Install Dependencies
shell: bash
run: sudo apt update; sudo apt install --yes aria2 coreutils jq p7zip-full qemu-user-static zip

- name: Checkout CustomPiOS
uses: actions/checkout@v4
with:
repository: ${{ inputs.custompios-repository }}
ref: ${{ inputs.custompios-ref }}
path: CustomPiOS

- name: Read board config
id: config
shell: bash
run: |
IFS='/' read -r -a array <<< "${{ inputs.config }}"
TYPE=${array[0]}
SBC=${array[1]}
echo "TYPE=${TYPE}" >> $GITHUB_OUTPUT
echo "SBC=${SBC}" >> $GITHUB_OUTPUT
GENERIC_FILE="./repository/config/default"
if [[ -f "$GENERIC_FILE" ]]; then
cat "${GENERIC_FILE}" >> ./repository/src/config
fi
TYPE_FILE="./repository/config/${TYPE}/default"
if [[ -f "$TYPE_FILE" ]]; then
cat "${TYPE_FILE}" >> ./repository/src/config
fi
SBC_FILE="./repository/config/${TYPE}/${SBC}"
if [[ -f "$SBC_FILE" ]]; then
cat "${SBC_FILE}" >> ./repository/src/config
fi
source ./repository/src/config
echo $DOWNLOAD_URL_CHECKSUM
echo $DOWNLOAD_URL_IMAGE
echo $MODULES
echo $(cat ./repository/src/config)
echo "DOWNLOAD_URL_CHECKSUM=${DOWNLOAD_URL_CHECKSUM}" >> $GITHUB_OUTPUT
echo "DOWNLOAD_URL_IMAGE=${DOWNLOAD_URL_IMAGE}" >> $GITHUB_OUTPUT
echo "MODULES=${MODULES}" >> $GITHUB_OUTPUT
- name: Base Image Checksum
id: checksum
shell: bash
run: |
cd repository/src/image
FILENAME=$(basename ${{ steps.config.outputs.DOWNLOAD_URL_CHECKSUM }})
wget -O ${FILENAME} ${{ steps.config.outputs.DOWNLOAD_URL_CHECKSUM }}
FILE_CONTENT=$(head -n 1 $FILENAME)
CHECKSUM=$(echo $FILE_CONTENT | cut -d' ' -f1)
echo "CHECKSUM=${CHECKSUM}" >> $GITHUB_OUTPUT
echo "FILENAME=${FILENAME}" >> $GITHUB_OUTPUT
- name: Cache Base Source Image
id: cache
uses: actions/cache@v3
with:
path: repository/src/image/*.img.xz
key: base-image-${{ steps.checksum.outputs.CHECKSUM }}

- name: Download Base Source Image via Torrent
if: steps.cache.outputs.cache-hit != 'true' && endswith(steps.config.outputs.DOWNLOAD_URL_IMAGE, '.torrent')
shell: bash
run: aria2c -d repository/src/image --seed-time=0 ${{ steps.config.outputs.DOWNLOAD_URL_IMAGE }}

- name: Download Base Source Image via wget
if: steps.cache.outputs.cache-hit != 'true' && !endswith(steps.config.outputs.DOWNLOAD_URL_IMAGE, '.torrent')
shell: bash
run: |
cd repository/src/image
wget ${{ steps.config.outputs.DOWNLOAD_URL_IMAGE }}
- name: Comparing Checksums
shell: bash
run: |
cd repository/src/image
sha256sum -b ${{ steps.checksum.outputs.FILENAME }}
- name: Update CustomPiOS Paths
shell: bash
run: cd repository/src && ../../CustomPiOS/src/update-custompios-paths

- name: Build Image
shell: bash
run: sudo modprobe loop && cd repository/src && sudo bash -x ./build_dist

- name: Cleanup workspace & fix permissions
if: success()
shell: bash
run: |
# Clean up workspace
path="${{ github.workspace }}/repository/src/workspace"
sudo rm -rfv ${path}/aptcache
sudo rm -rfv ${path}/mount
sudo rm -rfv ${path}/chroot_script
sudo chown -v -R ${USER}:${USER} ${path}
sudo chmod 0775 -v -R ${path}
11 changes: 7 additions & 4 deletions .github/label-actions.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configuration for Label Actions - https://github.com/dessant/label-actions

not on Github:
not an Issue:
issues:
comment: |
Ahoi!
Expand All @@ -9,10 +9,12 @@ not on Github:
Many helpful people will not see your message here and you are
unlikely to get a useful response.
We use github to handle bugreports, feature requests and
planning new releases.
We use the Github Issue-Tracker only for development related
topics, like feature requests, bug reports etc. To get help,
please join our Discord-Server or ask in Github Discussions:
Please use our Discord-Server for help: [discord.gg/mainsail](https://discord.gg/mainsail)
- [discord.gg/mainsail](https://discord.gg/mainsail)
- [GitHub Discussions](https://github.com/orgs/mainsail-crew/discussions)
This ticket will be automatically closed.
Expand All @@ -21,3 +23,4 @@ not on Github:
*PS: I'm just an automated script, not a real sailor.*
close: true

94 changes: 94 additions & 0 deletions .github/scripts/setup_matrix.py
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()
39 changes: 39 additions & 0 deletions .github/workflow_config.yml
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
24 changes: 16 additions & 8 deletions .github/workflows/BuildImages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- "src/build_dist"
- "config/**"
- ".github/workflows/BuildImages.yml"
- ".github/workflow_config.yml"
- ".github/scripts/setup_matrix.py"
tags-ignore:
- "**"
pull_request:
Expand All @@ -17,6 +19,8 @@ on:
- "src/**"
- "config/**"
- ".github/workflows/BuildImages.yml"
- ".github/scripts/setup_matrix.py"
- ".github/workflow_config.yml"

workflow_dispatch:

Expand All @@ -32,13 +36,15 @@ jobs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- 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="buildtest"
$PY_INT ${{ github.workspace }}/.github/scripts/setup_matrix.py -c $CONFIG -g $GROUP --git
build:
needs: setup
Expand All @@ -48,9 +54,15 @@ jobs:
matrix:
config: ${{ fromJson(needs.setup.outputs.matrix) }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
path: repository
submodules: true

- name: Build image
id: build
uses: mainsail-crew/MainsailOS-actions/build-image@master
uses: ./repository/.github/actions/build
with:
config: ${{ matrix.config }}

Expand All @@ -63,10 +75,6 @@ jobs:
NOW="$(date +"%Y-%m-%d")"
IMAGE="${NOW}-${DIST_NAME}-${DIST_VERSION}-${{ steps.build.outputs.type }}-${{ steps.build.outputs.sbc }}"
WORKSPACE=$(echo ${{ github.workspace }})
sudo chown -R $USER:$USER $WORKSPACE/repository/src/workspace || true
sudo chmod 0775 -R $WORKSPACE/repository/src/workspace || true
mv repository/src/workspace/*.img $IMAGE.img
echo "image=${IMAGE}" >> $GITHUB_OUTPUT
Expand Down
Loading

0 comments on commit 1304bdb

Please sign in to comment.