Skip to content

Merge pull request #142 from SaintAngeLs/frontend_posts #754

Merge pull request #142 from SaintAngeLs/frontend_posts

Merge pull request #142 from SaintAngeLs/frontend_posts #754

name: Sync to Azure DevOps Repository
on:
push:
branches:
- '*'
pull_request:
jobs:
Sync:
runs-on: ubuntu-latest
env:
AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }}
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0 # Fetch all branches
- name: Configuring git
run: |
git config --global user.email "voznesenskijandrej5@gmail.com"
git config --global user.name "Andrii Voznesenskyi"
- name: Adding Azure DevOps remote repository
env:
AZURE_DEVOPS_USERNAME: ${{ secrets.AZURE_DEVOPS_USERNAME }}
AZURE_DEVOPS_PASSWORD: ${{ secrets.AZURE_DEVOPS_PASSWORD }}
run: |
# git remote add azure https://$AZURE_DEVOPS_USERNAME:$AZURE_DEVOPS_PASSWORD@dev.azure.com/SocialAppOIPproject/SocialApp_IO/_git/SocialApp_IO
# Check if the remote already exists
if git remote get-url azure; then
echo "Remote 'azure' already exists. Updating URL if needed."
git remote set-url azure https://$AZURE_DEVOPS_PAT@dev.azure.com/SocialAppOIPproject/SocialApp_IO/_git/SocialApp_IO
else
git remote add azure https://$AZURE_DEVOPS_PAT@dev.azure.com/SocialAppOIPproject/SocialApp_IO/_git/SocialApp_IO
fi
- name: Push all branches to Azure DevOps
run: git push azure --all --force
- name: Push all tags to Azure DevOps
run: git push azure --tags --force
- name: Push pull requests to Azure DevOps
run: |
# Fetch the pull request refs
git fetch origin +refs/pull/*:refs/remotes/origin/pr/*
# Push each pull request ref to Azure DevOps
for ref in $(git for-each-ref --format='%(refname)' refs/remotes/origin/pr/*); do
pr_ref=${ref#refs/remotes/origin/pr/}
# Split the ref by / and get the PR number
IFS='/' read -ra ADDR <<< "$pr_ref"
pr_number=${ADDR[0]}
# Check out the PR head branch
git fetch origin pull/$pr_number/head:pr-$pr_number
git checkout pr-$pr_number
# Push the PR head branch to Azure as a branch named pr-{PR number}
git push azure pr-$pr_number:refs/heads/pr-$pr_number --force
done
# # Important branches anlizer:
# - name: Checkout and push all branches to Azure DevOps
# run: |
# for branch in $(git branch -a | grep 'remotes/origin/' | sed 's/remotes\/origin\///'); do
# if git rev-parse --verify $branch > /dev/null 2>&1; then
# # If branch exists locally, just checkout
# git checkout $branch
# else
# # If branch does not exist locally, create it tracking the remote
# git checkout -b $branch origin/$branch
# fi
# git push azure $branch:$branch --force -v
# done