Skip to content

Commit

Permalink
chore: update git-sync workflow to use secrets for GitLab and GitHub …
Browse files Browse the repository at this point in the history
…tokens and simplify fetch and push commands
  • Loading branch information
iamvikshan committed Nov 18, 2024
1 parent c5c8020 commit 9210456
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/git-sync.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
name: Sync Repositories

on:
# Trigger on pushes to all branches
push:
branches:
- '**'
# Trigger on pull request events
pull_request:
types: [opened, closed]
# Allow manual trigger
workflow_dispatch:
# Run on a schedule (every 6 hours) to catch GitLab changes
schedule:
- cron: '0 */6 * * *'

Expand All @@ -30,23 +26,16 @@ jobs:
- name: Add GitLab remote
run: |
git remote add gitlab https://oauth2:${GITLAB_TOKEN}@gitlab.com/vikshan/amina.git
git remote add gitlab https://oauth2:${{ secrets.GITLAB_TOKEN }}@gitlab.com/vikshan/amina.git
- name: Fetch and sync with GitLab
run: |
# Fetch all branches and tags from GitLab
git fetch gitlab
# Push all GitHub branches to GitLab
git push -f gitlab refs/remotes/origin/*:refs/heads/*
# Push all tags to GitLab
git push -f gitlab --tags
# Pull changes from GitLab and push to GitHub
git pull gitlab --allow-unrelated-histories || true
git push https://${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git --all
git push https://${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git --tags
git push https://${{ secrets.GH_TOKEN }}@github.com/${{ github.repository }}.git --all
git push https://${{ secrets.GH_TOKEN }}@github.com/${{ github.repository }}.git --tags
env:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}

0 comments on commit 9210456

Please sign in to comment.