-
-
Notifications
You must be signed in to change notification settings - Fork 5
76 lines (67 loc) · 2.92 KB
/
azure_synchronisation.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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