Skip to content

Build Image

Build Image #2

Workflow file for this run

name: Build Image
on:
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true
default: '23.05.3'
type: string
board:
description: 'Device board'
required: true
default: 'x86'
type: string
subtarget:
description: 'Device subtarget'
required: true
default: '64'
type: string
profile:
description: 'Device profile'
required: true
default: 'generic'
type: string
arch:
description: 'Device architecture'
required: true
default: 'x86_64'
type: string
env:
DELETE_USELESS_FILES: false
jobs:
build_image:
name: build_image ${{ inputs.version }}-${{ inputs.board }}-${{ inputs.subtarget }}-${{ inputs.profile }}
runs-on: ubuntu-latest
env:
CONFBRANCH: 'conf'
TARGETBRANCH: ${{ inputs.version }}-${{ inputs.board }}-${{ inputs.subtarget }}
VERSION: ${{ inputs.version }}
BOARD: ${{ inputs.board }}
SUBTARGET: ${{ inputs.subtarget }}
PROFILE: ${{ inputs.profile }}
ARCH: ${{ inputs.arch }}
USIGN_ID: ${{ vars.USIGN_ID }}
USIGN_KEY: ${{ secrets[format('USIGN_{0}', vars.USIGN_ID )] }}
ROOTFS_SIZE: 256
steps:
- name: Check if deployed
shell: bash
run: |
rcode=$(curl -sL -w '%{http_code}' -o /dev/null https://github.com/$GITHUB_REPOSITORY/tree/$TARGETBRANCH)
echo rcode: $rcode
[ "$rcode" != "404" ] || { >&2 echo Branch $TARGETBRANCH is not deployed, please build world first.; exit 1; }
- name: Import keys
env:
USIGN_PUBKEY_URL: https://github.com/$GITHUB_REPOSITORY_OWNER/packages/raw/master/keys/usign/${{ env.USIGN_ID }}.pub
shell: bash
run: |
# usign
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "USIGN_PUBKEY<<$EOF" >> $GITHUB_ENV
curl -sL "$USIGN_PUBKEY_URL" >> $GITHUB_ENV
echo "$EOF" >> $GITHUB_ENV
- name: Maximize build space
if: env.DELETE_USELESS_FILES == 'true' && !cancelled()
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 10240
swap-size-mb: 8192
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
- name: Initialize Environment
shell: bash
run: |
sudo apt update
sudo apt -y install build-essential clang flex bison g++ gawk \
gcc-multilib g++-multilib gettext git libncurses-dev libssl-dev \
python3-distutils rsync unzip zlib1g-dev file wget
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.TARGETBRANCH }}
- name: Determine packages be installed
shell: bash
run: |
INSTALLS=''
url="https://github.com/$GITHUB_REPOSITORY/raw/$CONFBRANCH/$VERSION/$BOARD/$SUBTARGET/preinstalled \
https://github.com/$GITHUB_REPOSITORY_OWNER/packages/raw/master/.github/workflows/prebuildpackages/generic \
https://github.com/$GITHUB_REPOSITORY_OWNER/packages/raw/master/.github/workflows/prebuildpackages/$ARCH"
for l in $url; do
if [ "$(curl -sL -w '%{http_code}' "$l" -o preinstalled)" != "404" ]; then
INSTALLS=${INSTALLS:+$INSTALLS }$(cat preinstalled 2>/dev/null)
else
>&2 echo URL: $l is not found.
fi
done
echo "Installing $INSTALLS"
echo "INSTALLS=$INSTALLS" >> $GITHUB_ENV
- name: Setup Image Builder
id: setup
shell: bash
run: |
tar -xf targets/$BOARD/$SUBTARGET/*-imagebuilder-*.*
pushd *-imagebuilder-*
# key-build
echo "$USIGN_KEY" > key-build
echo "$USIGN_PUBKEY" > key-build.pub
scripts/opkg-key add key-build.pub
# core feed
sed -i "/src\/gz openwrt_core /{ \
s|https://downloads.openwrt.org/releases/$VERSION|file://$GITHUB_WORKSPACE| \
}" repositories.conf
# fantastic feeds
n=$[ $(sed -n '/This is the local package repository/=' repositories.conf) -1 ]
sed -i "${n}i\
src/gz fantastic_packages https://github.com/$GITHUB_REPOSITORY_OWNER/packages/raw/gh-pages/releases/${VERSION%.*}/packages/$ARCH/packages\n\
src/gz fantastic_luci https://github.com/$GITHUB_REPOSITORY_OWNER/packages/raw/gh-pages/releases/${VERSION%.*}/packages/$ARCH/luci" \
repositories.conf
# ROOTFS_SIZE
sed -i "s|\(\bCONFIG_TARGET_ROOTFS_PARTSIZE\)=.*|\1=$ROOTFS_SIZE|" .config
- name: Build image
id: build_image
if: ${{ steps.setup.outcome == 'success' }}
shell: bash
run: |
echo "::group:: ls -R keys/"
ls -R keys/
echo "::endgroup::"
#
echo "::group:: repositories.conf"
cat repositories.conf
echo "::endgroup::"
#
echo "::group:: make image"
make image \
PROFILE="$PROFILE" \
DISABLED_SERVICES="$DISABLED_SERVICES" \
ADD_LOCAL_KEY="$ADD_LOCAL_KEY" \
PACKAGES="$INSTALLS"
echo "::endgroup::"
- name: Upload artifact (All)
if: ${{ steps.build_image.outcome == 'success' }}
uses: actions/upload-artifact@v4
with:
name: target-${{ env.VERSION }}-${{ env.BOARD }}-${{ env.SUBTARGET }}-${{ inputs.profile }}-all
path: |
bin/targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/