Skip to content

CI: sync code

CI: sync code #69

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_dir: ${{ steps.set_env.outputs.openwrt_dir }}
openwrt_branch: ${{ steps.set_env.outputs.openwrt_branch }}
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_dir=/data/openwrt
openwrt_branch="${GITHUB_REF#refs/heads/}"
echo "openwrt_dir=${openwrt_dir}" >> "$GITHUB_OUTPUT"
echo "openwrt_branch=${openwrt_branch}" >> "$GITHUB_OUTPUT"
openwrt_builder_volume=${{ vars.OPENWRT_BUILDER_VOLUME }}
echo "openwrt_builder_volume=${openwrt_builder_volume}" >> "$GITHUB_OUTPUT"
artifact_packages_rel=releases/packages-$(echo $openwrt_branch | sed 's|openwrt-||')
if [ "${openwrt_branch}" == "main" ];then
artifact_packages_rel=snapshots/packages
fi
echo "artifact_packages_rel=${artifact_packages_rel}" >> "$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: |
EXTRA_FEEDS="src-git|openclash|https://github.com/vernesong/OpenClash.git;master"
echo "EXTRA_FEEDS=$EXTRA_FEEDS" >> $GITHUB_ENV
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}
for t in $PACKAGES;do
find bin/packages/${{ matrix.arch }}/packages \( -name "$t*.ipk" -o -name "$t*.apk" \) -exec cp -rv {} ${artifact_dir} \; || true
done
for EXTRA_FEED in $EXTRA_FEEDS; do
EXTRA_FEED_NAME="$(echo "$EXTRA_FEED" | cut -d'|' -f2)"
find bin/packages/${{ matrix.arch }}/$EXTRA_FEED_NAME \( -name "*.ipk" -o -name "*.apk" \) -exec cp -rv {} ${artifact_dir} \; || true
done
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: Setup
working-directory: /builder
shell: su buildbot -c "bash {0}"
run: |
openwrt_mirror=https://mirrors.pku.edu.cn/openwrt
[ ! -f setup.sh ] || UPSTREAM_URL=${openwrt_mirror} bash setup.sh
make defconfig
mkdir -p /data/download/${{ needs.setup.outputs.artifact_packages_rel }}
- name: Download artifact
uses: actions/download-artifact@v4
with:
path: /data/download/${{ needs.setup.outputs.artifact_packages_rel }}
pattern: '*-packages'
merge-multiple: true
- 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 /data/download/${{ needs.setup.outputs.artifact_packages_rel }} -type d -name 'plugin');do
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