Skip to content

Rebuild

Rebuild #113

Workflow file for this run

name: Rebuild
on:
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true
default: '23.05.5|24.10.0-rc4|SNAPSHOT'
type: string
board:
description: 'Device board'
required: true
default: 'x86'
type: string
subtarget:
description: 'Device subtarget'
required: true
default: '64'
type: string
workflow_call:
inputs:
version:
required: true
type: string
board:
required: true
type: string
subtarget:
required: true
type: string
env:
DELETE_USELESS_FILES: true
jobs:
build_world:
name: build_world ${{ inputs.version }}-${{ inputs.board }}-${{ inputs.subtarget }}
runs-on: ubuntu-latest
permissions:
contents: write # To push a branch
env:
MIRROR_URL: 'https://downloads.openwrt.org'
CONFBRANCH: 'conf'
TARGETBRANCH: ${{ inputs.version }}-${{ inputs.board }}-${{ inputs.subtarget }}
OP_VERSION: ${{ inputs.version }}
USIGN_ID: ${{ vars.USIGN_ID }}
USIGN_KEY: ${{ secrets[format('USIGN_{0}', vars.USIGN_ID )] }}
USIGN_PUBKEY: ${{ vars[format('USIGN_PUB_{0}', vars.USIGN_ID )] }}
SINGLE_FILE_LIMIT: 80
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" ] || { echo "DEPLOYED=y" >> $GITHUB_ENV; }
- name: Determine branch name and Generate op_target_url_prefix
shell: bash
run: |
SNAPSHOTS=$(echo "$OP_VERSION" | grep -q SNAPSHOT && { [ "$OP_VERSION" = "SNAPSHOT" ] && echo y || echo i; } || echo )
echo "SNAPSHOTS=$SNAPSHOTS" >> $GITHUB_ENV
SNAPSHOTS_BRANCH="$(echo "$OP_VERSION" | sed -En 's|^(.+)-SNAPSHOT$|\1|p')"
echo "SNAPSHOTS_BRANCH=$SNAPSHOTS_BRANCH" >> $GITHUB_ENV
BRANCH="$([ -n "$SNAPSHOTS_BRANCH" ] && echo "$SNAPSHOTS_BRANCH" || echo "${OP_VERSION%.*}")"
echo "Building for $BRANCH"
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
op_target_url_prefix="$MIRROR_URL/$([ -n "$SNAPSHOTS" ] && echo snapshots || echo "releases/$OP_VERSION")/targets/${{ inputs.board }}/${{ inputs.subtarget}}"
echo "op_target_url_prefix=$op_target_url_prefix" >> $GITHUB_ENV
- name: Check raw config.buildinfo
shell: bash
run: |
rcode=$(curl -sL -w '%{http_code}' -o /dev/null "${op_target_url_prefix}/config.buildinfo")
echo rcode: $rcode
[ "$rcode" != "404" ] || { >&2 echo No raw config.buildinfo exist.; exit 1; }
- 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 axel build-essential ccache clang curl flex bison g++ gawk \
gcc-multilib g++-multilib genisoimage gettext git libdw-dev libelf-dev \
libncurses5-dev libssl-dev locales pv pwgen python3 python3-pip \
python3-setuptools qemu-utils rsync signify-openbsd subversion swig unzip \
zlib1g-dev file wget zstd python3-venv python3-pyelftools python3-cryptography \
llvm libbpf-dev pkg-config
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.CONFBRANCH }}
- name: Get buildinfo.sh / faillogs.txt path
shell: bash
run: |
sel_config() {
if [ -f "$2/${{ inputs.board }}/${{ inputs.subtarget}}/$3" ]; then
eval $1="$2/${{ inputs.board }}/${{ inputs.subtarget}}/$3"
elif [ -f "$2/${{ inputs.board }}/$3" ]; then
eval $1="$2/${{ inputs.board }}/$3"
elif [ -f "$2/$3" ]; then
eval $1="$2/$3"
else
return 1
fi
}
#
config=''
if [ -n "$SNAPSHOTS" ]; then
sel_config config "$BRANCH" buildinfo.sh ||
sel_config config "snapshots" buildinfo.sh ||
sel_config config "default" buildinfo.sh ||
{ >&2 echo No buildinfo.sh can be build.; exit 1; }
else
sel_config config "$OP_VERSION" buildinfo.sh ||
sel_config config "$BRANCH" buildinfo.sh ||
sel_config config "default" buildinfo.sh ||
{ >&2 echo No buildinfo.sh can be build.; exit 1; }
fi
echo "config='$config'"
echo "config=$config" >> $GITHUB_ENV
#
faillogs=''
if [ -n "$SNAPSHOTS" ]; then
sel_config faillogs "$BRANCH" faillogs.txt ||
sel_config faillogs "snapshots" faillogs.txt ||
sel_config faillogs "default" faillogs.txt || sleep 0
else
sel_config faillogs "$OP_VERSION" faillogs.txt ||
sel_config faillogs "$BRANCH" faillogs.txt ||
sel_config faillogs "default" faillogs.txt || sleep 0
fi
echo "faillogs='$faillogs'"
echo "faillogs=$faillogs" >> $GITHUB_ENV
- name: Checkout to TARGETBRANCH ${{ env.TARGETBRANCH }}
id: checkout_to_targetbranch
shell: bash
run: |
git config --local user.name "GitHub Action"
git config --local user.email "[email protected]"
#
if [ "$DEPLOYED" = "y" ]; then
git fetch --depth=1 origin $TARGETBRANCH
git checkout -b $TARGETBRANCH --track origin/$TARGETBRANCH
rm -rf *
git add .
else
git checkout --orphan $TARGETBRANCH
git reset .
git commit -m '' --allow-empty --allow-empty-message
git push --set-upstream origin $TARGETBRANCH
fi
- name: Initialize Openwrt Environment
id: init_openwrt_env
if: ${{ steps.checkout_to_targetbranch.outcome == 'success' }}
shell: bash
run: |
git clone --depth 1 --branch $([ -z "$SNAPSHOTS" ] && echo "v$OP_VERSION" || { [ "$SNAPSHOTS" = "i" ] && echo "openwrt-$BRANCH" || echo main; }) \
https://github.com/openwrt/openwrt.git openwrt
# .config
curl -Lo openwrt/.config "${op_target_url_prefix}/config.buildinfo"
git checkout origin/$CONFBRANCH -- "$config" 2>/dev/null || echo
sudo chmod +x "$config"
"$config" openwrt/.config
git reset HEAD "$config"
# key-build
echo "$USIGN_KEY" > openwrt/key-build
echo "$USIGN_PUBKEY" > openwrt/key-build.pub
# prebuilt LLVM toolchain
sha256sums="$(curl -L "${op_target_url_prefix}/sha256sums")"
llvm_bpf="$(sed -n '/\bllvm\b/{s|^[[:xdigit:]]*\s*\*||;p}' <<< "$sha256sums")"
axel -q -n8 "${op_target_url_prefix}/${llvm_bpf}"
tar $(echo "$llvm_bpf" | grep -qE '\.tar\.zst$' && echo '-I zstd') -xf "$llvm_bpf" -C openwrt/
- name: Build world
id: build_world
if: ${{ steps.init_openwrt_env.outcome == 'success' }}
shell: bash
run: |
group() {
endgroup
echo "::group:: $1"
GROUP=1
}
endgroup() {
if [ -n "$GROUP" ]; then
echo "::endgroup::"
fi
GROUP=
}
trap 'endgroup' ERR
NPROC=$(nproc)
sudo chown -R $USER:$GROUPS openwrt
pushd openwrt
#
group "echo start"
echo start
endgroup
#
group "scripts/feeds update -a"
scripts/feeds update -a
endgroup
#
group "scripts/feeds install <External KernelPackage>"
extfeeds=$(grep '^src-git ' feeds.conf.default | awk '{print $2}' | grep -v luci | tr '\n' ' ')
installs=''
pushd feeds
for feed in $extfeeds; do
cd $feed
installs=${installs:+$installs }$(grep -Er "\\$+\(eval \\$+\(call KernelPackage," | awk -F ':' '{print $1}' | sort -u | awk -F '/' '{print $(NF-1)}' || echo)
cd ..
done
popd
faillogs=$(curl -sL "https://github.com/$GITHUB_REPOSITORY/raw/$CONFBRANCH/$faillogs" | tr '\n' ' ' | sed 's|^\s*||;s|\s*$||')
installs=$(echo "$installs" | tr ' ' '\n' | grep -v '^$' | grep -Ev "^$(echo "$faillogs" | sed -E 's,\s+,|,g;s|^|\(|;s|$|\)|')$")
echo installs: $installs
scripts/feeds install $installs
endgroup
#
group "make defconfig"
make defconfig
# 23.05.4+
echo -e 'CONFIG_KERNEL_DEBUG_INFO_BTF_MODULES=y\nCONFIG_KERNEL_MODULE_ALLOW_BTF_MISMATCH=y' >> .config || sleep 0
endgroup
#
group "make prepare -j$NPROC"
make prepare -j$NPROC
endgroup
#
group "make package/compile V=s -j$NPROC IGNORE_ERRORS=1"
make package/compile V=s -j$NPROC IGNORE_ERRORS=1
endgroup
#
group "make package/install -j$NPROC"
make package/install -j$NPROC
endgroup
#
group "make target/install -j$NPROC"
make target/install -j$NPROC
endgroup
#
group "finishing work"
make package/index
make json_overview_image_info
make checksum
endgroup
#
popd
- name: Push packages
id: push_packages
if: ${{ steps.build_world.outcome == 'success' || steps.checkout_to_targetbranch.outcome == 'success' }}
shell: bash
run: |
mv openwrt/bin/* ./
git add packages/ # Non-essential
git add targets/${{ inputs.board }}/${{ inputs.subtarget}}/packages/
git add targets/${{ inputs.board }}/${{ inputs.subtarget}}/*.buildinfo
git add targets/${{ inputs.board }}/${{ inputs.subtarget}}/*.json
git add targets/${{ inputs.board }}/${{ inputs.subtarget}}/*.manifest
git add targets/${{ inputs.board }}/${{ inputs.subtarget}}/sha256sums
#git commit -m "Upload packages"
#git push
pushd targets/${{ inputs.board }}/${{ inputs.subtarget}}
if [ $(wc -c *-imagebuilder-*.* | awk '{print $1}') -gt $(( $SINGLE_FILE_LIMIT * 1024 ** 2 )) ]; then
ibname=$(basename *-imagebuilder-*.*)
split -b ${SINGLE_FILE_LIMIT}m $ibname ${ibname}.
git add ${ibname}.*
else
git add *-imagebuilder-*.*
fi
popd
#git commit -m "Upload imagebuilder"
#git push
pushd targets/${{ inputs.board }}/${{ inputs.subtarget}}
if [ $(wc -c *-sdk-*.* | awk '{print $1}') -gt $(( $SINGLE_FILE_LIMIT * 1024 ** 2 )) ]; then
sdkname=$(basename *-sdk-*.*)
split -b ${SINGLE_FILE_LIMIT}m $sdkname ${sdkname}.
git add ${sdkname}.*
else
git add *-sdk-*.*
fi
popd
#git commit -m "Upload sdk"
#git push
git commit -m "Upload packages imagebuilder sdk"
git push
rm -f targets/${{ inputs.board }}/${{ inputs.subtarget}}/${sdkname}.*
- name: Upload artifact (All)
if: ${{ steps.push_packages.outcome == 'success' }}
uses: actions/upload-artifact@v4
with:
name: target-${{ env.OP_VERSION }}-${{ inputs.board }}-${{ inputs.SUBTARGET }}-all
path: |
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/
!targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/packages/
- name: Upload artifact (Image files)
if: ${{ steps.push_packages.outcome == 'success' }}
uses: actions/upload-artifact@v4
with:
name: target-${{ env.OP_VERSION }}-${{ inputs.board }}-${{ inputs.SUBTARGET }}-image
path: |
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/*.bin
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/*.img
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/*.img.*
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/*-kernel.*
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/*-uImage.*
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/*-rootfs.*
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/*-factory.*
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/*-recovery.*
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/*-sysupgrade.*
- name: Upload artifact (Supplementary files)
if: ${{ steps.push_packages.outcome == 'success' }}
uses: actions/upload-artifact@v4
with:
name: target-${{ env.OP_VERSION }}-${{ inputs.board }}-${{ inputs.SUBTARGET }}-supplementary
path: |
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/kernel-debug.*
- name: Upload artifact (Image Builder)
if: ${{ steps.push_packages.outcome == 'success' }}
uses: actions/upload-artifact@v4
with:
name: target-${{ env.OP_VERSION }}-${{ inputs.board }}-${{ inputs.SUBTARGET }}-IB
path: |
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/*-imagebuilder-*.*
- name: Upload artifact (SDK)
if: ${{ steps.push_packages.outcome == 'success' }}
uses: actions/upload-artifact@v4
with:
name: target-${{ env.OP_VERSION }}-${{ inputs.board }}-${{ inputs.SUBTARGET }}-SDK
path: |
targets/${{ inputs.board }}/${{ inputs.SUBTARGET }}/*-sdk-*.*