From 484d30b3bfa2195872b6a4fa2f4c06a022e6e297 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Thu, 11 Jan 2024 22:39:51 +0100 Subject: [PATCH 1/8] chore: refactor build workflow Signed-off-by: Stefan Dej --- .github/build.yml | 130 ++++++++++++++++++++++++++++++ .github/workflows/BuildImages.yml | 2 +- 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 .github/build.yml diff --git a/.github/build.yml b/.github/build.yml new file mode 100644 index 000000000..d6fcfc855 --- /dev/null +++ b/.github/build.yml @@ -0,0 +1,130 @@ +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' + build-ref: + description: 'Branch / Tag / SHA to checkout Build repo' + required: false + default: ${{ github.ref }} +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@v3 + with: + repository: ${{ inputs.custompios-repository }} + ref: ${{ inputs.custompios-ref }} + path: CustomPiOS + + - name: Checkout Repository + uses: actions/checkout@v3 + with: + ref: ${{ inputs.build-ref }} + path: repository + submodules: true + + - 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 diff --git a/.github/workflows/BuildImages.yml b/.github/workflows/BuildImages.yml index c2f6f985b..53e165eed 100644 --- a/.github/workflows/BuildImages.yml +++ b/.github/workflows/BuildImages.yml @@ -56,7 +56,7 @@ jobs: steps: - name: Build image id: build - uses: mainsail-crew/MainsailOS-actions/build-image@master + uses: ./.github/actions/build with: config: ${{ matrix.config }} From ac2836b34596fc605103b51ebd804837aa275cab Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Thu, 11 Jan 2024 22:41:44 +0100 Subject: [PATCH 2/8] fix: file location Signed-off-by: Stefan Dej --- .github/{build.yml => actions/build/action.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{build.yml => actions/build/action.yml} (100%) diff --git a/.github/build.yml b/.github/actions/build/action.yml similarity index 100% rename from .github/build.yml rename to .github/actions/build/action.yml From 8efa07895117b765fdc965b8ec0a8e099311221d Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Thu, 11 Jan 2024 22:43:57 +0100 Subject: [PATCH 3/8] fix: extract checkout repository Signed-off-by: Stefan Dej --- .github/actions/build/action.yml | 11 ----------- .github/workflows/BuildImages.yml | 9 ++++++++- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index d6fcfc855..5a4f858d8 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -13,10 +13,6 @@ inputs: description: 'Branch / Tag / SHA to checkout CustomPiOS' required: false default: 'devel' - build-ref: - description: 'Branch / Tag / SHA to checkout Build repo' - required: false - default: ${{ github.ref }} outputs: type: description: SBC type (raspberry/armbian/...) @@ -39,13 +35,6 @@ runs: ref: ${{ inputs.custompios-ref }} path: CustomPiOS - - name: Checkout Repository - uses: actions/checkout@v3 - with: - ref: ${{ inputs.build-ref }} - path: repository - submodules: true - - name: Read board config id: config shell: bash diff --git a/.github/workflows/BuildImages.yml b/.github/workflows/BuildImages.yml index 53e165eed..0a5c51e6f 100644 --- a/.github/workflows/BuildImages.yml +++ b/.github/workflows/BuildImages.yml @@ -54,9 +54,16 @@ jobs: matrix: config: ${{ fromJson(needs.setup.outputs.matrix) }} steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + ref: ${{ inputs.build-ref }} + path: repository + submodules: true + - name: Build image id: build - uses: ./.github/actions/build + uses: ./repository/.github/actions/build with: config: ${{ matrix.config }} From f4bf0e79ff24b58bd5a8d593daed101ee54fc6f6 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Thu, 11 Jan 2024 22:45:42 +0100 Subject: [PATCH 4/8] chore: update actions/checkout to v4 Signed-off-by: Stefan Dej --- .github/actions/build/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 5a4f858d8..aa2244f60 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -29,7 +29,7 @@ runs: run: sudo apt update; sudo apt install --yes aria2 coreutils jq p7zip-full qemu-user-static zip - name: Checkout CustomPiOS - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: ${{ inputs.custompios-repository }} ref: ${{ inputs.custompios-ref }} From 36aebfd29ac315e88f67e036e29402a244c928ac Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Thu, 11 Jan 2024 22:53:46 +0100 Subject: [PATCH 5/8] chore: add cleanup & fix permission step in actions/build Signed-off-by: Stefan Dej --- .github/actions/build/action.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index aa2244f60..fd5f537b2 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -117,3 +117,16 @@ runs: - 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} From a611f82eade224b16d64389c15715035953a69fe Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Thu, 11 Jan 2024 22:54:25 +0100 Subject: [PATCH 6/8] chore: remove fix permission in buildimages & release workflow Signed-off-by: Stefan Dej --- .github/workflows/BuildImages.yml | 4 ---- .github/workflows/Release.yml | 4 ---- 2 files changed, 8 deletions(-) diff --git a/.github/workflows/BuildImages.yml b/.github/workflows/BuildImages.yml index 0a5c51e6f..31f899ad0 100644 --- a/.github/workflows/BuildImages.yml +++ b/.github/workflows/BuildImages.yml @@ -76,10 +76,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 diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 7ed3df389..d7afa3525 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -146,10 +146,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 }}" From a28f32d73930d82762f05792a34e675f5d753efe Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Thu, 11 Jan 2024 22:54:46 +0100 Subject: [PATCH 7/8] chore: remove deprecated input Signed-off-by: Stefan Dej --- .github/workflows/BuildImages.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/BuildImages.yml b/.github/workflows/BuildImages.yml index 31f899ad0..befe00189 100644 --- a/.github/workflows/BuildImages.yml +++ b/.github/workflows/BuildImages.yml @@ -57,7 +57,6 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 with: - ref: ${{ inputs.build-ref }} path: repository submodules: true From fa14bb87180cb391cc1b1f360711494a5cae3ff2 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Thu, 11 Jan 2024 22:55:03 +0100 Subject: [PATCH 8/8] chore: switch to new relative workflow Signed-off-by: Stefan Dej --- .github/workflows/Release.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index d7afa3525..8cc14fb34 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -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()