Rebuild #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rebuild | |
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 | |
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: | |
TPATH: '' | |
CONFBRANCH: 'conf' | |
TARGETBRANCH: ${{ inputs.version }}-${{ inputs.board }}-${{ inputs.subtarget }} | |
VERSION: ${{ inputs.version }} | |
BOARD: ${{ inputs.board }} | |
SUBTARGET: ${{ inputs.subtarget }} | |
USIGN_ID: ${{ vars.USIGN_ID }} | |
USIGN_KEY: ${{ secrets[format('USIGN_{0}', vars.USIGN_ID )] }} | |
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: Check can be build | |
shell: bash | |
run: | | |
rcode=$(curl -sL -w '%{http_code}' -o /dev/null https://github.com/$GITHUB_REPOSITORY/raw/$CONFBRANCH/$VERSION/$BOARD/$SUBTARGET/config.buildinfo) | |
echo rcode: $rcode | |
[ "$rcode" != "404" ] || { >&2 echo No config.buildinfo can be build.; 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 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 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.CONFBRANCH }} | |
- 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 v23.05.3 https://github.com/openwrt/openwrt.git openwrt | |
# .config | |
curl -Lo openwrt/.config "https://github.com/$GITHUB_REPOSITORY/raw/$CONFBRANCH/$VERSION/$BOARD/$SUBTARGET/config.buildinfo" | |
# key-build | |
echo "$USIGN_KEY" > openwrt/key-build | |
echo "$USIGN_PUBKEY" > openwrt/key-build.pub | |
# prebuilt LLVM toolchain | |
op_target_url_prefix="https://downloads.openwrt.org/releases/$VERSION/targets/$BOARD/$SUBTARGET" | |
sha256sums="$(curl -L "${op_target_url_prefix}/sha256sums")" | |
curl -Lo llvm-bpf.tar.xz "${op_target_url_prefix}/$(echo "$sha256sums" | sed -n '/\bllvm\b/{s|^[[:xdigit:]]*\s*\*||;p}')" | |
tar -xJf llvm-bpf.tar.xz -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 "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)}') | |
cd .. | |
done | |
popd | |
installs='coova-chilli macremapper mdio-netlink jool' | |
echo installs: $installs | |
scripts/feeds install $installs | |
endgroup | |
# | |
group "make defconfig" | |
make defconfig | |
endgroup | |
# | |
group "make prepare -j$NPROC" | |
make prepare -j$NPROC | |
endgroup | |
# | |
group "make package/compile V=s -j$NPROC" | |
make package/compile V=s -j$NPROC | |
endgroup | |
# | |
group "make package/install -j$NPROC" | |
make package/install -j$NPROC | |
endgroup | |
# | |
group "install fantastic feed" | |
for p in build_dir staging_dir; do | |
pushd $p/target-*/root-$BOARD/etc/opkg | |
echo "$USIGN_PUBKEY" > keys/${USIGN_ID,,} | |
sed -i "/src\/gz openwrt_core /{ \ | |
s|downloads.openwrt.org/releases/$VERSION|github.com/$GITHUB_REPOSITORY/raw/$TARGETBRANCH| \ | |
}" distfeeds.conf | |
popd | |
done | |
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/$BOARD/$SUBTARGET/packages/ | |
git add targets/$BOARD/$SUBTARGET/*.buildinfo | |
git add targets/$BOARD/$SUBTARGET/*.json | |
git add targets/$BOARD/$SUBTARGET/*.manifest | |
git add targets/$BOARD/$SUBTARGET/sha256sums | |
#git commit -m "Upload packages" | |
#git push | |
git add targets/$BOARD/$SUBTARGET/*-imagebuilder-*.* | |
#git commit -m "Upload imagebuilder" | |
#git push | |
pushd targets/$BOARD/$SUBTARGET | |
sdkname=$(basename *-sdk-*.*) | |
split -b 80m $sdkname ${sdkname}. | |
popd | |
git add targets/$BOARD/$SUBTARGET/${sdkname}.* | |
#git commit -m "Upload sdk" | |
#git push | |
git commit -m "Upload packages imagebuilder sdk" | |
git push | |
rm -f targets/$BOARD/$SUBTARGET/${sdkname}.* | |
- name: Upload artifact (All) | |
if: ${{ steps.push_packages.outcome == 'success' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: target-${{ env.VERSION }}-${{ env.BOARD }}-${{ env.SUBTARGET }}-all | |
path: | | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/ | |
!targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/packages/ | |
- name: Upload artifact (Image files) | |
if: ${{ steps.push_packages.outcome == 'success' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: target-${{ env.VERSION }}-${{ env.BOARD }}-${{ env.SUBTARGET }}-image | |
path: | | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/*.bin | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/*.img | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/*.img.* | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/*-kernel.* | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/*-uImage.* | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/*-rootfs.* | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/*-factory.* | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/*-recovery.* | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/*-sysupgrade.* | |
- name: Upload artifact (Supplementary files) | |
if: ${{ steps.push_packages.outcome == 'success' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: target-${{ env.VERSION }}-${{ env.BOARD }}-${{ env.SUBTARGET }}-supplementary | |
path: | | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/kernel-debug.* | |
- name: Upload artifact (Image Builder) | |
if: ${{ steps.push_packages.outcome == 'success' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: target-${{ env.VERSION }}-${{ env.BOARD }}-${{ env.SUBTARGET }}-IB | |
path: | | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/*-imagebuilder-*.* | |
- name: Upload artifact (SDK) | |
if: ${{ steps.push_packages.outcome == 'success' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: target-${{ env.VERSION }}-${{ env.BOARD }}-${{ env.SUBTARGET }}-SDK | |
path: | | |
targets/${{ env.BOARD }}/${{ env.SUBTARGET }}/*-sdk-*.* |