OpenWRT Packages Updater #616
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: OpenWRT Packages Updater | |
on: | |
schedule: | |
- cron: '0 */12 * * *' # 每12小时运行一次 | |
push: | |
paths: | |
- '.github/diy/Update.sh' | |
- '.github/workflows/OpenWRT_Packages_Updater.yml' | |
- '.github/diy/patches/openwrt-packages/*/*.patch' | |
- '.github/diy/openwrt-packages/*.sh' | |
watch: | |
types: started | |
repository_dispatch: | |
jobs: | |
update: | |
if: github.event.repository.owner.id == github.event.sender.id || ! github.event.sender.id | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
target: [main, qt6 , mt798x] | |
name: 更新 ${{ matrix.target }} 分支 | |
steps: | |
- name: 签出代码 | |
uses: actions/checkout@main | |
- name: 初始化环境 | |
run: | | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
sudo timedatectl set-timezone "Asia/Shanghai" | |
( sudo -E apt-get -qq install rename ) & | |
- name: 克隆代码 | |
run: | | |
cd $GITHUB_WORKSPACE | |
chmod +x .github/diy/openwrt-packages/*.sh | |
git clone -b ${{matrix.target}} https://github.com/FlawShatter/openwrt-packages.git ${{matrix.target}} | |
cd ${{matrix.target}} | |
git rm -r --cache * >/dev/null 2>&1 & | |
# 删除除diy目录以外的文件夹 | |
# rm -rf `find ./* -maxdepth 0 -type d ! -name "diy"` >/dev/null 2>&1 | |
rm -rf ./* >/dev/null 2>&1 | |
bash $GITHUB_WORKSPACE/.github/diy/openwrt-packages/${{matrix.target}}.sh | |
- name: 修改代码 | |
run: | | |
cd $GITHUB_WORKSPACE/${{matrix.target}} | |
bash $GITHUB_WORKSPACE/.github/diy/openwrt-packages/convert_translation.sh | |
bash $GITHUB_WORKSPACE/.github/diy/openwrt-packages/create_acl_for_luci.sh -a | |
bash $GITHUB_WORKSPACE/.github/diy/openwrt-packages/modify.sh | |
# 应用补丁 | |
find "$GITHUB_WORKSPACE/.github/diy/openwrt-packages/patches/${{matrix.target}}" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 -E --forward --no-backup-if-mismatch" || exit 1 | |
# 下载修改补丁 | |
curl -o "$GITHUB_WORKSPACE/.github/diy/openwrt-packages/download_patches/${{matrix.target}}/luci-smartdns-dev.patch" --create-dirs "https://github.com/xiaorouji/openwrt-passwall/compare/main...luci-smartdns-dev.patch" | |
find "$GITHUB_WORKSPACE/.github/diy/openwrt-packages/download_patches/${{matrix.target}}" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 -N --forward --no-backup-if-mismatch" 2>&1 | grep -v "error_message" || exit 1 | |
- name: 提交代码 | |
env: | |
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
run: | | |
cd $GITHUB_WORKSPACE/${{matrix.target}} | |
if [ "${{ github.event_name }}" == "schedule" ]; then | |
commit_message="⏲ Schedule update-$(TZ='Asia/Shanghai' date -d now)" | |
else | |
commit_message="🔗 Trigger update-$(TZ='Asia/Shanghai' date -d now)" | |
fi | |
# 添加文件到工作区 | |
git add . | |
# 检查是否有需要提交的更改 | |
if [ -n "$(git status --porcelain)" ]; then | |
# 提交更改 | |
git commit -m "$commit_message" | |
echo "Commit successful. Pushing changes to the repository." | |
git push --quiet "https://${{ secrets.ACCESS_TOKEN }}@github.com/FlawShatter/openwrt-packages.git" HEAD:${{matrix.target}} | |
else | |
echo "No changes to commit. Skipping the push step." | |
fi |