From 6c0a52d1b8b7c9d0638aa4f5565cb08dfaacb6ba Mon Sep 17 00:00:00 2001 From: Hyy2001X <1804430051@qq.com> Date: Thu, 2 Sep 2021 13:22:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=8A=E6=B8=B8=E6=94=B9=E5=8A=A8=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Repository_Sync.yml | 35 ++++++++++++ Scripts/Sync.sh | 81 +++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 .github/workflows/Repository_Sync.yml create mode 100644 Scripts/Sync.sh diff --git a/.github/workflows/Repository_Sync.yml b/.github/workflows/Repository_Sync.yml new file mode 100644 index 0000000..bdffbd1 --- /dev/null +++ b/.github/workflows/Repository_Sync.yml @@ -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}} + } diff --git a/Scripts/Sync.sh b/Scripts/Sync.sh new file mode 100644 index 0000000..a2b10f1 --- /dev/null +++ b/Scripts/Sync.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# AutoBuild Module by Hyy2001 +# 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: 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