Add support github actions

This commit is contained in:
remittor
2025-01-14 12:33:35 +03:00
parent 4ab2b4a312
commit 2c59084788
4 changed files with 295 additions and 1 deletions

281
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,281 @@
name: build
on:
workflow_dispatch:
inputs:
fake_build:
description: 'Fake build'
required: true
default: 'false'
type: choice
options:
- true
- false
suffix:
description: 'TAG suffix'
required: false
default: ''
type: string
env:
FAKE_BUILD: ${{ github.event.inputs.fake_build }}
REPO_URL: https://github.com/openwrt-xiaomi/openwrt
REPO_LNK: openwrt-xiaomi/openwrt
REPO_BRANCH: xq-24.10
TAG_PREFIX: v24-
BUILD_ROOT: ${{ github.workspace }}/openwrt
DEPENDENCIES: ${{ github.workspace }}/dependencies-ubuntu.txt
TZ: UTC
DEVICE_NAME: unknown
BUILD_DATE: unknown
REPO_DATE: unknown
FW_DATE: unknown
FW_VER: unknown
jobs:
check:
runs-on: ubuntu-24.04
outputs:
tag: ${{ steps.gh.outputs.tag }}
date: ${{ steps.gh.outputs.date }}
sha: ${{ steps.gh.outputs.sha }}
url: ${{ steps.gh.outputs.url }}
message: ${{ steps.gh.outputs.message }}
build_date: ${{ steps.gh.outputs.build_date }}
fw_date: ${{ steps.gh.outputs.fw_date }}
fw_ver: ${{ steps.gh.outputs.fw_ver }}
is_active: ${{ steps.activity.outputs.is_active }}
steps:
- name: Get repo data via GH API
id: gh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Tag name from GITHUB_REF_NAME: $GITHUB_REF_NAME"
echo "Tag name from github.ref_name: ${{ github.ref_name }}"
BRANCH=$REPO_BRANCH
REPO_DATE=$(gh api repos/$REPO_LNK/commits/$BRANCH --jq '.commit.committer.date')
BUILD_DATE=$( date --utc +'%y%m%d' )
FW_DATE=$( date --utc +'%Y-%m-%d' )
TAG=$TAG_PREFIX$BUILD_DATE
echo "REPO_DATE=$REPO_DATE" >> $GITHUB_ENV
echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_ENV
echo "FW_DATE=$FW_DATE" >> $GITHUB_ENV
echo "TAG=$TAG" >> $GITHUB_ENV
wget $REPO_URL/raw/refs/heads/$BRANCH/include/version.mk
FW_VERSION=$( grep -s '^VERSION_NUMBER:=$(if' version.mk 2>/dev/null )
[ -z "$FW_VERSION" ] && { echo "ERROR: Cannot find VERSION_NUMBER"; exit 90; }
FW_VER=$( echo $FW_VERSION | cut -d"," -f3 | cut -d")" -f1 )
echo 'FW_VER = "'$FW_VER'"'
echo "FW_VER=$FW_VER" >> $GITHUB_ENV
rm -f version.mk
{
echo "tag=$TAG"
echo "date=$(date --utc -d $REPO_DATE +%Y%m%d)"
echo "sha=$(gh api repos/$REPO_LNK/commits/$BRANCH --jq '.sha[0:7]')"
echo "url=$(gh api repos/$REPO_LNK/commits/$BRANCH --jq '.html_url')"
echo "message<<EOF"
gh api repos/$REPO_LNK/commits/$BRANCH --jq '.commit.message'
echo EOF
echo "build_date=$BUILD_DATE"
echo "fw_date=$FW_DATE"
echo "fw_ver=$FW_VER"
} >> $GITHUB_OUTPUT
- name: Check for repo activity
id: activity
env:
REPO_DATE: ${{ env.REPO_DATE }}
URL: ${{ steps.gh.outputs.url }}
run: |
TIMESTAMP=$(date --utc -d $REPO_DATE +%s)
DAYS=$(( ( $(date --utc +%s) - $TIMESTAMP ) / 86400 ))
echo "Repository activity: $(date --utc -d $REPO_DATE)"
echo "Commit: $URL"
if [ "${{ github.event_name }}" != "schedule" ]; then
is_active=true
elif [[ $DAYS -lt 1 ]] ; then
is_active=true
else
echo "Repository not updated within last 24 hours."
is_active=false
fi
echo "is_active=$is_active" >> $GITHUB_OUTPUT
build:
needs: check
#if: needs.check.outputs.is_active == 'true'
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
target:
- kng_re
- r3d
- r3g
- rb03
- rb06
- rd03
- rt-ax52
- rt-ax57m
- rt-ax59u
- rt-ax89x
- tuf_ax4200
- tuf_ax6000
steps:
- name: Initialization environment
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get -qq update
#sudo apt-get -qq update && sudo apt-get -qq upgrade
sudo apt-get -qq install $(cat $DEPENDENCIES)
sudo apt-get -qq autoremove --purge
sudo apt-get -qq clean
sudo timedatectl set-timezone "$TZ"
- name: Maximize build disk space
uses: easimon/maximize-build-space@master
with:
remove-dotnet: true
remove-android: true
remove-haskell: true
remove-codeql: true
remove-docker-images: true
- name: Checkout builder
uses: actions/checkout@main
- name: Download OpenWrt sources
run: git clone --branch $REPO_BRANCH $REPO_URL.git $BUILD_ROOT
- name: Init builder
env:
BLDROOT: ${{ github.workspace }}
shell: bash
run: |
rsync -avq --exclude=".*" --exclude="$(basename $BUILD_ROOT)" $BLDROOT/ $BUILD_ROOT/
cd $BUILD_ROOT
chmod +x *.sh
wget https://github.com/fantastic-packages/packages/raw/refs/heads/24.10/keys/usign/53FF2B6672243D28.pub
- name: Update OpenWrt packages
id: update
run: |
cd $BUILD_ROOT && ./xupdate.sh -f
echo "status=success" >> $GITHUB_OUTPUT
- name: Build the firmware image
id: compile
if: steps.update.outputs.status == 'success'
env:
TARGET: ${{ matrix.target }}
FW_VER: ${{ needs.check.outputs.fw_ver }}
run: |
cd $BUILD_ROOT
MAKE_JOBS=$(($(nproc)+1))
echo "$MAKE_JOBS thread compile"
./xmake.sh -I -t $TARGET
[ "$FAKE_BUILD" != "true" ] && make -j $MAKE_JOBS download world
FILE_DATE=$(date --utc +'%y%m%d')
DEVICE_NAME=$( grep -so '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' )
BOARD_NAME=$( grep -so '^CONFIG_TARGET_BOARD=.*' .config | cut -d'"' -f2 )
SUBTARGET_NAME=$( grep -so '^CONFIG_TARGET_SUBTARGET=.*' .config | cut -d'"' -f2 )
OUT_DIR=$BUILD_ROOT/bin/targets/$BOARD_NAME/$SUBTARGET_NAME
if [ "$FAKE_BUILD" = "true" ]; then
mkdir -p logs
mkdir -p $OUT_DIR
echo "$BOARD_NAME $SUBTARGET_NAME $DEVICE_NAME" > "$OUT_DIR/$DEVICE_NAME.txt"
touch "$OUT_DIR/kernel-debug.tar.zst"
ls -la
BLD_VER=$FW_VER
else
BLD_VER=$( cat $OUT_DIR/profiles.json | grep -so '"version_number":"[^"]*' | grep -so '[^"]*$' )
fi
echo "Firmware $BLD_VER [$FILE_DATE] builded!"
if [ ! -f $OUT_DIR/kernel-debug.tar.zst ]; then
echo "File kernel-debug.tar.zst not found!"
exit 100
fi
echo "status=success" >> $GITHUB_OUTPUT
echo "DEVICE_NAME=$DEVICE_NAME" >> $GITHUB_ENV
echo "BOARD_NAME=$BOARD_NAME" >> $GITHUB_ENV
echo "SUBTARGET_NAME=$SUBTARGET_NAME" >> $GITHUB_ENV
echo "BLD_VER=$BLD_VER" >> $GITHUB_ENV
echo "OUT_DIR=$OUT_DIR" >> $GITHUB_ENV
echo "FILE_DATE=$FILE_DATE" >> $GITHUB_ENV
- name: Check space usage
run: df -hT
- name: Compress build logs
if: always()
env:
TARGET: ${{ matrix.target }}
FW_DATE: ${{ needs.check.outputs.fw_date }}
LOGS_DIR: ${{ env.BUILD_ROOT }}/logs
run: |
tar -cJvf logs-$TARGET-$FW_DATE.tar.xz $LOGS_DIR
- name: Cleanup OUT directory
if: steps.compile.outputs.status == 'success'
env:
OUT_DIR: ${{ env.OUT_DIR }}
run: |
cd $OUT_DIR
echo "---------------------------"
ls -la
echo "---------------------------"
rm -rf packages
rm -f kernel-*
rm -f *uImage
rm -f *ubi-cleaner*
rm -f *-ram-*.bin
- name: Upload OUT directory
uses: actions/upload-artifact@main
if: steps.compile.outputs.status == 'success'
with:
name: openwrt-${{ env.BLD_VER }}-${{ needs.check.outputs.build_date }}-${{ env.DEVICE_NAME }}
path: ${{ env.OUT_DIR }}
if-no-files-found: error
- name: Upload build logs
if: always()
uses: actions/upload-artifact@v4
with:
name: logs-${{ matrix.target }}-${{ env.FW_DATE }}
path: logs-*.tar.xz
release:
needs: [ check, build ]
permissions:
contents: write
runs-on: ubuntu-24.04
strategy:
max-parallel: 1
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: openwrt-*
- name: Put images into zip
run: |
mkdir -p public
find . -mindepth 1 -type d -name 'openwrt-*' -exec sh -c 'zip -0 ./public/$(basename {}).zip -j {} {}/*' \;
ls -lh ./public/*.zip
- name: Upload assets
uses: andelf/nightly-release@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.check.outputs.tag }}
with:
prerelease: false
tag_name: ${{ needs.check.outputs.tag }}
name: '${{ needs.check.outputs.tag }}'
body: |
OpenWrt ${{ needs.check.outputs.fw_ver }} [${{ needs.check.outputs.fw_date }}]
author: [remittor](https://github.com/remittor)
files: ./public/*.zip

1
dependencies-ubuntu.txt Normal file
View File

@@ -0,0 +1 @@
build-essential clang flex bison g++ gawk gcc-multilib g++-multilib gettext git libncurses5-dev libssl-dev python3-setuptools rsync swig unzip zlib1g-dev file wget

View File

@@ -16,8 +16,9 @@ KALLSYMS=false
TESTING_KERNEL=false
BUILD_ONLY_INITRAMFS=false
BUILD_SKIP_INITRAMFS=false
ONLY_INIT=false
while getopts "j:t:fiskT" opt; do
while getopts "j:t:fiskTI" opt; do
case $opt in
j) MAKE_JOBS=$OPTARG;;
t) XTARGET=$OPTARG;;
@@ -26,6 +27,7 @@ while getopts "j:t:fiskT" opt; do
T) TESTING_KERNEL=true;;
i) BUILD_ONLY_INITRAMFS=true;;
s) BUILD_SKIP_INITRAMFS=true;;
I) ONLY_INIT=true;;
esac
done
@@ -262,6 +264,8 @@ function build_target {
#make tools/install -j$make_jobs
#make toolchain/install -j$make_jobs
[ "$ONLY_INIT" = "true" ] && return 0
make -j $make_jobs download world
}

View File

@@ -10,9 +10,11 @@ ADDONSNSS=$XDIR/_addons_nss.config
. ./xcommon.sh
OPT_FULL_UPDATE=false
USE_GITHUB_SRC=false
while getopts "f" opt; do
case $opt in
f) OPT_FULL_UPDATE=true;;
g) USE_GITHUB_SRC=true;;
esac
done
@@ -46,6 +48,12 @@ git reset --hard origin/$CUR_BRANCH
rm -f feeds.conf
cp -f feeds.conf.default feeds.conf
if [ "$USE_GITHUB_SRC" = "true" ]; then
sed -i -e 's|https://git.openwrt.org/feed/|https://github.com/openwrt/|' feeds.conf
sed -i -e 's|https://git.openwrt.org/project/|https://github.com/openwrt/|' feeds.conf
fi
feed_lst=$( get_cfg_feed_lst "$ADDONSCFG" )
for feed in $feed_lst; do
value=$( get_cfg_feed_url "$ADDONSCFG" $feed )