Skip to content

Sync

Sync #13

Workflow file for this run

name: Sync
on:
schedule:
- cron: '0 1 * * *'
push:
paths:
- '.github/workflows/scripts/**'
- '.github/workflows/build-*'
- main.sh
workflow_dispatch:
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
branchs: ${{ steps.set_env.outputs.branchs }}
openwrt_builder_volume: ${{ steps.set_env.outputs.openwrt_builder_volume }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set env
id: set_env
run: |
branchs=main
branchs+=$(echo;git ls-remote origin | sed -n 's|.*\(openwrt-*\)|\1|p' | xargs)
JSON='['
FIRST=1
for BRANCH in $branchs; do
TUPLE='"'"$(echo $BRANCH | cut -d "/" -f 1)"'"'
[[ $FIRST -ne 1 ]] && JSON="$JSON"','
JSON="$JSON""$TUPLE"
FIRST=0
done
JSON="$JSON"']'
echo -e "\n---- branchs ----\n"
echo "$JSON"
echo -e "\n---- branchs ----\n"
echo "branchs=$JSON" >> $GITHUB_OUTPUT
echo "openwrt_builder_volume=${{ vars.OPENWRT_BUILDER_VOLUME }}" >> "$GITHUB_OUTPUT"
plugin:
name: Plugin
needs: [setup]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
branch: ${{fromJson(needs.setup.outputs.branchs)}}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
token: ${{ secrets.PAT }}
- name: Sync main
if: ${{ matrix.branch != 'main' }}
run: |
git clone ${{ github.server_url }}/${{ github.repository }} feeds/main
mkdir -p .github/workflows/
cp -rfv feeds/main/.github/workflows/scripts/ feeds/main/.github/workflows/build-* .github/workflows/
cp -rfv feeds/main/main.sh .
- name: Determine update
run: bash main.sh update
- name: Determine changes
run: |
git config user.name github-actions
git config user.email [email protected]
if [ -n "$(git status -s)" ];then
git pull && git add . && git commit -m "CI: sync code" && git push
fi
mirror:
name: Mirror
runs-on: self-hosted
needs: [setup]
strategy:
fail-fast: false
matrix:
branch: ${{fromJson(needs.setup.outputs.branchs)}}
container:
image: openwrt/sdk:x86-64-${{ matrix.branch }}
volumes:
- openwrt-sdk-x86-64-${{ matrix.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: |
openwrt_branch_number=$(echo ${{ matrix.branch }} | sed 's|openwrt-||')
artifact_packages_rel=
if [ "${{ matrix.branch }}" == "main" ];then
artifact_packages_rel=snapshots/packages
else
artifact_packages_rel=releases/packages-${openwrt_branch_number}
fi
artifact_packages_bin=/builder/bin/download
artifact_packages_dir=${artifact_packages_bin}/$artifact_packages_rel
download_packages_bin=/data/download
download_packages_dir=${download_packages_bin}/$artifact_packages_rel
echo "openwrt_branch_number=${openwrt_branch_number}" >> "$GITHUB_OUTPUT"
echo "artifact_packages_rel=${artifact_packages_rel}" >> "$GITHUB_OUTPUT"
echo "artifact_packages_bin=${artifact_packages_bin}" >> "$GITHUB_OUTPUT"
echo "artifact_packages_dir=${artifact_packages_dir}" >> "$GITHUB_OUTPUT"
echo "download_packages_bin=${download_packages_bin}" >> "$GITHUB_OUTPUT"
echo "download_packages_dir=${download_packages_dir}" >> "$GITHUB_OUTPUT"
- 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 ${{ steps.set_env.outputs.artifact_packages_bin }}
mkdir -p ${{ steps.set_env.outputs.download_packages_dir }}
- name: Sync
working-directory: /builder
shell: su buildbot -c "bash {0}"
run: |
echo 'immortalwrt-org' > rsync-immortalwrt-password
chmod 600 rsync-immortalwrt-password
echo "
*vlmcsd*
luci-app-openclash*
" > include-packages
rsync --password-file=rsync-immortalwrt-password -avmR --include-from=include-packages --include=*/ --exclude=* \
rsync://[email protected]/firmware-public/${{ steps.set_env.outputs.artifact_packages_rel }} ${{ steps.set_env.outputs.artifact_packages_bin }}
(
cd ${{ steps.set_env.outputs.artifact_packages_dir }}
for t in `find -maxdepth 1 -type d -not -path . -exec basename {} \;`;do
plugin_rel=$t/plugin
mkdir -p $plugin_rel
find $t \( -name "*.ipk" -o -name "*.apk" \) -and \( -not -path '*plugin/*' \) -exec cp -rv {} ${plugin_rel} \;
rsync -avmR --include-from=/builder/include-packages --include=*/ --exclude=* --delete $plugin_rel ${{ steps.set_env.outputs.download_packages_dir }}
done
)
- 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,mirror]
strategy:
fail-fast: false
matrix:
branch: ${{fromJson(needs.setup.outputs.branchs)}}
if: always()
steps:
- run: |
volume_names=$(docker volume ls -q | grep 'openwrt-sdk-x86-64-${{ matrix.branch }}$' || true | xargs )
if [ -n "${volume_names}" ];then
docker volume rm $volume_names
fi