Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhepS committed Aug 2, 2024
1 parent 0e37aa8 commit fbeaaee
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 82 deletions.
102 changes: 55 additions & 47 deletions .github/workflows/repo-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,63 +20,71 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Run script
run: |
# Define the directory
config_dir="scripts/install"
# - name: Run script
# run: |
# # Define the directory
# config_dir="scripts/install"

# Check if the config_dir directory exists
if [ ! -d "${config_dir}" ]; then
# If not, create it
mkdir -p "${config_dir}"
fi
# # Check if the config_dir directory exists
# if [ ! -d "${config_dir}" ]; then
# # If not, create it
# mkdir -p "${config_dir}"
# fi

# Get user input from workflow dispatch
site_type=${{ github.event.inputs.site_type }}
version=${{ github.event.inputs.version }}
npm_token=${{ github.event.inputs.npm_token }}
# # Get user input from workflow dispatch
# site_type=${{ github.event.inputs.site_type }}
# version=${{ github.event.inputs.version }}
# npm_token=${{ github.event.inputs.npm_token }}

# Check if config.sh already exists in the config_dir directory
if [ -f "${config_dir}/config.sh" ]; then
echo "config.sh already exists in ${config_dir}. Removing it..."
rm "${config_dir}/config.sh"
fi
# # Check if config.sh already exists in the config_dir directory
# if [ -f "${config_dir}/config.sh" ]; then
# echo "config.sh already exists in ${config_dir}. Removing it..."
# rm "${config_dir}/config.sh"
# fi

# Copy the content of config.default.sh to config.sh
cp "${config_dir}/config.default.sh" "${config_dir}/config.sh"
echo "config.sh has been created in ${config_dir}."
# # Copy the content of config.default.sh to config.sh
# cp "${config_dir}/config.default.sh" "${config_dir}/config.sh"
# echo "config.sh has been created in ${config_dir}."

# Set the BASE_SITE value based on user input
if [ "${site_type}" == "b2c" ]; then
sed -i 's/^BASE_SITE=.*/BASE_SITE="electronics-spa"/' "${config_dir}/config.sh"
sed -i 's/^SSR_APP_NAME=.*/SSR_APP_NAME="spartacusstore"/' "${config_dir}/config.sh"
elif [ "${site_type}" == "b2b" ]; then
sed -i 's/^BASE_SITE=.*/BASE_SITE="powertools-spa"/' "${config_dir}/config.sh"
sed -i 's/^SSR_APP_NAME=.*/SSR_APP_NAME="b2bspastore"/' "${config_dir}/config.sh"
else
echo "Invalid site type. BASE_SITE and SSR_APP_NAME not set."
fi
# # Set the BASE_SITE value based on user input
# if [ "${site_type}" == "b2c" ]; then
# sed -i 's/^BASE_SITE=.*/BASE_SITE="electronics-spa"/' "${config_dir}/config.sh"
# sed -i 's/^SSR_APP_NAME=.*/SSR_APP_NAME="spartacusstore"/' "${config_dir}/config.sh"
# elif [ "${site_type}" == "b2b" ]; then
# sed -i 's/^BASE_SITE=.*/BASE_SITE="powertools-spa"/' "${config_dir}/config.sh"
# sed -i 's/^SSR_APP_NAME=.*/SSR_APP_NAME="b2bspastore"/' "${config_dir}/config.sh"
# else
# echo "Invalid site type. BASE_SITE and SSR_APP_NAME not set."
# fi

# Set the SPARTACUS_VERSION value based on user input
sed -i "s/^SPARTACUS_VERSION=.*/SPARTACUS_VERSION='${version}'/" "${config_dir}/config.sh"
# # Set the SPARTACUS_VERSION value based on user input
# sed -i "s/^SPARTACUS_VERSION=.*/SPARTACUS_VERSION='${version}'/" "${config_dir}/config.sh"

# Set the NPM_TOKEN value based on user input
sed -i "s/^NPM_TOKEN=.*/NPM_TOKEN='${npm_token}'/" "${config_dir}/config.sh"
# # Set the NPM_TOKEN value based on user input
# sed -i "s/^NPM_TOKEN=.*/NPM_TOKEN='${npm_token}'/" "${config_dir}/config.sh"

