-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.yml
More file actions
86 lines (81 loc) · 2.82 KB
/
Copy pathaction.yml
File metadata and controls
86 lines (81 loc) · 2.82 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: upstream_sync
description: >
Automatically sync branch from upstream repository.
inputs:
upstreamRepo:
description: Upstream repository slug (owner/repo).
default: The-OpenROAD-Project/OpenROAD
upstreamBranch:
description: Upstream branch name to update.
default: master
force:
description: Use a force push.
default: false
syncTags:
description: >
Also fetch and force-push tags from upstream. Off by default. Turn on
for mirrors where an independent process (e.g. a scheduled tag-creation
workflow) may also run on the upstream repo, so this mirror should
always hold the exact same tag objects rather than creating its own.
default: false
deployKey:
description: SSH Private "deploy key" which has write access.
required: true
runs:
using: composite
steps:
- name: Updating '${{ inputs.upstreamBranch }}' from ${{ inputs.upstreamRepo }}
env:
FORCE: ${{ inputs.force }}
SYNC_TAGS: ${{ inputs.syncTags }}
shell: bash
run: |
# Configure ssh to ignore host key checking.
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "::group::Existing ssh config file"
cat ~/.ssh/config || true
echo "::endgroup::"
cat > ~/.ssh/config << EOF
Host *
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
EOF
# Figure out if we should do a force push
export GIT_ARGS=''
if [[ x$FORCE = 'xtrue' ]]; then
export GIT_ARGS=--force
fi
# Clone a blobless repository and don't bother checking it out.
echo "::group::Clone repo"
rm -rf repo
git clone \
--filter=blob:none \
--no-tags \
--no-checkout \
--origin upstream \
--branch ${{ inputs.upstreamBranch }} \
--verbose \
https://github.com/${{ inputs.upstreamRepo }}.git \
repo
cd repo
echo "::endgroup::"
# Start ssh agent and add deploy key.
eval $(ssh-agent -s)
ssh-add - <<< "${{ inputs.deployKey }}"
# Add local repository and push to it.
echo "::group::Push repo"
git remote add origin git+ssh://git@github.com/${{ github.repository }}.git
git push origin $GIT_ARGS --verbose upstream/${{ inputs.upstreamBranch }}:${{ inputs.upstreamBranch }}
echo "::endgroup::"
# Mirror tags exactly rather than letting this repo create its own
# (e.g. via a separately-scheduled tag-creation workflow), which would
# produce a different tag object for the same commit and break plain
# `git fetch` between the two remotes ("would clobber existing tag").
if [[ x$SYNC_TAGS = 'xtrue' ]]; then
echo "::group::Sync tags"
git fetch upstream --tags --verbose
git push origin --force --tags --verbose
echo "::endgroup::"
fi
kill $SSH_AGENT_PID