Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .github/scripts/sdk_package_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash
# Runs inside ghcr.io/openwrt/sdk:<arch>-<branch> as the buildbot user.
# /src is the checkout of the project, /artifacts receives apk/, logs/
# and sizes.txt.
#
# PACKAGE source package of the project in the feed, e.g. odhcpd
# PACKAGES binary packages to build, defaults to $PACKAGE
# FEED feed providing the source package, defaults to base

set -e

[ -n "$PACKAGE" ] || {
echo "::error::PACKAGE is not set"
exit 1
}

PACKAGES="${PACKAGES:-$PACKAGE}"
FEED="${FEED:-base}"
JOBS="${JOBS:-$(nproc)}"

group() {
echo "::group::$1"
}

endgroup() {
echo "::endgroup::"
}

group "setup.sh"
[ ! -f setup.sh ] || bash setup.sh
endgroup

git config --global --add safe.directory '*'

sed -n \
-e 's,https://git.openwrt.org/openwrt/,https://github.com/openwrt/,' \
-e 's,https://git.openwrt.org/feed/,https://github.com/openwrt/,' \
-e 's,https://git.openwrt.org/project/,https://github.com/openwrt/,' \
-e '/^src-git.* base /p' \
-e "/^src-git.* $FEED /p" \
feeds.conf.default | sort -u > feeds.conf

group "feeds"
cat feeds.conf
./scripts/feeds update -a
./scripts/feeds install "$PACKAGE"
endgroup

makefile="$(readlink -f "package/feeds/$FEED/$PACKAGE/Makefile")"
[ -f "$makefile" ] || {
echo "::error::$PACKAGE is not a source package of the $FEED feed"
exit 1
}

mkdir -p git-src
ln -sfn /src "git-src/$PACKAGE"

sed -i \
-e "s/^PKG_SOURCE_DATE:=.*/PKG_SOURCE_DATE:=$(git -C /src log -1 --format=%cd --date=format:%Y-%m-%d)/" \
-e "s/^PKG_SOURCE_VERSION:=.*/PKG_SOURCE_VERSION:=$(git -C /src rev-parse HEAD)/" \
-e '/^PKG_MIRROR_HASH:=/d' \
"$makefile"

for pkg in $PACKAGES; do
echo "CONFIG_PACKAGE_$pkg=m" >> .config
done

group "make defconfig"
make defconfig </dev/null
endgroup

for pkg in $PACKAGES; do
grep -qx "CONFIG_PACKAGE_$pkg=[ym]" .config || {
echo "::error::$pkg cannot be selected for $(sed -n 's/^CONFIG_TARGET_ARCH_PACKAGES="\(.*\)"/\1/p' .config)"
exit 1
}
done

RET=0
make -j"$JOBS" BUILD_LOG=1 IGNORE_ERRORS=n "package/$PACKAGE/compile" </dev/null || RET=$?

if [ "$RET" -ne 0 ]; then
for log in $(find logs -path "*/$PACKAGE/*" -name '*.txt' 2>/dev/null); do
echo "::group::$log"
tail -n 200 "$log"
echo "::endgroup::"
done
fi

mkdir -p /artifacts/apk
[ ! -d logs ] || cp -a logs /artifacts/
[ "$RET" -eq 0 ] || exit "$RET"

find bin/packages -name '*.apk' -exec cp {} /artifacts/apk/ \;
find bin/targets -path '*/packages/*.apk' ! -name 'kmod-*' ! -name 'kernel-*' \
-exec cp {} /artifacts/apk/ \;

for pkg in $PACKAGES; do
apk="$(find /artifacts/apk -name "$pkg-[0-9]*.apk")"
[ -n "$apk" ] || {
echo "::error::$pkg was not built"
exit 1
}
echo "$pkg $(stat -c %s "$apk")"
done > /artifacts/sizes.txt
119 changes: 119 additions & 0 deletions .github/workflows/sdk-package-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: SDK Package Build

on:
workflow_call:
inputs:
package:
description: 'Source package of the calling project in the feed, e.g. odhcpd'
required: true
type: string
packages:
description: 'Binary packages to build, space separated. Defaults to the source package.'
required: false
type: string
default: ''
feed:
description: 'Feed providing the source package'
required: false
type: string
default: 'base'
archs:
description: 'JSON array of SDK architectures'
required: false
type: string
default: >-
[
"x86_64",
"i386_pentium4",
"aarch64_generic",
"arm_cortex-a15_neon-vfpv4",
"mips_24kc",
"mipsel_24kc",
"powerpc_8548",
"riscv64_generic"
]
sdk_branch:
description: 'OpenWrt branch of the SDK containers'
required: false
type: string
default: 'master'

permissions:
contents: read

jobs:
build:
name: Build ${{ matrix.arch }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: ${{ fromJSON(inputs.archs) }}

steps:
- name: Checkout
uses: actions/checkout@v7
with:
path: source

- name: Checkout build script
uses: actions/checkout@v7
with:
repository: openwrt/actions-shared-workflows
path: workflow_context
sparse-checkout: |
.github/scripts/sdk_package_build.sh
sparse-checkout-cone-mode: false

- name: Build
env:
ARTIFACTS: ${{ runner.temp }}/artifacts
FEED: ${{ inputs.feed }}
PACKAGE: ${{ inputs.package }}
PACKAGES: ${{ inputs.packages }}
SDK: ghcr.io/openwrt/sdk:${{ matrix.arch }}-${{ inputs.sdk_branch }}
run: |
mkdir -p "$ARTIFACTS"
sudo chown -R 1000:1000 "$GITHUB_WORKSPACE/source" "$ARTIFACTS"
docker run --rm \
--env FEED \
--env PACKAGE \
--env PACKAGES \
--volume "$GITHUB_WORKSPACE/source:/src" \
--volume "$GITHUB_WORKSPACE/workflow_context/.github/scripts:/ci:ro" \
--volume "$ARTIFACTS:/artifacts" \
"$SDK" \
/ci/sdk_package_build.sh

- name: Restore ownership
if: always()
env:
ARTIFACTS: ${{ runner.temp }}/artifacts
run: sudo chown -R "$(id -u):$(id -g)" "$GITHUB_WORKSPACE/source" "$ARTIFACTS"

- name: Sizes
env:
ARCH: ${{ matrix.arch }}
ARTIFACTS: ${{ runner.temp }}/artifacts
run: |
{
echo "### $ARCH"
echo "| package | apk size |"
echo "| :--- | ---: |"
awk '{ printf "| %s | %s |\n", $1, $2 }' "$ARTIFACTS/sizes.txt"
} >> "$GITHUB_STEP_SUMMARY"

- name: Upload packages
uses: actions/upload-artifact@v7
with:
name: packages-${{ matrix.arch }}
path: ${{ runner.temp }}/artifacts/apk/
if-no-files-found: error

- name: Upload logs
if: failure()
uses: actions/upload-artifact@v7
with:
name: logs-${{ matrix.arch }}
path: ${{ runner.temp }}/artifacts/logs/
if-no-files-found: ignore
Loading