Skip to content

Build images

Build images #62

Workflow file for this run

name: Build images
on:
workflow_dispatch:
inputs:
openwrt_tag:
type: string
description: "eg: v23.05.5"
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
targets: ${{ steps.set_env.outputs.targets }}
targets_subtargets: ${{ steps.set_env.outputs.targets_subtargets }}
targets_devices: ${{ steps.set_env.outputs.targets_devices }}
archs: ${{ steps.set_env.outputs.archs }}
openwrt_tag: ${{ steps.set_env.outputs.openwrt_tag }}
openwrt_tag_version: ${{ steps.set_env.outputs.openwrt_tag_version }}
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_targets_rel: ${{ steps.set_env.outputs.artifact_targets_rel }}
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-||')
openwrt_tag=${{ inputs.openwrt_tag }}
artifact_targets_rel=
artifact_packages_rel=
if [ "${openwrt_branch}" == "main" ];then
openwrt_tag=$openwrt_branch
artifact_targets_rel=snapshots/targets
artifact_packages_rel=snapshots/packages
else
openwrt_tag=${openwrt_tag:-$(curl -sL 'https://git.openwrt.org/?p=openwrt/openwrt.git;a=summary' | sed -n "s|.*OpenWrt \(v${openwrt_branch_number}.*\) Release.*|\1|p" | head -n 1)}
openwrt_tag_version=$(echo $openwrt_tag | sed 's|^v||')
artifact_targets_rel=releases/$openwrt_tag_version/targets
artifact_packages_rel=releases/packages-${openwrt_branch_number}
fi
echo "openwrt_builder_volume=${{ vars.OPENWRT_BUILDER_VOLUME }}" >> "$GITHUB_OUTPUT"
echo "openwrt_branch=${openwrt_branch}" >> "$GITHUB_OUTPUT"
echo "openwrt_branch_number=${openwrt_branch_number}" >> "$GITHUB_OUTPUT"
echo "openwrt_tag=${openwrt_tag}" >> "$GITHUB_OUTPUT"
echo "openwrt_tag_version=${openwrt_tag_version}" >> "$GITHUB_OUTPUT"
echo "artifact_targets_rel=${artifact_targets_rel}" >> "$GITHUB_OUTPUT"
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.target }}/${{ matrix.subtarget }}
needs: setup
runs-on: self-hosted
strategy:
fail-fast: false
matrix:
include: ${{fromJson(needs.setup.outputs.targets_subtargets)}}
container:
image: openwrt/imagebuilder:${{ matrix.target }}-${{ matrix.subtarget }}-${{ needs.setup.outputs.openwrt_tag }}
volumes:
- openwrt-ib-${{ matrix.target }}-${{ matrix.subtarget }}-${{ needs.setup.outputs.openwrt_tag }}:/builder
- ${{ needs.setup.outputs.openwrt_builder_volume }}/:/data/
options: --user root --privileged --pull always
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set env
id: set_env
shell: bash
run: |
python3 -m pip install jinja2
download_dir=/data/download
download_targets_dir=${download_dir}/${{ needs.setup.outputs.artifact_targets_rel }}
download_packages_dir=${download_dir}/${{ needs.setup.outputs.artifact_packages_rel }}
echo "download_dir=${download_dir}" >> "$GITHUB_OUTPUT"
echo "download_targets_dir=${download_targets_dir}" >> "$GITHUB_OUTPUT"
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_targets_dir }} bin
ln -snf ${{ steps.set_env.outputs.download_targets_dir }} bin/targets
openwrt_tag=${{ needs.setup.outputs.openwrt_tag }}
openwrt_mirror=https://mirrors.pku.edu.cn/openwrt
[ ! -f setup.sh ] || UPSTREAM_URL=${openwrt_mirror} bash setup.sh
sed -i 's|^CONFIG_SIGNATURE_CHECK|# \0|' .config
if [ "$openwrt_tag" == "main" ];then
id;pwd;ls -al
openwrt_plugin=$(sed -n -e 's|\(.*\)base\(\.*\)|\1plugin\2|p' repositories | sed -e "s|https://downloads.openwrt.org|http://openwrt-download.czy21.com|")
sed -i -e "1i ${openwrt_plugin}" -e "s|https://downloads.openwrt.org|${openwrt_mirror}|" repositories
cat repositories
else
id;pwd;ls -al
(cd ${{ steps.set_env.outputs.download_targets_dir }}/../;ln -snf ../$(basename ${{ needs.setup.outputs.artifact_packages_rel }}) packages)
openwrt_plugin=$(sed -n -e 's|openwrt_base\(.*\)base$|openwrt_plugin\1plugin|p' repositories.conf | sed -e "s|https://downloads.openwrt.org|http://openwrt-download.czy21.com|")
sed -i -e "s|https://downloads.openwrt.org|${openwrt_mirror}|" -e 's|^option check_signature|# \0|' -e "\$a ${openwrt_plugin}" repositories.conf
cat repositories.conf
fi
- name: Generate image
shell: su buildbot -c "bash {0}"
run: |
(
cd /builder
sed -i -e '/device_packages/a\\t\"user_packages\": getenv(\"USER_PACKAGES\","").split(),' scripts/json_add_image_info.py
make clean
)
python3 -B .github/workflows/scripts/gen_image.py --openwrt-dir /builder --config config --target ${{ matrix.target }}/${{ matrix.subtarget }}
- name: Generate version
shell: su buildbot -c "bash {0}"
if: always()
run: |
wget https://downloads.openwrt.org/index.html -O ${{ steps.set_env.outputs.download_dir }}/index.html
for t in $(ls ${{ steps.set_env.outputs.download_dir }}/releases/ | grep "^[0-9]");do
sed -i -e "s|//archive.openwrt.org/\(releases/${t}\)|\1|" ${{ steps.set_env.outputs.download_dir }}/index.html
done
python3 -B .github/workflows/scripts/gen_version.py --artifact-dir ${{ steps.set_env.outputs.download_dir }}
clean:
name: Clean ${{ matrix.target }}/${{ matrix.subtarget }}
runs-on: self-hosted
needs: [setup,build]
strategy:
fail-fast: false
matrix:
include: ${{fromJson(needs.setup.outputs.targets_subtargets)}}
if: always()
steps:
- run: |
volume_names=$(docker volume ls -q | grep 'openwrt-ib-${{ matrix.target }}-${{ matrix.subtarget }}-${{ needs.setup.outputs.openwrt_tag }}$' || true | xargs )
if [ -n "${volume_names}" ];then
docker volume rm $volume_names
fi