Sync a branch to private repo #343
Workflow file for this run
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: | | |
PUBLIC_REPOSITORY_BRANCH_NAME=${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }} | |
PRIVATE_REPOSITORY_BRANCH_NAME=${PUBLIC_REPOSITORY_BRANCH_NAME//\//-} | |
git push -u https://${{ secrets.GHT_USER }}:${{ secrets.GHT_PRIVATE_REPO_TOKEN }}@github.tools.sap/cx-commerce-storefronts/${{ secrets.GHT_SPARTACUS_REPO }}.git $PRIVATE_REPOSITORY_BRANCH_NAME -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 |