55 lines
1.5 KiB
YAML
55 lines
1.5 KiB
YAML
name: Mirror to GitHub
|
|
description: Mirror the current repo to GitHub.
|
|
|
|
inputs:
|
|
target:
|
|
description: "GitHub repo (e.g. owner/repo)"
|
|
required: true
|
|
source:
|
|
description: "Authenticated clone URL for the source repo"
|
|
required: true
|
|
token:
|
|
description: "GitHub personal access token with push access"
|
|
required: true
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Install git-filter-repo
|
|
shell: bash
|
|
run: pip install --break-system-packages git-filter-repo
|
|
|
|
- name: Clone mirror
|
|
shell: bash
|
|
run: git clone --bare "$GITHUB_WORKSPACE" /tmp/mirror-repo
|
|
|
|
- name: Filter ignored paths
|
|
shell: bash
|
|
run: |
|
|
MIRRORIGNORE="$GITHUB_WORKSPACE/.mirrorignore"
|
|
if [ ! -f "$MIRRORIGNORE" ]; then
|
|
echo "No .mirrorignore found, skipping filter"
|
|
exit 0
|
|
fi
|
|
|
|
ARGS=""
|
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
line="$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
|
|
[ -z "$line" ] && continue
|
|
[[ "$line" == \#* ]] && continue
|
|
ARGS="$ARGS --path $line"
|
|
done < "$MIRRORIGNORE"
|
|
|
|
# Always filter .mirrorignore itself
|
|
ARGS="$ARGS --path .mirrorignore"
|
|
|
|
if [ -n "$ARGS" ]; then
|
|
cd /tmp/mirror-repo
|
|
git filter-repo $ARGS --invert-paths --force
|
|
fi
|
|
|
|
- name: Push mirror
|
|
shell: bash
|
|
run: |
|
|
cd /tmp/mirror-repo
|
|
git push --mirror "https://${{ inputs.token }}@github.com/${{ inputs.target }}.git"
|