Skip to content

Sync a branch to private repo #599

Sync a branch to private repo

Sync a branch to private repo #599

Workflow file for this run

name: Run Script
on:
workflow_dispatch:
inputs:
version:
description: 'Enter the version to use'
required: true
npm_token:
description: 'Enter your npm token'
required: true
secret: true
env:
CONFIG_DIR: scripts/install
REPO_URL: https://${{secrets.GH_TEMPORARY_TOKEN}}@github.com/SAP-samples/cloud-commerce-sample-setup.git
jobs:
run_script:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Run script
run: |
function setup_config_dir() {
[ -d "${CONFIG_DIR}" ] || mkdir -p "${CONFIG_DIR}"
cp "${CONFIG_DIR}/config.default.sh" "${CONFIG_DIR}/config.sh"
}
function update_config() {
local site_type=$1
local version=${{ github.event.inputs.version }}
local npm_token=${{ github.event.inputs.npm_token }}
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"
sed -i '/ADD_B2B_LIBS/c\ADD_B2B_LIBS=true' "${config_dir}/config.sh"
else
echo "Invalid site type. BASE_SITE and SSR_APP_NAME not set."
fi
sed -i "s/^SPARTACUS_VERSION=.*/SPARTACUS_VERSION='${version}'/" "${CONFIG_DIR}/config.sh"
sed -i "s/^NPM_TOKEN=.*/NPM_TOKEN='${npm_token}'/" "${CONFIG_DIR}/config.sh"
sed -i "s|^NPM_URL=.*|NPM_URL='https://73554900100900004337.dev.npmsrv.base.repositories.cloud.sap/'|" "${CONFIG_DIR}/config.sh"
}
if [ "${site_type}" == "b2c" ]; then
mv ../spartacus-${version} ../spartacus-${version}-b2c
elif [ "${site_type}" == "b2b" ]; then
mv ../spartacus-${version} ../spartacus-${version}-b2b
fi
function modify_file_to_remove_baseurl() {
local file_location="../spartacus-${version}-${site_type}/apps/spartacusstore/src/app/spartacus/spartacus-configuration.module.ts"
if [ -f "${file_location}" ]; then
sed -i 's/baseUrl/\/\/baseUrl/1' "${file_location}"
echo "Modified ${file_location}."
else
echo "${file_location} does not exist."
fi
}
# Array of site types
site_types=("b2c" "b2b")
# Loop over site types
for site_type in "${site_types[@]}"; do
setup_config_dir
update_config $site_type
cd "${CONFIG_DIR}" && bash "./run.sh" install_npm
modify_file_to_remove_baseurl $site_type
done
- name: Set Git user
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Commit changes
run: |
function clone_and_setup_repo() {
git clone $REPO_URL
cd cloud-commerce-sample-setup
# Create a new branch with a unique name
branch_name="new_branch_$timestamp"
git checkout -b $branch_name
rm -rf js-storefront/spartacusstore/*
cp -r ./../../spartacus-${{ github.event.inputs.version }}-b2c/apps/spartacusstore/* js-storefront/spartacusstore/
git add .
git commit -m "Updated content of js-storefront/spartacusstore"
rm -rf js-storefront/b2bspastore/*
cp -r ./../../spartacus-${{ github.event.inputs.version }}-b2b/apps/b2bspastore/* js-storefront/b2bspastore/
git add .
git commit -m "Updated content of js-storefront/b2bspastore"
git push -u $REPO_URL
}
clone_and_setup_repo
# Echo the branch name so it can be used in later steps
echo "branch_name=$branch_name" >> $GITHUB_ENV
- name: Create Pull Request
run: |
curl -X POST -H "Authorization: token ${{ secrets.GH_TEMPORARY_TOKEN }}" -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/SAP-samples/cloud-commerce-sample-setup/pulls \
-d '{
"title": "Update js-storefronts content",
"body": "This PR updates the content of the js-storefronts.",
"head": "'"$branch_name"'",
"base": "main"
}'