添加 一键同步上游改动脚本

This commit is contained in:
Hyy2001X 2021-09-02 13:22:07 +08:00
parent 79951d8060
commit 6c0a52d1b8
2 changed files with 116 additions and 0 deletions

35
.github/workflows/Repository_Sync.yml vendored Normal file
View File

@ -0,0 +1,35 @@
############################################################
# Description: GitHub Action to synchronise forks #
# Based on: danshui-git/github-forks-sync-action.git #
# Modify: Hyy2001X #
# Thanks to: https://github.com/281677160 #
############################################################
name: Synchronise Fork
on:
repository_dispatch:
workflow_dispatch:
inputs:
sync_mode:
description: '同步上游所有内容'
default: 'false'
env:
SCRIPT_FILE: Scripts/Sync.sh
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@main
- name: Run synchronise script
run: |
[ "${{github.event.inputs.sync_mode}}" == true ] && {
bash $GITHUB_WORKSPACE/Scripts/Sync.sh ${{secrets.GITHUB_TOKEN}} ${{github.repository}} --sync-all
} || {
bash $GITHUB_WORKSPACE/Scripts/Sync.sh ${{secrets.GITHUB_TOKEN}} ${{github.repository}}
}

81
Scripts/Sync.sh Normal file
View File

@ -0,0 +1,81 @@
#!/bin/bash
# AutoBuild Module by Hyy2001 <https://github.com/Hyy2001X/AutoBuild-Actions>
# Thanks 281677160 and TobKed/github-forks-sync-action.git
# Sync
# 上游仓库与分支
INPUT_UPSTREAM_REPOSITORY=Hyy2001X/AutoBuild-Actions
INPUT_UPSTREAM_BRANCH=master
# 文件同步列表,按需修改
Sync_List=(
# .github/workflows/*
# Configs/*
CustomFiles/Depends/*
CustomFiles/Patches/*
CustomFiles/mac80211_d-team_newifi-d2.patch
CustomFiles/system_d-team_newifi-d2
# Scripts/AutoBuild_DiyScript.sh
# Scripts/AutoBuild_ExtraPackages.sh
# Scripts/Sync.sh
Scripts/AutoBuild_Function.sh
Scripts/AutoUpdate.sh
Scripts/AutoBuild_Tools.sh
Scripts/Convert_Translation.sh
# LICENSE
README.md
)
set -e
[[ $# -lt 2 ]] && exit
[[ $* =~ '--sync-all' ]] && {
echo "Sync mode: All files"
SYNC_ALL=true
} || {
echo "Sync mode: <Sync_List> files"
SYNC_ALL=false
}
DUMP_DIR=/tmp/Sync_Fork
INPUT_GITHUB_TOKEN=$1
INPUT_LOCAL_REPOSITORY=$2
INPUT_LOCAL_BRANCH=master
UPSTREAM_REPO="https://github.com/${INPUT_UPSTREAM_REPOSITORY}.git"
UPSTREAM_REPO_DIR=${DUMP_DIR}/${INPUT_UPSTREAM_REPOSITORY##*/}
LOCAL_REPO="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_LOCAL_REPOSITORY}.git"
LOCAL_REPO_DIR=${DUMP_DIR}/${INPUT_LOCAL_REPOSITORY##*/}
mkdir -p ${DUMP_DIR}
if [[ ${SYNC_ALL} == true ]];then
git clone -b ${INPUT_UPSTREAM_BRANCH} ${UPSTREAM_REPO} ${UPSTREAM_REPO_DIR}
cd ${UPSTREAM_REPO_DIR}
git push --force ${LOCAL_REPO} ${INPUT_UPSTREAM_BRANCH}:${INPUT_LOCAL_BRANCH}
[[ $? == 0 ]] && echo "Sync successful" || echo "Sync failed"
else
git clone -b ${INPUT_UPSTREAM_BRANCH} ${UPSTREAM_REPO} ${UPSTREAM_REPO_DIR}
git clone -b ${INPUT_LOCAL_BRANCH} ${LOCAL_REPO} ${LOCAL_REPO_DIR}
echo "Clone finished"
cd ${UPSTREAM_REPO_DIR}
for i in $(echo ${Sync_List[@]});do
if [[ -f $i ]];then
echo "Checkout [${UPSTREAM_REPO_DIR}/$i] to [${LOCAL_REPO_DIR}/$i] ..."
[[ $i =~ '/' && ! -d ${LOCAL_REPO_DIR}/${i%/*} ]] && mkdir -p ${LOCAL_REPO_DIR}/${i%/*}
cp -a ${UPSTREAM_REPO_DIR}/$i ${LOCAL_REPO_DIR}/$i
else
echo "Unable to access file ${UPSTREAM_REPO_DIR}/$i ..."
fi
done
sleep 3
cd ${LOCAL_REPO_DIR}
git config --global user.name ${GITHUB_ACTOR}
# git remote add origin ${LOCAL_REPO}
git add *
echo "Sync time: $(date "+%Y/%m/%d-%H:%M:%S")"
git commit -m "Sync $(date "+%Y/%m/%d-%H:%M:%S")"
git push origin ${INPUT_LOCAL_BRANCH} --force
[[ $? == 0 ]] && echo "Sync successful" || echo "Sync failed"
fi