2020-10-16 22:27:36 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-10-26 10:17:14 +08:00
|
|
|
set -e
|
|
|
|
|
|
|
|
source /gh-toolkit/shell.sh
|
2020-10-16 22:27:36 +08:00
|
|
|
|
2020-10-16 22:40:56 +08:00
|
|
|
gh_username="$INPUT_GH_USERNAME"
|
2020-10-17 09:32:45 +08:00
|
|
|
gh_accesstoken="$INPUT_GH_ACCESSTOKEN"
|
2020-10-16 22:40:56 +08:00
|
|
|
gitea_host="$INPUT_GITEA_HOST"
|
|
|
|
gitea_username="$INPUT_GITEA_USERNAME"
|
|
|
|
gitea_accesstoken="$INPUT_GITEA_ACCESSTOKEN"
|
|
|
|
gitea_gist_prefix="$INPUT_GITEA_GIST_PREFIX"
|
|
|
|
gitea_gist_surfix="$INPUT_GITEA_GIST_SURFIX"
|
|
|
|
gistsSource="$INPUT_GISTSSOURCE"
|
|
|
|
gistsStared="$INPUT_GISTSSTARED"
|
|
|
|
repositoryStared="$INPUT_REPOSITORYSTARED"
|
|
|
|
repositorySource="$INPUT_REPOSITORYSOURCE"
|
|
|
|
repositoryForked="$INPUT_REPOSITORYFORKED"
|
2020-10-26 10:17:14 +08:00
|
|
|
localCache="$INPUT_LOCALCACHE"
|
2020-10-16 22:27:36 +08:00
|
|
|
|
2020-10-17 09:32:45 +08:00
|
|
|
echo "###[group] Setting Up Gitea Mirror Script"
|
2020-10-16 23:13:02 +08:00
|
|
|
git clone https://github.com/varunsridharan/github-gitea-mirror ./mirror-handler
|
2020-10-16 23:59:35 +08:00
|
|
|
echo "###[endgroup]"
|
2020-10-16 23:13:02 +08:00
|
|
|
|
2020-10-16 23:55:41 +08:00
|
|
|
echo "🗳️ Updating Settings"
|
2020-10-26 10:17:14 +08:00
|
|
|
template='{"github":{"username":"%s","accesstoken":"%s"},"gitea":{"host":"%s","accesstoken":"%s","username":"%s","default_userpassword":"%s","gist":{"prefix":"%s","surfix":"%s"}},"repomap":{},"gistsSource":%s,"gistsStared":%s,"repositoryStared":%s,"repositorySource":%s,"repositoryForked":%s, "local_cache": { "enabled": %s, "file_path": "gitea.json" }}'
|
2020-10-26 10:22:53 +08:00
|
|
|
json_string=$(printf "$template" "$gh_username" "$gh_accesstoken" "$gitea_host" "$gitea_accesstoken" "$gitea_username" "RY7VpBD62P7964c9mSz%2GAM82hv68yUbHc4@Gdw8c%f^W3*qdzof*8a6b^rKy" "$gitea_gist_prefix" "$gitea_gist_surfix" "$gistsSource" "$gistsStared" "$repositoryStared" "$repositorySource" "$repositoryForked" "$localCache")
|
2020-10-16 23:55:41 +08:00
|
|
|
echo "$json_string" >./mirror-handler/src/config.json
|
2020-10-16 23:13:02 +08:00
|
|
|
|
2020-10-26 10:17:14 +08:00
|
|
|
if [ -z "$GITHUB_TOKEN" ]; then
|
|
|
|
echo "🚩 Set the GITHUB_TOKEN env variable To Store Cache In REPO"
|
|
|
|
else
|
|
|
|
gitconfig
|
|
|
|
fi
|
|
|
|
|
2020-10-26 12:21:18 +08:00
|
|
|
#if [ "$localCache" == "true" ]; then
|
|
|
|
# echo "###[group] ⏳ Setting Up Local Cache"
|
|
|
|
# python3 ./mirror-handler/repoCache.py
|
|
|
|
# echo "###[endgroup]"
|
|
|
|
#fi
|
2020-10-26 10:17:14 +08:00
|
|
|
|
2020-10-16 23:35:54 +08:00
|
|
|
if [ "$gistsSource" == "true" ]; then
|
2020-10-16 23:55:41 +08:00
|
|
|
echo "###[group] ⏳ Setting Up Mirror For Public & Private Gits"
|
2020-10-16 23:35:54 +08:00
|
|
|
python3 ./mirror-handler/gist.py
|
2020-10-16 23:55:41 +08:00
|
|
|
echo "###[endgroup]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$gistsStared" == "true" ]; then
|
|
|
|
echo "###[group] ⏳ Setting Up Mirror For Stared Gits"
|
|
|
|
python3 ./mirror-handler/giststared.py
|
|
|
|
echo "###[endgroup]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$repositorySource" == "true" ]; then
|
|
|
|
echo "###[group] ⏳ Setting Up Mirror For Public & Private Source Repository"
|
|
|
|
python3 ./mirror-handler/repoSource.py
|
|
|
|
echo "###[endgroup]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$repositoryForked" == "true" ]; then
|
|
|
|
echo "###[group] ⏳ Setting Up Mirror For Forked Repository"
|
|
|
|
python3 ./mirror-handler/repoForked.py
|
|
|
|
echo "###[endgroup]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$repositoryStared" == "true" ]; then
|
|
|
|
echo "###[group] ⏳ Setting Up Mirror For Stared Repository"
|
|
|
|
python3 ./mirror-handler/repoStared.py
|
|
|
|
echo "###[endgroup]"
|
|
|
|
fi
|
2020-10-26 10:17:14 +08:00
|
|
|
|
2020-10-26 13:54:26 +08:00
|
|
|
rm -rf ./mirror-handler/
|
|
|
|
|
2020-10-26 10:17:14 +08:00
|
|
|
if [ "$localCache" == "true" ]; then
|
|
|
|
if [ "$(git status --porcelain)" != "" ]; then
|
|
|
|
git add gitea.json -f
|
|
|
|
git commit -m "Updated / Created Gitea Local Repository Cache"
|
2020-10-26 10:20:23 +08:00
|
|
|
#git push origin
|
|
|
|
git push "https://x-access-token:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY"
|
2020-10-26 10:17:14 +08:00
|
|
|
fi
|
|
|
|
fi
|