Skip to content

Commit

Permalink
Merge pull request #36 from YoYoGames/develop.gurpreet
Browse files Browse the repository at this point in the history
Resolving merge conflicts from develop -> main
  • Loading branch information
gurpreetsinghmatharoo authored Oct 11, 2023
2 parents 0d92680 + 75ab222 commit ab178b5
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: YoYoStudioRoboHelp
path: output\RoboHelp
path: output\RoboHelp\*.zip
if-no-files-found: error

112 changes: 112 additions & 0 deletions sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env bash

#
# Setup automatic sync from a Github upstream repository to a fork
# - a branch "actions" will be created (or re-used) to hold the Github action to run
# - sync is done each hour
# - branch 'actions' needs to be the default branch of your fork (=> settings)
# - the script is able to both create and update and rewrite the sync script if you modify this script file
#
# Author: Mathiue Carbou
# Date: April 2021
#
# Notes:
# - Github bug: action is not shown if pushed first before changing the default branch
#
# Good luck...
#
# BLOG: https://blog.mathieu.photography/post/649318432483033088/automatic-fork-syncing-with-github
#

usage() {
echo "sync.sh <fork> <upstream> <branch-to-sync> <domain>"
exit 1
}

if [ "$#" -ne 3 ] && [ "$#" -ne 4 ]; then
usage
fi

fork=$1
upstream=$2
branch=$3
domain="github.com"
tmp_dir=$(mktemp -d -t git)
echo "Temporary directory: $tmp_dir"

if [ "$#" -eq 4 ]; then
domain=$4
fi

# quic and fast clone
git clone --depth=1 git@$domain:ksuchitra532/$fork.git $tmp_dir

if [ $(git -C $tmp_dir branch --show-current) != "actions" ]; then
# default repository branch is NOT 'actions'
git -C $tmp_dir checkout actions
if [ $? -eq 1 ]
then
# branch 'actions' does not exist
git -C $tmp_dir checkout --orphan actions
git -C $tmp_dir rm -rf .
git -C $tmp_dir commit --allow-empty -am "root"
git -C $tmp_dir push origin actions
fi
echo ""
echo "========================================================"
echo ">>> WARNING <<<"
echo "========================================================"
echo "Please go to: https://$domain/$fork/settings/branches"
echo "Change your default branch to 'actions'"
echo "Press a key to continue."
echo "========================================================"
read
fi

# create workflow script
mkdir -p $tmp_dir/.github/workflows
cat << EOF > $tmp_dir/.github/workflows/fork-sync.yml
name: "Fork Sync"
on:
schedule:
- cron: '0 */2 * * *'
workflow_dispatch:
jobs:
sync-$branch:
runs-on: ubuntu-latest
name: "Sync from $upstream@$branch"
steps:
- name: "Checkout: $branch"
uses: actions/checkout@v2
with:
ref: $branch
token: \${{ github.token }}
- name: "Update: $branch"
id: sync-$branch
uses: mathieucarbou/Fork-Sync-With-Upstream-action@fork-sync
with:
domain: '$domain'
upstream_repository: $upstream
upstream_branch: $branch
target_branch: $branch
git_pull_args: --ff-only
# git_push_args: --force
- name: Timestamp
run: date
EOF
git -C $tmp_dir rm .github/workflows/sync.yml # remove old workflow script
git -C $tmp_dir add .github/workflows/fork-sync.yml
git -C $tmp_dir commit -am "fork-sync.yml"
git -C $tmp_dir push origin actions

# cleanup
rm -f -r $tmp_dir/.git
rm -f -r $tmp_dir

echo ""
echo "=========================================================================="
echo ">>> WARNING <<<"
echo "=========================================================================="
echo "Please go to: https://$domain/$fork/actions"
echo "Run the Sync task manually. It will run each hour automatically."
echo "=========================================================================="

0 comments on commit ab178b5

Please sign in to comment.