Skip to content

CI: sync code

CI: sync code #82

Workflow file for this run

name: Build packages
on:
push:
paths:
- luci/**
- package/**
workflow_dispatch:
inputs:
packages:
type: string
description: "empty only build changed or input special package names or input all will build all"
debug:
type: boolean
default: false
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
archs: ${{ steps.set_env.outputs.archs }}
openwrt_branch: ${{ steps.set_env.outputs.openwrt_branch }}
openwrt_branch_number: ${{ steps.set_env.outputs.openwrt_branch_number }}
openwrt_builder_volume: ${{ steps.set_env.outputs.openwrt_builder_volume }}
artifact_packages_rel: ${{ steps.set_env.outputs.artifact_packages_rel }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set env
id: set_env
run: |
openwrt_branch="${GITHUB_REF#refs/heads/}"
openwrt_branch_number=$(echo $openwrt_branch | sed 's|openwrt-||')
artifact_packages_rel=releases/packages-${openwrt_branch_number}
if [ "${openwrt_branch}" == "main" ];then
artifact_packages_rel=snapshots/packages
fi
echo "openwrt_branch=${openwrt_branch}" >> "$GITHUB_OUTPUT"
echo "openwrt_branch_number=${openwrt_branch_number}" >> "$GITHUB_OUTPUT"
echo "artifact_packages_rel=${artifact_packages_rel}" >> "$GITHUB_OUTPUT"
echo "openwrt_builder_volume=${{ vars.OPENWRT_BUILDER_VOLUME }}" >> "$GITHUB_OUTPUT"
python3 -B ./.github/workflows/scripts/get_targets.py | while read v;do echo "$v" >> "$GITHUB_OUTPUT"; done
build:
name: Build ${{ matrix.arch }}
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
matrix:
arch: ${{fromJson(needs.setup.outputs.archs)}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine packages
run: |
PACKAGES=
INPUT_PACKAGES="${{ inputs.packages }}"
if [[ "$INPUT_PACKAGES" =~ "luci" ]];then
PACKAGES+="luci-base "
fi
if [[ ! "$INPUT_PACKAGES" =~ "all" ]];then
# only detect packages with changes
PKG_ROOTS=$(find . -name Makefile | grep -v ".*/src/Makefile" | sed -e 's@./\(.*\)/Makefile@\1/@')
CHANGES=$(git diff --diff-filter=d --name-only ${{ github.event_name == 'push' && 'HEAD^' || '' }})
for ROOT in $PKG_ROOTS; do
for CHANGE in $CHANGES; do
if [[ "$CHANGE" == "$ROOT"* ]]; then
PACKAGES+=$(echo "$ROOT" | sed -e 's@.*/\(.*\)/@\1 @')
break
fi
done
done
for t in $INPUT_PACKAGES;do
flag=false
for s in $PACKAGES;do
if [[ "$t" == "$s" ]]; then
flag=true
break
fi
done
if [ $flag == "false" ];then
PACKAGES+="$t "
fi
done
PACKAGES="${PACKAGES:-luci-app-attendedsysupgrade}"
fi
echo "Building $PACKAGES"
echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
- name: Build
uses: openwrt/gh-action-sdk@v7
env:
ARCH: ${{ matrix.arch }}-${{ needs.setup.outputs.openwrt_branch }}
FEEDNAME: packages_ci
V: ${{ inputs.debug && 's' || '' }}
- name: Move created packages to project dir
run: |
ls -alR bin/packages
artifact_dir=bin/artifact/${{ matrix.arch }}/plugin
mkdir -p ${artifact_dir}
find bin/packages/${{ matrix.arch }}/packages_ci \( -name "*.ipk" -o -name "*.apk" \) -exec cp -rv {} ${artifact_dir} \; || true
- name: Store packages
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.arch }}-packages
path: bin/artifact/
- name: Store logs
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.arch }}-logs
path: "logs/"
deploy:
name: Deploy
runs-on: self-hosted
needs: [setup,build]
if: always()
container:
image: openwrt/sdk:x86-64-${{ needs.setup.outputs.openwrt_branch }}
volumes:
- openwrt-sdk-x86-64-${{ needs.setup.outputs.openwrt_branch }}:/builder
- ${{ needs.setup.outputs.openwrt_builder_volume }}/:/data/
options: --user root --privileged --pull always
steps:
- name: Set env
id: set_env
shell: bash
run: |
download_packages_dir=/data/download/${{ needs.setup.outputs.artifact_packages_rel }}
echo "download_packages_dir=${download_packages_dir}" >> "$GITHUB_OUTPUT"
- name: Setup
working-directory: /builder
shell: su buildbot -c "bash {0}"
run: |
mkdir -p ${{ steps.set_env.outputs.download_packages_dir }}
openwrt_mirror=https://mirrors.pku.edu.cn/openwrt
[ ! -f setup.sh ] || UPSTREAM_URL=${openwrt_mirror} bash setup.sh
make defconfig
- name: Download artifact
uses: actions/download-artifact@v4
with:
path: ${{ steps.set_env.outputs.download_packages_dir }}
pattern: '*-packages'
merge-multiple: true
- name: Modify permission
run: chown -R buildbot:buildbot ${{ steps.set_env.outputs.download_packages_dir }}
- name: Generate index
working-directory: /builder
shell: su buildbot -c "bash {0}"
run: |
sed -i -e 's|--sign $(BUILD_KEY_APK_SEC)|--allow-untrusted|' package/Makefile
for t in $(find ${{ steps.set_env.outputs.download_packages_dir }} -type d -name 'plugin');do
echo "Generating index for package ${t}"
make -j4 package/index V=s CONFIG_SIGNED_PACKAGES= PACKAGE_SUBDIRS=$t
done
clean:
name: Clean
runs-on: self-hosted
needs: [setup,build,deploy]
if: always()
steps:
- run: |
volume_names=$(docker volume ls -q | grep 'openwrt-sdk-x86-64-${{ needs.setup.outputs.openwrt_branch }}$' || true | xargs )
if [ -n "${volume_names}" ];then
docker volume rm $volume_names
fi