mirror of
https://github.com/go-i2p/go-github-sync.git
synced 2025-12-20 12:15:54 -05:00
71 lines
2.4 KiB
YAML
71 lines
2.4 KiB
YAML
# GitHub Actions workflow file to sync an external repository to this GitHub mirror.
|
|
# This file was automatically generated by go-github-sync.
|
|
#
|
|
# The workflow does the following:
|
|
# - Runs on a scheduled basis (and can also be triggered manually)
|
|
# - Clones the GitHub mirror repository
|
|
# - Fetches changes from the primary external repository
|
|
# - Applies those changes to the mirror repository
|
|
# - Pushes the updated content back to the GitHub mirror
|
|
#
|
|
# Authentication is handled by the GITHUB_TOKEN secret provided by GitHub Actions.
|
|
|
|
jobs:
|
|
sync:
|
|
env:
|
|
GITHUB_ACTIONS_ENVIRONMENT: ${{ github.action }}
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Security Check
|
|
run: if [ "$GITHUB_ACTIONS_ENVIRONMENT" == "" ]; then echo "This workflow is only intended to run inside GitHub Actions"; exit 1; fi
|
|
- name: Checkout GitHub Mirror
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Configure Git
|
|
run: |-
|
|
git config user.name 'GitHub Actions'
|
|
git config user.email 'actions@github.com'
|
|
- env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
name: Sync Primary Repository
|
|
run: |-
|
|
# Add the primary repository as a remote
|
|
git remote add primary https://i2pgit.org/go-i2p/go-github-sync.git
|
|
|
|
# Fetch the latest changes from the primary repository
|
|
git fetch primary
|
|
|
|
# Check if the primary branch exists in the primary repository
|
|
if git ls-remote --heads primary main | grep -q main; then
|
|
echo "Primary branch main found in primary repository"
|
|
else
|
|
echo "Error: Primary branch main not found in primary repository"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if we're already on the mirror branch
|
|
if git rev-parse --verify --quiet main; then
|
|
git checkout main
|
|
else
|
|
# Create the mirror branch if it doesn't exist
|
|
git checkout -b main
|
|
fi
|
|
|
|
|
|
# Force-apply all changes from primary, overriding any conflicts
|
|
echo "Performing force sync from primary/main to main"
|
|
git reset --hard primary/main
|
|
|
|
|
|
# Push changes back to the mirror repository
|
|
git push origin main
|
|
name: Sync Primary Repository to GitHub Mirror
|
|
"on":
|
|
schedule:
|
|
- cron: 0 * * * *
|
|
workflow_dispatch: {}
|
|
permissions:
|
|
actions: read
|
|
contents: write
|