Sync a branch to private repo #320
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | |
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 ${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }} -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" | |
echo "---------------------------------------------------------------------------------------------------------------------------" | |
echo "Clone repo" | |
git clone -b ${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }} 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: '${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }}'%gi" $PIPELINE_CONFIG_PATH | |
echo "---------------------------------------------------------------------------------------------------------------------------" | |
echo "Verify productiveBranch has been updated with the synched branch name" | |
if grep -Fq "productiveBranch: '${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }}'" $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 - ${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }}%gi" $AZURE_CONFIG_PATH | |
echo "---------------------------------------------------------------------------------------------------------------------------" | |
echo "Verify trigger has been updated with the synched branch name" | |
if grep -Pzo "trigger:\n - ${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }}" $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=${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }}%gi" $SONAR_PATH | |
echo "---------------------------------------------------------------------------------------------------------------------------" | |
echo "Verify sonar.branch.name has been updated with the synched branch name" | |
if grep -Fq "sonar.branch.name=${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }}" $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 ${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }} |