# Set the NPM_URL value
sed -i "s|^NPM_URL=.*|NPM_URL='https://73554900100900004337.dev.npmsrv.base.repositories.cloud.sap/'|" "${config_dir}/config.sh"
# # Set the NPM_URL value
# sed -i "s|^NPM_URL=.*|NPM_URL='https://73554900100900004337.dev.npmsrv.base.repositories.cloud.sap/'|" "${config_dir}/config.sh"

# Navigate to the directory and run the script
cd "${config_dir}" && bash "./run.sh" install_npm
# # Navigate to the directory and run the script
# cd "${config_dir}" && bash "./run.sh" install_npm

# Define the file location
file_location="../../../spartacus-${version}/apps/spartacusstore/src/app/spartacus/spartacus-configuration.module.ts"
# # Define the file location
# file_location="../../../spartacus-${version}/apps/spartacusstore/src/app/spartacus/spartacus-configuration.module.ts"

# Check if the file exists
if [ -f "${file_location}" ]; then
# Comment out baseUrl in spartacus configuration
sed -i 's/baseUrl/\/\/baseUrl/1' "${file_location}"
echo "Modified ${file_location}."
# # Check if the file exists
# if [ -f "${file_location}" ]; then
# # Comment out baseUrl in spartacus configuration
# sed -i 's/baseUrl/\/\/baseUrl/1' "${file_location}"
# echo "Modified ${file_location}."
# else
# echo "${file_location} does not exist."
# fi
- name: Commit changes
run: |
git clone https://${{secrets.GH_TEMPORARY_TOKEN}}@github.com/SAP-samples/cloud-commerce-sample-setup.git
if [ $? -eq 0 ]; then
echo "Repository cloned successfully."
else
echo "${file_location} does not exist."
echo "Error: Failed to clone the repository."
fi
145 changes: 110 additions & 35 deletions .github/workflows/update-ccv2.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,124 @@
on:
schedule:
- cron: '0 0 * * 1,4'
workflow_dispatch:
inputs:
ccv2_branch:
description: Branch on ccv2 to update
default: spa_p4
required: true
source_branch_to_deploy:
description: source branch to deploy on ccv2 (repo default branch if left empty)
branch_to_sync:
description: Branch to sync to the private repository (repo default branch if left empty)
required: false

name: Update ccv2 repo with unreleased Spartacus
name: Sync a branch to private repo

env:
DEFAULT_BRANCH_TO_DEPLOY: ${{ github.event.repository.default_branch }}
DEFAULT_BRANCH_TO_SYNC: ${{ github.event.repository.default_branch }}

jobs:
deploy_to_ccv2:
name: Updating storefront of a ccv2 environment
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@v4
with:
ref: ${{ github.event.inputs.source_branch_to_deploy || env.DEFAULT_BRANCH_TO_DEPLOY }}
ref: ${{ github.event.inputs.branch_to_sync || env.DEFAULT_BRANCH_TO_SYNC }}
fetch-depth: 0
- name: Get commit hash of the branch to deploy
id: branch-to-deploy-commit-id
- 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: |
echo "::set-output name=commit_hash::$(git rev-parse ${{ github.event.inputs.source_branch_to_deploy || env.DEFAULT_BRANCH_TO_DEPLOY }})"
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
key: nodemodules-${{ steps.branch-to-deploy-commit-id.outputs.commit_hash }}
restore-keys: nodemodules-${{ steps.branch-to-deploy-commit-id.outputs.commit_hash }}
- name: Package installation
run: npm ci
- name: Update ccv2 environment with source
env:
CCV2_BRANCH: ${{ github.event.inputs.ccv2_branch }}
SOURCE_BRANCH_TO_DEPLOY: ${{ github.event.inputs.source_branch_to_deploy }}
GHT_USER: ${{ secrets.GHT_USER }}
GHT_PRIVATE_REPO_TOKEN: ${{ secrets.GHT_PRIVATE_REPO_TOKEN }}
GHT_REPO: ${{ secrets.GHT_CCV2_REPO }}
GHT_CCV2_EMAIL: ${{ secrets.GHT_CCV2_EMAIL }}
GHT_CCV2_USERNAME: ${{ secrets.GHT_CCV2_USERNAME }}
run: |
ci-scripts/update-ccv2.sh
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 }}

0 comments on commit fbeaaee

Please sign in to comment.