-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (43 loc) · 1.73 KB
/
mirror-private-repo.yml
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
# This workflow mirrors the public repository to a private repository
# copies all branches and tags from the public repository to the private repository
name: Mirror to Private Repository
on:
push:
branches:
- main
- dev
workflow_dispatch: # Keeps manual triggering option
jobs:
mirror_repository:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags
- name: Push to private repository
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
TARGET_PRIVATE_MIRROR_REPO: ${{ secrets.TARGET_PRIVATE_MIRROR_REPO }}
run: |
# Configure Git
git config user.name github-actions
git config user.email [email protected]
if [ -z "$GH_TOKEN" ]; then
echo "Error: GH_PAT is not set"
exit 1
fi
# Ensure this is only run in the dashboard-runner repository
REPO_NAME=$(basename -s .git `git config --get remote.origin.url`)
if [ "$REPO_NAME" != "dashboard-runner" ]; then
echo "This action is only allowed to run in the dashboard-runner repository."
exit 0
fi
# Clone the source repository
git clone --mirror https://${GH_TOKEN}@github.com/earthfast/dashboard-runner.git source-repo
cd source-repo
# Push branches to the private repository
git push --prune https://${GH_TOKEN}@github.com/${TARGET_PRIVATE_MIRROR_REPO}.git +refs/heads/*:refs/heads/*
# Push tags to the private repository
git push --prune https://${GH_TOKEN}@github.com/${TARGET_PRIVATE_MIRROR_REPO}.git +refs/tags/*:refs/tags/*
echo "Repository mirrored successfully!"