Skip to content

Sync a branch to private repo #598

Sync a branch to private repo

Sync a branch to private repo #598

Workflow file for this run

name: Run Script
on:
workflow_dispatch:
inputs:
site_type:
description: 'Enter the type of site (b2c or b2b)'
required: true
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=${{ github.event.inputs.site_type }}
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"
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"
}
function modify_file_to_remove_baseurl() {
local file_location="../spartacus-${version}/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
}
setup_config_dir
update_config
cd "${CONFIG_DIR}" && bash "./run.sh" install_npm
modify_file_to_remove_baseurl
- 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 }}/apps/spartacusstore/* js-storefront/spartacusstore/
git add .
git commit -m "Updated content of js-storefront/spartacusstore"
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-storefront/spartacusstore content",
"body": "This PR updates the content of js-storefront/spartacusstore.",
"head": "'"$branch_name"'",
"base": "main"
}'