同步 Coolsnowwolf 仓库 #671
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: 同步 Coolsnowwolf 仓库 | |
on: | |
schedule: | |
- cron: '0 */12 * * *' # 每12小时运行一次 | |
push: | |
paths: | |
- '.github/workflows/Sync_Lean.yml' | |
- '.github/diy/patches/lede/*/*.patch' | |
- '.github/diy/patches/luci/*/*.patch' | |
- '.github/diy/patches/packages/*/*.patch' # 当workflow文件有改变时触发 | |
watch: | |
types: [started] | |
jobs: | |
sync_lede: | |
name: 同步 lede 仓库 | |
if: github.event.repository.owner.id == github.event.sender.id || ! github.event.sender.id | |
runs-on: ubuntu-latest | |
env: | |
TARGETS: "lean openwrt-snapshot dg741a immortalwrt hanwckf" | |
UPSTREAMS: "https://github.com/coolsnowwolf/lede.git https://github.com/openwrt/openwrt.git https://github.com/dg741a/lede.git https://github.com/immortalwrt/immortalwrt.git https://github.com/hanwckf/immortalwrt-mt798x.git" | |
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" | |
- name: 克隆仓库并设置上游 | |
run: | | |
cd $GITHUB_WORKSPACE | |
git clone --quiet --depth=1 https://github.com/FlawShatter/lede.git temp_rep | |
cd temp_rep | |
index=1 | |
for target in $TARGETS; do | |
upstream=$(echo $UPSTREAMS | cut -d' ' -f$index) | |
echo "Target: $target Upstream: $upstream" | |
git remote add $target $upstream | |
((index++)) | |
done | |
git fetch --all --no-tags | |
- name: 拉取上游代码并打补丁 | |
env: | |
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
run: | | |
cd $GITHUB_WORKSPACE/temp_rep | |
for target in $TARGETS; do | |
echo "Target: $target" | |
if [[ $target == "hanwckf" ]]; then | |
git checkout -B $target $target/openwrt-21.02 | |
else | |
git checkout -B $target $target/master | |
fi | |
if [ -d "$GITHUB_WORKSPACE/.github/diy/lede/patches/$target" ]; then | |
find "$GITHUB_WORKSPACE/.github/diy/lede/patches/$target" -type f -name '*.patch' -print0 | | |
while IFS= read -r -d '' patch_file; do | |
echo "应用补丁中: $patch_file" | |
if git apply --check "$patch_file"; then | |
git apply "$patch_file" | |
git add . | |
git commit -m "Applying $(basename "$file_path")." | |
else | |
echo "应用补丁时出错: $patch_file" | |
fi | |
done | |
fi | |
if [[ $target == "lean" ]]; then | |
git push "https://${{ secrets.ACCESS_TOKEN }}@github.com/FlawShatter/lede.git" -f HEAD:master | |
else | |
if [ -d .github ]; then | |
rm -rf .github | |
git add . | |
git commit -m "Removing workflows files." | |
fi | |
git push "https://${{ secrets.ACCESS_TOKEN }}@github.com/FlawShatter/lede.git" -f HEAD:$target | |
fi | |
done | |
sync_luci: | |
name: 同步 Luci 仓库 | |
if: github.event.repository.owner.id == github.event.sender.id || ! github.event.sender.id | |
# if: ${{ false }} | |
runs-on: ubuntu-latest | |
env: | |
TARGETS: "lean openwrt immortalwrt" | |
UPSTREAMS: "https://github.com/coolsnowwolf/luci.git https://github.com/openwrt/luci.git https://github.com/immortalwrt/luci.git" | |
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" | |
- name: 克隆仓库并设置上游 | |
run: | | |
cd $GITHUB_WORKSPACE | |
git clone --quiet --depth=1 https://github.com/FlawShatter/luci.git temp_rep | |
cd temp_rep | |
index=1 | |
for target in $TARGETS; do | |
upstream=$(echo $UPSTREAMS | cut -d' ' -f$index) | |
echo "Target: $target Upstream: $upstream" | |
git remote add $target $upstream | |
((index++)) | |
done | |
git fetch --all --no-tags | |
- name: 拉取上游代码并打补丁 | |
env: | |
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
run: | | |
cd $GITHUB_WORKSPACE/temp_rep | |
for target in $TARGETS; do | |
echo "Target: $target" | |
git checkout -B $target $target/master | |
if [ -d "$GITHUB_WORKSPACE/.github/diy/luci/patches/$target" ]; then | |
find "$GITHUB_WORKSPACE/.github/diy/luci/patches/$target" -type f -name '*.patch' -print0 | | |
while IFS= read -r -d '' patch_file; do | |
echo "应用补丁中: $patch_file" | |
if git apply --check "$patch_file"; then | |
git apply "$patch_file" | |
git add . | |
git commit -m "Applying $(basename "$file_path")." | |
else | |
echo "应用补丁时出错: $patch_file" | |
fi | |
done | |
fi | |
if [[ $target == "lean" ]]; then | |
git push "https://${{ secrets.ACCESS_TOKEN }}@github.com/FlawShatter/luci.git" -f HEAD:master | |
else | |
if [ -d .github ]; then | |
rm -rf .github | |
git add . | |
git commit -m "Removing workflows files." | |
fi | |
git push "https://${{ secrets.ACCESS_TOKEN }}@github.com/FlawShatter/luci.git" -f HEAD:$target | |
fi | |
done | |
echo "Target: hanwckf" | |
git checkout -B hanwckf immortalwrt/openwrt-21.02 | |
if [ -d "$GITHUB_WORKSPACE/.github/diy/luci/patches/hanwckf" ]; then | |
find "$GITHUB_WORKSPACE/.github/diy/luci/patches/hanwckf" -type f -name '*.patch' -print0 | | |
while IFS= read -r -d '' patch_file; do | |
echo "应用补丁中: $patch_file" | |
if git apply --check "$patch_file"; then | |
git apply "$patch_file" | |
git add . | |
git commit -m "Applying $(basename "$file_path")." | |
else | |
echo "应用补丁时出错: $patch_file" | |
fi | |
done | |
fi | |
if [ -d .github ]; then | |
rm -rf .github | |
git add . | |
git commit -m "Removing workflows files." | |
fi | |
git push "https://${{ secrets.ACCESS_TOKEN }}@github.com/FlawShatter/luci.git" -f HEAD:hanwckf | |
sync_packages: | |
name: 同步 Packages 仓库 | |
if: github.event.repository.owner.id == github.event.sender.id || ! github.event.sender.id | |
# if: ${{ false }} | |
runs-on: ubuntu-latest | |
env: | |
TARGETS: "lean openwrt immortalwrt" | |
UPSTREAMS: "https://github.com/coolsnowwolf/packages.git https://github.com/openwrt/packages.git https://github.com/immortalwrt/packages.git" | |
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" | |
- name: 克隆仓库并设置上游 | |
run: | | |
cd $GITHUB_WORKSPACE | |
git clone --quiet --depth=1 https://github.com/FlawShatter/packages.git temp_rep | |
cd temp_rep | |
index=1 | |
for target in $TARGETS; do | |
upstream=$(echo $UPSTREAMS | cut -d' ' -f$index) | |
echo "Target: $target Upstream: $upstream" | |
git remote add $target $upstream | |
((index++)) | |
done | |
git fetch --all --no-tags | |
- name: 拉取上游代码并打补丁 | |
env: | |
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
run: | | |
cd $GITHUB_WORKSPACE/temp_rep | |
for target in $TARGETS; do | |
echo "Target: $target" | |
git checkout -B $target $target/master | |
if [ -d "$GITHUB_WORKSPACE/.github/diy/packages/patches/$target" ]; then | |
find "$GITHUB_WORKSPACE/.github/diy/packages/patches/$target" -type f -name '*.patch' -print0 | | |
while IFS= read -r -d '' patch_file; do | |
echo "应用补丁中: $patch_file" | |
if git apply --check "$patch_file"; then | |
git apply "$patch_file" | |
git add . | |
git commit -m "Applying $(basename "$file_path")." | |
else | |
echo "应用补丁时出错: $patch_file" | |
fi | |
done | |
fi | |
if [[ $target == "lean" ]]; then | |
git push "https://${{ secrets.ACCESS_TOKEN }}@github.com/FlawShatter/packages.git" -f HEAD:master | |
else | |
if [ -d .github ]; then | |
rm -rf .github | |
git add . | |
git commit -m "Removing workflows files." | |
fi | |
git push "https://${{ secrets.ACCESS_TOKEN }}@github.com/FlawShatter/packages.git" -f HEAD:$target | |
fi | |
done | |
echo "Target: hanwckf" | |
git checkout -B hanwckf immortalwrt/openwrt-21.02 | |
if [ -d "$GITHUB_WORKSPACE/.github/diy/packages/patches/hanwckf" ]; then | |
find "$GITHUB_WORKSPACE/.github/diy/packages/patches/hanwckf" -type f -name '*.patch' -print0 | | |
while IFS= read -r -d '' patch_file; do | |
echo "应用补丁中: $patch_file" | |
if git apply --check "$patch_file"; then | |
git apply "$patch_file" | |
git add . | |
git commit -m "Applying $(basename "$file_path")." | |
else | |
echo "应用补丁时出错: $patch_file" | |
fi | |
done | |
fi | |
if [ -d .github ]; then | |
rm -rf .github | |
git add . | |
git commit -m "Removing workflows files." | |
fi | |
git push "https://${{ secrets.ACCESS_TOKEN }}@github.com/FlawShatter/packages.git" -f HEAD:hanwckf | |
del_runs: | |
name: 删除旧运行记录 | |
runs-on: ubuntu-latest | |
permissions: | |
actions: write | |
contents: read | |
steps: | |
- name: Delete workflow runs | |
uses: Mattraks/delete-workflow-runs@v2 | |
with: | |
token: ${{ github.token }} | |
repository: ${{ github.repository }} | |
retain_days: 1 | |
keep_minimum_runs: 4 |