-
Notifications
You must be signed in to change notification settings - Fork 387
128 lines (100 loc) · 6.25 KB
/
repo-sync.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
on:
schedule:
- cron: '0 0 * * 1,4'
workflow_dispatch:
inputs:
branch_to_sync:
description: Branch to sync to the private repository (repo default branch if left empty)
required: false
name: Sync a branch to private repo
env:
DEFAULT_BRANCH_TO_SYNC: ${{ github.event.repository.default_branch }}
PUBLIC_BRANCH: ${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }}
PRIVATE_BRANCH: ${{ PUBLIC_BRANCH//\//- }}
jobs:
sync_public_repo_to_private:
name: Force sync a branch to the private repository with current git history
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }}
fetch-depth: 0
- name: Push a branch to the private repository
run: |
git push -u https://${{ secrets.GHT_USER }}:${{ secrets.GHT_PRIVATE_REPO_TOKEN }}@github.tools.sap/cx-commerce-storefronts/${{ secrets.GHT_SPARTACUS_REPO }}.git ${{ env.PRIVATE_BRANCH }} -f
- name: Include remaining pipeline files to the private remote's branch
run: |
PIPELINE_CONFIG_PATH="./.pipeline/config.yml"
AZURE_CONFIG_PATH="./azure-pipelines.yml"
SONAR_PATH="./sonar-project.properties"
RELEASE_PACKAGES_LIST_GENERATOR="./ci-scripts/release-packages-list-generator.sh"
PUBLIC_REPOSITORY_BRANCH_NAME=${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }}
PRIVATE_REPOSITORY_BRANCH_NAME=${PUBLIC_REPOSITORY_BRANCH_NAME//\//-}
echo "---------------------------------------------------------------------------------------------------------------------------"
echo "Clone repo"
git clone -b $PRIVATE_REPOSITORY_BRANCH_NAME https://${{ secrets.GHT_USER }}:${{ secrets.GHT_PRIVATE_REPO_TOKEN }}@github.tools.sap/cx-commerce-storefronts/${{ secrets.GHT_SPARTACUS_REPO }}.git
cd ${{ secrets.GHT_SPARTACUS_REPO }}
git config --global user.email ${{ secrets.GHT_EMAIL }}
git config --global user.name ${{ secrets.GHT_USER }}
echo "---------------------------------------------------------------------------------------------------------------------------"
echo "Get files from other branch"
git checkout origin/sap-pipeline-files -- .
echo "---------------------------------------------------------------------------------------------------------------------------"
echo "Configure pipeline"
sed -i "s%productiveBranch:%productiveBranch: $PRIVATE_REPOSITORY_BRANCH_NAME%gi" $PIPELINE_CONFIG_PATH
echo "---------------------------------------------------------------------------------------------------------------------------"
echo "Verify productiveBranch has been updated with the synched branch name"
if grep -Fq "productiveBranch: $PRIVATE_REPOSITORY_BRANCH_NAME" $PIPELINE_CONFIG_PATH
then
echo "Branch name has successfully been added to the productiveBranch"
else
echo "Error. Branch name has NOT been added to the productiveBranch"
exit 1
fi
echo "---------------------------------------------------------------------------------------------------------------------------"
echo "Configure azure pipeline trigger"
sed -i "s%trigger:%trigger:\n - $PRIVATE_REPOSITORY_BRANCH_NAME%gi" $AZURE_CONFIG_PATH
echo "---------------------------------------------------------------------------------------------------------------------------"
echo "Verify trigger has been updated with the synched branch name"
if grep -Pzo "trigger:\n - $PRIVATE_REPOSITORY_BRANCH_NAME" $AZURE_CONFIG_PATH
then
echo "Branch name has successfully been added to the trigger"
else
echo "Error. Branch name has NOT been added to the trigger"
exit 1
fi
echo "---------------------------------------------------------------------------------------------------------------------------"
echo "Configure azure pipeline build packages list"
RELEASE_PACKAGES=$($RELEASE_PACKAGES_LIST_GENERATOR)
FORMATTED_RELEASE_PACKAGES=""
for PACKAGE in $RELEASE_PACKAGES; do
FORMATTED_RELEASE_PACKAGES+=" - ${PACKAGE}\n"
done
sed -i "s%buildPackages:%buildPackages:\n${FORMATTED_RELEASE_PACKAGES}%gi" $AZURE_CONFIG_PATH
echo "---------------------------------------------------------------------------------------------------------------------------"
echo "Verify buildPackages parameter has been updated with the generated release packages list"
if grep -Pzo "buildPackages:\n${FORMATTED_RELEASE_PACKAGES}" $AZURE_CONFIG_PATH
then
echo "List of packages to release has successfully been added to the buildPackages parameter"
else
echo "Error. List of packages to release has NOT been added to the buildPackages parameter"
exit 1
fi
echo "---------------------------------------------------------------------------------------------------------------------------"
echo "Configure sonar"
sed -i "s%sonar.branch.name=%sonar.branch.name=$PRIVATE_REPOSITORY_BRANCH_NAME%gi" $SONAR_PATH
echo "---------------------------------------------------------------------------------------------------------------------------"
echo "Verify sonar.branch.name has been updated with the synched branch name"
if grep -Fq "sonar.branch.name=$PRIVATE_REPOSITORY_BRANCH_NAME" $SONAR_PATH
then
echo "Branch name has successfully been added to the sonar.branch.name"
else
echo "Error. Branch name has NOT been added to the sonar.branch.name"
exit 1
fi
echo "---------------------------------------------------------------------------------------------------------------------------"
echo "Include files to synced branch"
git add .
git commit -m "include remaining pipeline files"
git push origin $PRIVATE_REPOSITORY_BRANCH_NAME