Files
scripts/.github/workflows/build-with-docker.yml
2023-02-13 14:21:20 +01:00

403 lines
15 KiB
YAML

name: Build with Docker
on:
workflow_dispatch:
workflow_call:
inputs:
parallel:
required: false
type: number
description: How many runners for matrix
boardtype:
required: false
type: string
sourcerepo:
required: true
type: string
packagesrepo:
required: false
type: string
variant:
required: true
type: string
runner:
required: true
type: string
part:
required: true
type: number
of:
required: true
type: number
include:
required: false
type: string
exclude:
required: false
type: string
uploading:
type: string
fromsources:
required: false
type: string
secrets:
CR_PAT:
required: false
GPG_KEY1:
required: true
GPG_PASSPHRASE1:
required: true
GPG_KEY2:
required: true
GPG_PASSPHRASE2:
required: true
SCRIPTS_ACCESS_TOKEN:
required: true
SSH_KEY_TORRENTS:
required: true
KNOWN_HOSTS_UPLOAD:
required: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
Prepare:
if: ${{ github.repository_owner == 'Armbian' }}
name: targets
runs-on: small
outputs:
matrix: ${{steps.list_dirs.outputs.matrix}}
runner: ${{steps.list_dirs.outputs.runner}}
parallel: ${{steps.list_dirs.outputs.parallel}}
steps:
- name: Runner prepare
uses: armbian/actions/runner-prepare@main
- name: Set ENV vars
run: |
SOURCEREPO=${{ inputs.sourcerepo }}
echo "REPO=${SOURCEREPO:-nightly}" >> $GITHUB_ENV
PACKAGESREPO=${{ inputs.packagesrepo }}
echo "BETA=${PACKAGESREPO:-yes}" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v3.3.0
with:
fetch-depth: 1
repository: armbian/build
path: build
ref: ${{ env.REPO }}
clean: false
- name: Make build list
if: ${{ inputs.boardtype != '' }}
id: make-list
uses: armbian/actions/make-list@main
with:
type: ${{ inputs.boardtype }}
- name: Upload build list
if: ${{ inputs.boardtype != '' }}
uses: actions/upload-artifact@v3
with:
path: targets.txt
name: targets
if-no-files-found: ignore
- name: Remove previous artefacts if any
run: |
sudo rm -rf changes 2>/dev/null || true
- name: Download changes
uses: actions/download-artifact@v3.0.2
with:
name: changes
- name: Prepare matrix
id: list_dirs
run: |
var="${{ inputs.variant }}"
if [[ "$var" == *stable || "$var" == *rc ]]; then
FILENAME="build/config/targets.conf | grep ${var%:*} | grep \"yes\|adv\""
else
FILENAME="build/config/targets-${var%:*}-beta.conf"
fi
[[ -n "${{ inputs.boardtype }}" ]] && FILENAME="targets.txt | grep ${var%:*}"
# if we want to split more
TEMP=$(mktemp -d || exit 1)
LIST="cat "${FILENAME}" | grep -v \"^$\" | grep -v \"^#\" | awk '{if (\$6 == \"yes\" || \$6 == \"adv\") print \$0;}' | ${{ inputs.include }} ${{ inputs.exclude }} cut -f1 -d ' ' | pr -t -n4 | tr -s '[:blank:]' ':' | cut -d\":\" -f2,3"
eval $LIST > $TEMP/data.txt
MATRIX="split --number=l/${{ inputs.part }}/${{ inputs.of }} <<< cat $TEMP/data.txt"
[ -s changes ] || unset MATRIX
#echo ::set-output name=matrix::$(for x in $(eval $MATRIX); do echo $x; done|jq -cnR '[inputs | select(length>0)]' | jq)
#value=$(for x in $(eval $MATRIX); do echo $x; done|jq -cnR '[inputs | select(length>0)]' | jq -c)
echo "matrix=$(for x in $(eval $MATRIX); do echo $x; done|jq -cnR '[inputs | select(length>0)]' | jq -c)" >> $GITHUB_OUTPUT
if [[ -z "${{ inputs.runner }}" ]]; then
#echo ::set-output name=runner::$(echo '["ubuntu-latest"]' | jq) || true
echo "runner=ubuntu-latest" >> $GITHUB_OUTPUT
else
#echo ::set-output name=runner::$(echo '["${{ inputs.runner }}"]' | jq) || true
echo "runner=${{ inputs.runner }}" >> $GITHUB_OUTPUT
fi
if [[ -z "${{ inputs.parallel }}" ]]; then
#echo ::set-output name=parallel::128 || true
echo "parallel=128" >> $GITHUB_OUTPUT
else
#echo ::set-output name=parallel::${{ inputs.parallel }} || true
echo "parallel=${{ inputs.parallel }}" >> $GITHUB_OUTPUT
fi
image:
needs: Prepare
if: ${{ needs.Prepare.outputs.matrix != '[]' && needs.Prepare.outputs.matrix != '' }}
strategy:
fail-fast: false
max-parallel: ${{fromJson(needs.Prepare.outputs.parallel)}}
matrix:
node: ${{fromJson(needs.Prepare.outputs.matrix)}}
runs-on: ${{needs.Prepare.outputs.runner}}
steps:
- name: Runner prepare
uses: armbian/actions/runner-prepare@main
- name: Set environment variables
run: |
SOURCEREPO=${{ inputs.sourcerepo }}
echo "REPO=${SOURCEREPO:-nightly}" >> $GITHUB_ENV
PACKAGESREPO=${{ inputs.packagesrepo }}
echo "BETA=${PACKAGESREPO:-yes}" >> $GITHUB_ENV
echo ${{needs.Prepare.outputs.runner}}
- name: Checkout repository
uses: actions/checkout@v3.3.0
with:
fetch-depth: 1
repository: armbian/build
path: build
ref: ${{ env.REPO }}
clean: false
- name: Checkout support scripts
uses: actions/checkout@v3.3.0
with:
fetch-depth: 1
repository: armbian/scripts
path: scripts
clean: false
# - name: Make build list
# if: ${{ inputs.boardtype != '' }}
# id: make-list
# uses: armbian/actions/make-list@main
# with:
# type: ${{ inputs.boardtype }}
- name: Download build list
if: ${{ inputs.boardtype != '' }}
uses: actions/download-artifact@v3.0.2
with:
name: targets
- name: Copy templates
run: |
mkdir -p build/userpatches
sudo cp scripts/configs/* build/userpatches/
- name: Pull Docker image
run: |
[[ -z $(command -v docker) ]] && sudo apt-get -yy install docker containerd docker.io
sudo docker kill $(sudo docker ps -q) 2>/dev/null || true
sudo docker image rm $(sudo docker images | grep -v latest | grep armbian | awk 'NR>1 {print $3}') 2> /dev/null || true
sudo docker pull ghcr.io/armbian/build:latest"-$(dpkg --print-architecture)"
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_KEY1 }}
passphrase: ${{ secrets.GPG_PASSPHRASE1 }}
workdir: scripts
git_user_signingkey: true
git_commit_gpgsign: true
- name: Assemble
run: |
# use local resources if possible
if [[ $(curl -s http://ifconfig.me) == "93.103.15.56" ]]; then
sudo rm -rf build/cache/toolchain/*
sudo mkdir -p build/cache/toolchain build/cache/rootfs || true
! sudo mountpoint -q cache/toolchain && sudo mount nas:/tank/armbian/toolchain.armbian.com build/cache/toolchain -o rsize=32768,wsize=32768,timeo=5,retrans=2,actimeo=60,retry=3 || true
#! sudo mountpoint -q cache/rootfs && sudo mount nas:/tank/armbian/cache.armbian.com/rootfs build/cache/rootfs -o rsize=32768,wsize=32768,timeo=5,retrans=2,actimeo=60,retry=3 || true
fi
#if [[ $(curl -s http://ifconfig.me) == "188.227.12.36" || $(curl -s http://ifconfig.me) == "206.82.251.151" ]]; then
# sudo rm -rf build/cache/sources
# sudo mkdir -p build/cache/toolchain build/cache/rootfs || true
# # sudo mount -a
# ! sudo mountpoint -q build/cache/toolchain && sudo mount --bind /mnt/armbian/cache/toolchain/ build/cache/toolchain -o rsize=32768,wsize=32768,timeo=5,retrans=2,actimeo=60,retry=3 || true
# ! sudo mountpoint -q build/cache/rootfs && sudo mount --bind /mnt/armbian/cache/rootfs/ build/cache/rootfs/ -o rsize=32768,wsize=32768,timeo=5,retrans=2,actimeo=60,retry=3 || true
#fi
var="${{ inputs.variant }}"
RC="no"
if [[ "$var" == *stable || "$var" == *rc ]]; then
FILENAME="build/config/targets.conf | grep ${var%:*} | grep \"yes\|adv\""
MAKE_FOLDERS=archive
#OLD="ghcr.io/armbian/build:$(cat build/VERSION | cut -d"." -f1-2)"-$(dpkg --print-architecture)
#sudo docker tag $OLD ghcr.io/armbian/build:$(cat scripts/VERSION)-$(dpkg --print-architecture)
# we use nightly repository, but change back to stable right before closing image
echo "#!""/bin/bash" | sudo tee build/userpatches/customize-image.sh
echo "sed -i 's/beta/apt/' /etc/apt/sources.list.d/armbian.list" | sudo tee -a build/userpatches/customize-image.sh
echo "sed -i 's/https/http/' /etc/apt/sources.list.d/armbian.list" | sudo tee -a build/userpatches/customize-image.sh
echo "sed -i 's/IMAGE_TYPE=.*/IMAGE_TYPE=stable/' /etc/armbian-image-release" | sudo tee -a build/userpatches/customize-image.sh
echo "sed -i 's/IMAGE_TYPE=.*/IMAGE_TYPE=stable/' /etc/armbian-release" | sudo tee -a build/userpatches/customize-image.sh
if [[ "$var" == *rc ]]; then
MAKE_FOLDERS=rc
fi
else
FILENAME="build/config/targets-${var%:*}-beta.conf"
MAKE_FOLDERS=nightly
fi
INSTALL_HEADERS="no"
# install headers on all images but minimal
# [[ "${BUILD_MINIMAL}" != yes ]] && INSTALL_HEADERS="yes"
# when making all from the list
if [[ "${{ inputs.fromsources }}" == yes ]]; then
SKIP_EXTERNAL_TOOLCHAINS="no"
IGNORE_UPDATES="no"
UPLOAD_FOLDER="images/"
BSPFREEZE="yes"
# we are not building kernel
REPOSITORY_INSTALL="kernel"
elif [[ -n "${{ inputs.boardtype }}" ]]; then
FILENAME="targets.txt | grep ${var%:*}"
SKIP_EXTERNAL_TOOLCHAINS="no"
IGNORE_UPDATES="no"
REPOSITORY_INSTALL="kernel,armbian-config,armbian-firmware,armbian-zsh"
UPLOAD_FOLDER="images-csc/"
else
SKIP_EXTERNAL_TOOLCHAINS="yes"
IGNORE_UPDATES="yes"
BSPFREEZE="yes"
REPOSITORY_INSTALL="u-boot,kernel,armbian-bsp-cli,armbian-bsp-desktop,armbian-desktop,armbian-config,armbian-firmware,armbian-zsh"
UPLOAD_FOLDER="images/"
fi
#### we need to install all from repo since we don't drag compilers here
#### REPOSITORY_INSTALL="u-boot,kernel,armbian-config,armbian-firmware,armbian-zsh"
echo "DEPLOYFOLDER=$MAKE_FOLDERS" >> $GITHUB_ENV
var="${{ inputs.variant }}"
CHUNK="${{ matrix.node }}"
LINE=$(echo $CHUNK | cut -d":" -f1)
BOARD=$(echo $CHUNK | cut -d":" -f2)
echo "BOARD=$BOARD" >> $GITHUB_ENV
echo "VERSION=$(cat build/VERSION)" >> $GITHUB_ENV
# community builds are weekly
if [[ -n "${{ inputs.boardtype }}" ]]; then
echo "VERSION=$(date +%Y%U)" >> $GITHUB_ENV
fi
LINIJA="cat ${FILENAME} | grep -v \"^$\" | grep -v \"^#\" | ${{ inputs.include }} ${{ inputs.exclude }} sed -n ''$LINE'p'"
read -r BOARD BRANCH RELEASE BUILD_TARGET BUILD_STABILITY BUILD_IMAGE DESKTOP_ENVIRONMENT DESKTOP_ENVIRONMENT_CONFIG_NAME DESKTOP_APPGROUPS_SELECTED \
<<< $(eval $LINIJA)
DESKTOP_APPGROUPS_SELECTED="${DESKTOP_APPGROUPS_SELECTED//,/ }"
BUILD_DESKTOP="no"
BUILD_MINIMAL="no"
[[ ${BUILD_TARGET} == "desktop" ]] && BUILD_DESKTOP="yes"
[[ ${BUILD_TARGET} == "minimal" ]] && BUILD_MINIMAL="yes"
cd build
[[ ! -f .ignore_changes ]] && sudo touch .ignore_changes
sudo sed -i "s/-it --rm/-i --rm/" userpatches/config-docker.conf
./compile.sh docker \
BETA="${{ env.BETA }}" \
RELEASE="${RELEASE}" \
KERNEL_ONLY="no" \
BSPFREEZE="${BSPFREEZE}" \
INSTALL_HEADERS="${INSTALL_HEADERS}" \
SKIP_EXTERNAL_TOOLCHAINS="$SKIP_EXTERNAL_TOOLCHAINS" \
IGNORE_UPDATES="${IGNORE_UPDATES}" \
SYNC_CLOCK="no" \
DESKTOP_ENVIRONMENT_CONFIG_NAME="$DESKTOP_ENVIRONMENT_CONFIG_NAME" \
BUILD_DESKTOP="$BUILD_DESKTOP" \
BUILD_MINIMAL="$BUILD_MINIMAL" \
DESKTOP_ENVIRONMENT="${DESKTOP_ENVIRONMENT}" \
KERNEL_CONFIGURE="no" \
BOARD="$BOARD" \
LOG_SUBPATH="debug/$BOARD" \
BRANCH="$BRANCH" \
MAKE_FOLDERS="$MAKE_FOLDERS" \
IMAGE_PRESENT="no" \
BUILD_ALL="no" \
USE_TORRENT="yes" \
USE_MAINLINE_GOOGLE_MIRROR="yes" \
ARMBIAN_CACHE_TOOLCHAIN_PATH="${ARMBIAN_CACHE_TOOLCHAIN_PATH}" \
ARMBIAN_CACHE_ROOTFS_PATH="${ARMBIAN_CACHE_ROOTFS_PATH}" \
REPOSITORY_INSTALL="$REPOSITORY_INSTALL" \
DESKTOP_APPGROUPS_SELECTED="$DESKTOP_APPGROUPS_SELECTED" \
EXPERT="yes"
sudo chown -R $USER.$USER output/images/$BOARD 2> /dev/null || true
sudo chmod 644 output/images/$BOARD/*/*.xz 2> /dev/null || true
echo ${{ secrets.GPG_PASSPHRASE1 }} | gpg --passphrase-fd 0 --armor --detach-sign --pinentry-mode loopback --batch --yes output/images/$BOARD/$MAKE_FOLDERS/*.img.xz
- name: Install SSH key for storage
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY_TORRENTS }}
known_hosts: ${{ secrets.KNOWN_HOSTS_UPLOAD }}
if_key_exists: replace
- name: "Upload artefacts 1"
uses: ncipollo/release-action@v1
if: ${{ github.repository_owner == 'Armbian' && inputs.uploading != 'true' && github.event.inputs.choice != 'stable' && github.event.inputs.choice != 'rc' }}
with:
artifacts: "build/output/images/${{ env.BOARD }}/${{ env.DEPLOYFOLDER }}/*"
#tag: "latest"
tag: "${{ env.VERSION }}"
omitBody: true
omitName: true
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Upload artefacts 2"
if: inputs.uploading == 'true'
uses: ncipollo/release-action@v1
with:
artifacts: "build/output/images/${{ env.BOARD }}/${{ env.DEPLOYFOLDER }}/*"
tag: "${{ env.VERSION }}"
omitBody: true
replacesArtifacts: true
omitName: true
allowUpdates: true
token: ${{ secrets.CR_PAT }}
- name: Deploy to server
if: ${{ github.repository_owner == 'Armbian' && (github.event.inputs.choice == 'stable' || github.event.inputs.choice == 'rc') }}
run: |
ls -l build/output/images/*/*/
sudo apt-get -y -qq install lftp
lftp -u upload, -e "set net:timeout 4;set net:max-retries 6;mirror --Remove-source-files -R --no-empty-dirs --parallel=8 --no-perms $(pwd)/build/output/images/ ${UPLOAD_FOLDER} ;bye" sftp://users.armbian.com