Sync #58
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
archs: ${{ steps.set_env.outputs.archs }} | |
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" | |
python3 -B ./.github/workflows/scripts/get_targets.py | while read v;do echo "$v" >> "$GITHUB_OUTPUT"; done | |
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=releases/packages-${openwrt_branch_number} | |
if [ "${{ matrix.branch }}" == "main" ];then | |
artifact_packages_rel=snapshots/packages | |
fi | |
artifact_dir=/builder/bin/download | |
artifact_packages_dir=${artifact_dir}/$artifact_packages_rel | |
download_dir=/data/download | |
download_packages_dir=${download_dir}/$artifact_packages_rel | |
echo "openwrt_branch_number=${openwrt_branch_number}" >> "$GITHUB_OUTPUT" | |
echo "artifact_packages_rel=${artifact_packages_rel}" >> "$GITHUB_OUTPUT" | |
echo "artifact_dir=${artifact_dir}" >> "$GITHUB_OUTPUT" | |
echo "artifact_packages_dir=${artifact_packages_dir}" >> "$GITHUB_OUTPUT" | |
echo "download_dir=${download_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.artifact_dir }} | |
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: Sync | |
working-directory: /builder | |
shell: su buildbot -c "bash {0}" | |
run: | | |
echo 'immortalwrt-org' > rsync-immortalwrt-password | |
chmod 600 rsync-immortalwrt-password | |
archs="${{ join(fromJson(needs.setup.outputs.archs),' ') }}" | |
packages="*vlmcsd* luci-app-openclash*" | |
echo -n "" > include-archs-packages | |
for a in $archs;do | |
for p in $packages;do | |
echo "*/$a/*/$p" >> include-archs-packages | |
done | |
done | |
echo -n "" > include-packages | |
for p in $packages;do | |
echo "$p" >> include-packages | |
done | |
rsync --password-file=rsync-immortalwrt-password -avmR --include-from=include-archs-packages --include=*/ --exclude=* rsync://[email protected]/firmware-public/${{ steps.set_env.outputs.artifact_packages_rel }} ${{ steps.set_env.outputs.artifact_dir }} | |
( | |
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 -r {} ${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 |