Skip to content

Commit

Permalink
chore: refactor build & release workflow to remove external actions (#…
Browse files Browse the repository at this point in the history
…264)

* chore: refactor build workflow

Signed-off-by: Stefan Dej <[email protected]>

* fix: file location

Signed-off-by: Stefan Dej <[email protected]>

* fix: extract checkout repository

Signed-off-by: Stefan Dej <[email protected]>

* chore: update actions/checkout to v4

Signed-off-by: Stefan Dej <[email protected]>

* chore: add cleanup & fix permission step in actions/build

Signed-off-by: Stefan Dej <[email protected]>

* chore: remove fix permission in buildimages & release workflow

Signed-off-by: Stefan Dej <[email protected]>

* chore: remove deprecated input

Signed-off-by: Stefan Dej <[email protected]>

* chore: switch to new relative workflow

Signed-off-by: Stefan Dej <[email protected]>

---------

Signed-off-by: Stefan Dej <[email protected]>
  • Loading branch information
meteyou authored Jan 12, 2024
1 parent 01a3b73 commit 5944e36
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 11 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}
12 changes: 7 additions & 5 deletions .github/workflows/BuildImages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,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 @@ -69,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
13 changes: 7 additions & 6 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,17 @@ jobs:
matrix:
config: ${{ fromJson(needs.matrix.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 }}
build-ref: master

- name: Upload failed Logfile
if: failure()
Expand All @@ -146,10 +151,6 @@ jobs:
id: move-image
shell: bash
run: |
WORKSPACE=$(echo ${{ github.workspace }})
sudo chown -R $USER:$USER $WORKSPACE/repository/src/workspace || true
sudo chmod 0775 -R $WORKSPACE/repository/src/workspace || true
source repository/src/config
base_name="${{ needs.release.outputs.date }}-${DIST_NAME}-${DIST_VERSION}"
image="${base_name}-${{ steps.build.outputs.type }}-${{ steps.build.outputs.sbc }}"
Expand Down

0 comments on commit 5944e36

Please sign in to comment.