Skip to content

Sync a branch to private repo #595

Sync a branch to private repo

Sync a branch to private repo #595

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
jobs:
run_script:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
# - 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
# # 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
# # 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 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_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
# # 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}."
# else
# echo "${file_location} does not exist."
# fi
- 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: |
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 "Error: Failed to clone the repository."
fi
# Navigate to the cloned repository
cd cloud-commerce-sample-setup
# Get the current date and time
timestamp=$(date +%Y%m%d%H%M%S)
# Create a new branch with a unique name
branch_name="new_branch_$timestamp"
git checkout -b $branch_name
# Replace the content inside js-storefront/spartacusstore with the content from ./../../spartacus-${{ github.event.inputs.version }}/apps/spartacusstore
rm -rf js-storefront/spartacusstore/*
cp -r ./../../spartacus-${{ github.event.inputs.version }}/apps/spartacusstore/* js-storefront/spartacusstore/
# Add the changes to the new branch
git add .
# Commit the changes
git commit -m "Updated content of js-storefront/spartacusstore"
# Push the changes to the new branch
git push -u https://${{secrets.GH_TEMPORARY_TOKEN}}@github.com/SAP-samples/cloud-commerce-sample-setup.git
# 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"
}'