Skip to content

Commit

Permalink
initial commit migrating v2 stuff to the new repo (#1)
Browse files Browse the repository at this point in the history
* initial commit migrating v2 stuff to the new repo

* add circle ci

* cleanup

* add package-lock

* move front end files around

* add lint

* add mock for tests

* delete dead test code
  • Loading branch information
DerrickGHW authored Aug 24, 2022
1 parent 25c37eb commit 3709630
Show file tree
Hide file tree
Showing 107 changed files with 30,836 additions and 0 deletions.
217 changes: 217 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
version: 2.1

orbs:
swissknife: roopakv/[email protected]
slack: circleci/[email protected]

executors:
sfcc-executor:
docker:
- image: boltdev/sfcc-ci:v1.1.0
auth:
username: $DOCKER_USER
password: $DOCKER_PASSWORD

parameters:
run_release_workflow:
type: boolean
default: false
tag:
type: string
default: "21.1"

commands:
checkout-and-install:
description: Sets up the repo including installing deps
steps:
- checkout:
path: /home/circleci/bolt-demandware-managed
- restore_cache:
keys:
- npm-v2-{{ checksum "package-lock.json" }}
- run:
name: Install Dependencies
command: |
npm install --prefer-offline --no-audit
- run:
name: Compile Assets # check for css and js being generated successfully
command: |
npm run compile
bash .circleci/scripts/test-compile-error.sh
- save_cache:
key: npm-v2-{{ checksum "package-lock.json" }}
paths:
- /home/circleci/.npm
- /home/circleci/bolt-demandware-managed/node_modules

create-zip-artifact:
description: Creates the final zipped artifact for release
steps:
- run:
name: Zip the current release artifact
command: bash .circleci/scripts/create-zip-artifacts.sh << pipeline.parameters.tag >>
- persist_to_workspace:
root: ../artifacts
paths:
- "*.zip"
- "release-artifacts.sh"
- "*.txt"
- store_artifacts:
path: ../artifacts

notify-buildcop:
description: Notify build cop if tests fail on master
steps:
- slack/status:
fail_only: true
failure_message: ":red_circle: A $CIRCLE_JOB job has failed!"
only_for_branches: master
webhook: $GREENKEEPER_WEBHOOK

jobs:
lint-and-unit-test:
working_directory: /home/circleci/bolt-demandware-managed
executor: sfcc-executor
steps:
- checkout-and-install
- run:
name: Lint
command: |
npm run lint
- run:
name: Unit Test
command: |
npm run test:unit
- notify-buildcop

# TODO: fix this to run against v2 cartridge. This currently runs on zzgv-002 which is for V1
integration-tests:
working_directory: /home/circleci/bolt-demandware-managed
executor: sfcc-executor
steps:
- checkout-and-install
- run:
name: Running integration tests against zzgv-002
command: bash .circleci/scripts/run-integration-tests.sh
- notify-buildcop

update-qa-sandbox:
working_directory: /home/circleci/bolt-demandware-managed
executor: sfcc-executor
steps:
- checkout-and-install
- run:
name: Setup dw.json for meta upload
command: |
echo "{" \
"\"hostname\":\"${QA_V2_SANDBOX_HOSTNAME}\"" \
"}" > dw.json
- run:
name: Upload metadata to QA-v2 sandbox zzgv-003
command: |
sfcc-ci client:auth ${SFCCCLIENTID} ${SFCCCLIENTSECRET}
npm run uploadMetadata
- run:
name: Reset dw.json #On meta upload process, adding user/password data to dw.json causes auth issue, it's a SFCC bug
command: |
rm dw.json
- run:
name: Setup dw.json for cartridge upload
command: |
echo "{" \
"\"hostname\":\"${QA_V2_SANDBOX_HOSTNAME}\"," \
"\"client-id\":\"${SFCCCLIENTID}\"," \
"\"client-secret\":\"${SFCCCLIENTSECRET}\"," \
"\"username\":\"${SFCC_QA_ACCOUNT}\"," \
"\"password\":\"${SFCC_QA_ACCOUNT_PW}\"," \
"\"code-version\":\"qa_version\"" \
"}" > dw.json
- run:
name: Upload cartridges to QA-v2 sandbox zzgv-003
command: |
npm run upload:all
bash .circleci/scripts/upload-cartridges.sh
- notify-buildcop

publish-github-release:
docker:
- image: circleci/golang:1.10
steps:
- attach_workspace:
at: ../artifacts
- run:
name: "Publish Release on GitHub"
command: bash ../artifacts/release-artifacts.sh << pipeline.parameters.tag >>

create-release:
working_directory: /home/circleci/bolt-demandware-managed
executor: sfcc-executor
steps:
- checkout-and-install
- create-zip-artifact

create-auto-release:
working_directory: /home/circleci/bolt-demandware-managed
executor: sfcc-executor
steps:
- checkout-and-install
- run:
name: Zip the current release artifact
command: bash .circleci/scripts/auto-release.sh

workflows:
sfcc-flow:
when:
not: << pipeline.parameters.run_release_workflow >>
jobs:
- lint-and-unit-test:
context: sfcc-creds

- integration-tests:
context: sfcc-creds
requires:
- update-qa-sandbox
filters:
branches:
only:
- master

- update-qa-sandbox:
context: sfcc-creds
filters:
branches:
only:
- master

sfcc-release-flow:
when: << pipeline.parameters.run_release_workflow >>
jobs:
- create-release:
context: sfcc-creds
- publish-github-release:
requires:
- create-release
context: sfcc-creds
filters:
branches:
only:
- master
- /release\/.*/

# auto-release:
# triggers:
# - schedule:
# cron: '0 5 1 * *'
# filters:
# branches:
# only:
# - master
# - /release\/.*/
# jobs:
# - create-auto-release:
# context: sfcc-creds
# filters:
# branches:
# only:
# - master
# - /release\/.*/
18 changes: 18 additions & 0 deletions .circleci/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM cimg/node:10.22

USER root
COPY sfcc-ci-linux .
RUN chmod +x ./sfcc-ci-linux
RUN sudo mv ./sfcc-ci-linux /usr/local/bin/sfcc-ci

USER circleci
WORKDIR /home/circleci
COPY storefront-reference-architecture-master.zip .
RUN unzip storefront-reference-architecture-master.zip && \
mv storefront-reference-architecture-master storefront-reference-architecture && \
cd storefront-reference-architecture && \
npm install

RUN sfcc-ci --help

RUN rm -rf /home/circleci/project
23 changes: 23 additions & 0 deletions .circleci/scripts/auto-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

PREVREL=$(git for-each-ref --sort=-creatordate --format="%(refname:short)|%(creatordate:unix)" refs/tags/* | head -n 1)

taggedDate=$(echo $PREVREL | cut -d"|" -f2)
releaseCyclePeriod=$(date --date "10 days ago" +"%s")

if [[ ${taggedDate} -lt ${releaseCyclePeriod} ]]; then
OLDTAGNAME=$(echo $PREVREL | cut -d"|" -f1)
NEWTAGNAME=$(echo $OLDTAGNAME | awk -F. '{print $1 "." $2 "." $3+1}')

echo $NEWTAGNAME

curl -u ${CIRCLE_TOKEN}: -X POST --header "Content-Type: application/json" -d '{
"parameters": {
"tag": '"\""$NEWTAGNAME"\""',
"run_release_workflow": true
}
}' https://circleci.com/api/v2/project/gh/BoltApp/bolt-demandware/pipeline
else
echo "No release this week"
circleci-agent step halt
fi
19 changes: 19 additions & 0 deletions .circleci/scripts/automate-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# install dependencies and upload cartridges and metadata
echo Fetching latest master
currentBranch=$(git branch --show-current)
cd ../../
git checkout master
git pull
git checkout $currentBranch

echo Upload cartridge and metadata....
echo Installing dependencies
npm install
echo Compiling + Transpiling cartridges
npm run build

echo Uploading cartridges
npm run upload:all

echo Uploading Metadata
npm run uploadMetadata
81 changes: 81 additions & 0 deletions .circleci/scripts/create-zip-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash

GIT_TAG=$1

merchantList=()
# Load merchant list
merchants="./.circleci/scripts/merchants.txt"
if ! test -f "$merchants"; then
echo "Cannot find the merchants file."
exit 1
fi
echo "The following merchant versions will be released:"
echo "$GIT_TAG"
while IFS= read -r MERCHANT_NAME || [[ -n "$MERCHANT_NAME" ]]; do
if [ ${#MERCHANT_NAME} -gt 0 ]; then
merchantList+=("$MERCHANT_NAME")
echo "$GIT_TAG-$MERCHANT_NAME"
fi
done <"$merchants"

# Create release artifacts per mechant
create_release() {
local MERCHANT_NAME=$1
pwd
cd ../"$MERCHANT_NAME" || exit
DIR_PATH="cartridges/int_bolt_extensions/cartridge/scripts/merchant-custom/"
DIR_PATH_PREFIX="src/"
echo "Creating zip for $MERCHANT_NAME"
for dir in "${DIR_PATH}"*/; do
dir=${dir%*/}
CURR_MX="${dir##*/}"
# Delete all other merchant specific code in the src/cartridges/ and cartridges/
if [[ "$MERCHANT_NAME" != "$CURR_MX" ]]; then
EXCLUDE_PATH="${DIR_PATH_PREFIX}${DIR_PATH}${CURR_MX}/"
rm -rf "$EXCLUDE_PATH"
EXCLUDE_PATH="${DIR_PATH}${CURR_MX}/"
rm -rf "$EXCLUDE_PATH"
else
# Update MERCHANT_NAME in metadata
METADATA_PATH="metadata/bolt-meta-import/meta/system-objecttype-extensions.xml"
sed -i.bak "s/MERCHANT_NAME/${CURR_MX}/g" $METADATA_PATH
rm $METADATA_PATH.bak
# Delete extraneous cartridges defined in delete.txt
DELETE_PATH="${DIR_PATH}${CURR_MX}/delete.txt"
while IFS= read -r CARTRIDGE || [[ -n "$CARTRIDGE" ]]; do
if [ ${#CARTRIDGE} -gt 0 ]; then
echo "Deleting $CARTRIDGE"
CARTRIDGES_DIR="cartridges/"
rm -rf "${DIR_PATH_PREFIX}${CARTRIDGES_DIR}${CARTRIDGE}"
rm -rf "${CARTRIDGES_DIR}${CARTRIDGE}"
fi
done <"$DELETE_PATH"
rm -rf "$DELETE_PATH"
rm -rf "${DIR_PATH_PREFIX}$DELETE_PATH"
fi
done
# Run Merchant custom linter
CUSTOM_LINT_FILE="./src/cartridges/int_bolt_extensions/cartridge/scripts/merchant-custom/${MERCHANT_NAME}/.lint.json"
if test -f "$CUSTOM_LINT_FILE"; then
echo "====== Start Custom Merchant Linter ========="
npx eslint --format unix --ext .jsx,.js --cache --cache-location node_modules/eslintcache/cache . --fix --config "$CUSTOM_LINT_FILE"
npx babel ./src/cartridges -d ./cartridges --copy-files
echo "====== End Custom Merchant Linter ========="
else
echo "No Custom Merchant Linter Found"
fi
# Zip the artifact into artifacts directory as v<TAG>-<MERCHANT_NAME>.zip
zip -r ../artifacts/"$GIT_TAG-$MERCHANT_NAME".zip . -x ".git/*" "node_modules/*" ".circleci/*" "src/*"
cd ../bolt-demandware || exit
rm -rf "$MERCHANT_NAME:?x/"
}

# Create Artifacts directory
mkdir ../artifacts
for merchant in "${merchantList[@]}"; do
cp -r . ../"$merchant"
create_release "$merchant"
done

# Copy release script for the next build step
cp .circleci/scripts/release-artifacts.sh ../artifacts
Loading

0 comments on commit 3709630

Please sign in to comment.