|
| 1 | +# GitHub Actions workflow file to sync an external repository to this GitHub mirror. |
| 2 | +# This file was automatically generated by go-github-sync. |
| 3 | +# |
| 4 | +# The workflow does the following: |
| 5 | +# - Runs on a scheduled basis (and can also be triggered manually) |
| 6 | +# - Clones the GitHub mirror repository |
| 7 | +# - Fetches changes from the primary external repository |
| 8 | +# - Applies those changes to the mirror repository |
| 9 | +# - Pushes the updated content back to the GitHub mirror |
| 10 | +# |
| 11 | +# Authentication is handled by the GITHUB_TOKEN secret provided by GitHub Actions. |
| 12 | + |
| 13 | +jobs: |
| 14 | + sync: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Validate Github Actions Environment |
| 18 | + run: if [ "$GITHUB_ACTIONS" != "true" ]; then echo 'This script must be run in a GitHub Actions environment.'; exit 1; fi |
| 19 | + - name: Checkout GitHub Mirror |
| 20 | + uses: actions/checkout@v3 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + - name: Configure Git |
| 24 | + run: |- |
| 25 | + git config user.name 'GitHub Actions' |
| 26 | + git config user.email 'actions@github.com' |
| 27 | + - env: |
| 28 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + name: Sync Primary Repository |
| 30 | + run: |- |
| 31 | + # Add the primary repository as a remote |
| 32 | + git remote add primary https://i2pgit.org/I2P_Developers/i2p.scripts.git |
| 33 | +
|
| 34 | + # Fetch the latest changes from the primary repository |
| 35 | + git fetch primary |
| 36 | +
|
| 37 | + # Check if the primary branch exists in the primary repository |
| 38 | + if git ls-remote --heads primary master | grep -q master; then |
| 39 | + echo "Primary branch master found in primary repository" |
| 40 | + else |
| 41 | + echo "Error: Primary branch master not found in primary repository" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +
|
| 45 | + # Check if we're already on the mirror branch |
| 46 | + if git rev-parse --verify --quiet master; then |
| 47 | + git checkout master |
| 48 | + else |
| 49 | + # Create the mirror branch if it doesn't exist |
| 50 | + git checkout -b master |
| 51 | + fi |
| 52 | +
|
| 53 | +
|
| 54 | + # Force-apply all changes from primary, overriding any conflicts |
| 55 | + echo "Performing force sync from primary/master to master" |
| 56 | + git reset --hard primary/master |
| 57 | +
|
| 58 | +
|
| 59 | + # Push changes back to the mirror repository |
| 60 | + git push origin master |
| 61 | +name: Sync Primary Repository to GitHub Mirror |
| 62 | +"on": |
| 63 | + push: {} |
| 64 | + schedule: |
| 65 | + - cron: 0 * * * * |
| 66 | + workflow_dispatch: {} |
0 commit comments