This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmirror_repos
executable file
·69 lines (47 loc) · 1.96 KB
/
mirror_repos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /bin/bash
set -ueo pipefail
export AWS_REGION=eu-west-2
export AWS_DEFAULT_REGION=eu-west-2
base_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function with_credentials {
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_SESSION_TOKEN
eval $(./set_credentials)
}
with_credentials
echo "Finding Github repos tagged with 'govuk'..."
repos=$(${base_dir}/get_github_repos)
[[ $(uname) == 'Darwin' ]] && md5=md5 || md5=md5sum
for repo in ${repos}; do
with_credentials
git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
echo -n "Checking if ${repo} is up to date... "
github_md5=$(git ls-remote --heads --tags https://${GITHUB_ACCESS_TOKEN}@github.com/alphagov/${repo} | $md5 | cut -d" " -f1)
aws_cc_md5=$(git ls-remote --heads --tags https://git-codecommit.${AWS_REGION}.amazonaws.com/v1/repos/${repo} | $md5 | cut -d" " -f1)
if [ ${github_md5} != ${aws_cc_md5} ]; then
echo "updating"
git="git --git-dir ${repo}.git"
github_remote="ssh://git@github.com/alphagov/${repo}"
aws_remote="ssh://${AWS_CODECOMMIT_USER_ID}@git-codecommit.${AWS_REGION}.amazonaws.com/v1/repos/${repo}"
echo "Cleaning the workspace"
rm -rf "${repo}.git"
echo "Fetching ${repo}"
${git} clone --mirror "${github_remote}"
echo "Doing some cleanup for ${repo}"
${git} reflog expire --expire-unreachable=now --all
${git} gc --prune=now
echo "Pushing latest ${repo} tags"
${git} push "${aws_remote}" --force $(git for-each-ref --sort=taggerdate --format '%(refname:short)' refs/tags | tail -4000 | tr '\n' ' ')
echo "Pushing all ${repo} repo branches"
${git} push --force --quiet --all "${aws_remote}"
echo "Manually pushing ${repo} git heads information"
${git} push ${aws_remote} +refs/remotes/origin/*:refs/heads/*
echo "Deleting local copy ${repo}.git"
rm -rf "${repo}.git"
else
echo "ok"
fi
sleep 2
done