diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..628deeb6 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,32 @@ +name: Node.js CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Yarn CLI + uses: CultureHQ/actions-yarn@v1.0.1 + - run: yarn + - run: yarn build + - run: yarn nowatch-test + - run: yarn lint + - run: yarn check-deps diff --git a/package.json b/package.json index 5b155300..5d9c4fd6 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "start": "ng serve", "build": "ng build", "test": "ng test", + "nowatch-test": "ng test --watch=false", "lint": "ng lint", "e2e": "ng e2e", "prepare": "husky install", diff --git a/scripts/build_client.sh b/scripts/build_client.sh new file mode 100755 index 00000000..a9f61d4f --- /dev/null +++ b/scripts/build_client.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +echo "Start getting modules"; +npm install; +echo "Start build process"; +if [ -z $1 ] +then + npm run build --configuration +else + npm rum configuration production +fi +echo "Check if previous version archive exist" +archive_name=app.zip; +cd ../dist; +if [ -f "./$archive_name" ] +then + echo "Delete previous version" + rm "./$archive_name"; +fi +echo "Create new archive" +zip -rm $archive_name app; diff --git a/scripts/pipeline-2023-03-22T20:42:56+04:00.json b/scripts/pipeline-2023-03-22T20:42:56+04:00.json new file mode 100644 index 00000000..8d4ec09b --- /dev/null +++ b/scripts/pipeline-2023-03-22T20:42:56+04:00.json @@ -0,0 +1,121 @@ +{ + "pipeline": { + "name": "angular-shop", + "roleArn": "roleArn", + "artifactStore": { + "type": "S3", + "location": "codepipeline-artifactStore-location" + }, + "stages": [ + { + "name": "Source", + "actions": [ + { + "name": "Source", + "actionTypeId": { + "category": "Source", + "owner": "ThirdParty", + "provider": "GitHub", + "version": "1" + }, + "runOrder": 1, + "configuration": { + "Branch": "master", + "OAuthToken": "****", + "Owner": "mihan-pro", + "PollForSourceChanges": "true", + "Repo": "shop-angular-cloudfront" + }, + "outputArtifacts": [ + { + "name": "SourceArtifact" + } + ], + "inputArtifacts": [], + "region": "us-east-1", + "namespace": "SourceVariables" + } + ] + }, + { + "name": "QualityGate", + "actions": [ + { + "name": "LintingAntUnitTesting", + "actionTypeId": { + "category": "Build", + "owner": "AWS", + "provider": "CodeBuild", + "version": "1" + }, + "runOrder": 1, + "configuration": { + "EnvironmentVariables": "[{\"name\":\"BUILD_CONFIGURATION\",\"value\":\"{{BUILD_CONFIGURATION value}}\",\"type\":\"PLAINTEXT\"}]", + "ProjectName": "client-app-quality" + }, + "outputArtifacts": [], + "inputArtifacts": [ + { + "name": "SourceArtifact" + } + ], + "region": "us-east-1" + } + ] + }, + { + "name": "Approve", + "actions": [ + { + "name": "ManualApproval", + "actionTypeId": { + "category": "Approval", + "owner": "AWS", + "provider": "Manual", + "version": "1" + }, + "runOrder": 1, + "configuration": { + "CustomData": "Approve me" + }, + "outputArtifacts": [], + "inputArtifacts": [], + "region": "us-east-1" + } + ] + }, + { + "name": "Build", + "actions": [ + { + "name": "BuildAndDeploy", + "actionTypeId": { + "category": "Build", + "owner": "AWS", + "provider": "CodeBuild", + "version": "1" + }, + "runOrder": 1, + "configuration": { + "EnvironmentVariables": "[{\"name\":\"BUILD_CONFIGURATION\",\"value\":\"{{BUILD_CONFIGURATION value}}\",\"type\":\"PLAINTEXT\"}]", + "ProjectName": "client-app-build" + }, + "outputArtifacts": [ + { + "name": "BuildArtifact" + } + ], + "inputArtifacts": [ + { + "name": "SourceArtifact" + } + ], + "region": "us-east-1", + "namespace": "BuildVariables" + } + ] + } + ], + "version": "2" + } +} diff --git a/scripts/pipeline.json b/scripts/pipeline.json new file mode 100644 index 00000000..5d4b05a0 --- /dev/null +++ b/scripts/pipeline.json @@ -0,0 +1,127 @@ +{ + "pipeline": { + "name": "angular-shop", + "roleArn": "roleArn", + "artifactStore": { + "type": "S3", + "location": "codepipeline-artifactStore-location" + }, + "stages": [ + { + "name": "Source", + "actions": [ + { + "name": "Source", + "actionTypeId": { + "category": "Source", + "owner": "ThirdParty", + "provider": "GitHub", + "version": "1" + }, + "runOrder": 1, + "configuration": { + "Branch": "{{Branch name}}", + "OAuthToken": "****", + "Owner": "{{GitHub Owner}}", + "PollForSourceChanges": "{{PollForSourceChanges}}", + "Repo": "shop-angular-cloudfront" + }, + "outputArtifacts": [ + { + "name": "SourceArtifact" + } + ], + "inputArtifacts": [], + "region": "us-east-1", + "namespace": "SourceVariables" + } + ] + }, + { + "name": "QualityGate", + "actions": [ + { + "name": "LintingAntUnitTesting", + "actionTypeId": { + "category": "Build", + "owner": "AWS", + "provider": "CodeBuild", + "version": "1" + }, + "runOrder": 1, + "configuration": { + "EnvironmentVariables": "[{\"name\":\"BUILD_CONFIGURATION\",\"value\":\"{{BUILD_CONFIGURATION value}}\",\"type\":\"PLAINTEXT\"}]", + "ProjectName": "client-app-quality" + }, + "outputArtifacts": [], + "inputArtifacts": [ + { + "name": "SourceArtifact" + } + ], + "region": "us-east-1" + } + ] + }, + { + "name": "Approve", + "actions": [ + { + "name": "ManualApproval", + "actionTypeId": { + "category": "Approval", + "owner": "AWS", + "provider": "Manual", + "version": "1" + }, + "runOrder": 1, + "configuration": { + "CustomData": "Approve me" + }, + "outputArtifacts": [], + "inputArtifacts": [], + "region": "us-east-1" + } + ] + }, + { + "name": "Build", + "actions": [ + { + "name": "BuildAndDeploy", + "actionTypeId": { + "category": "Build", + "owner": "AWS", + "provider": "CodeBuild", + "version": "1" + }, + "runOrder": 1, + "configuration": { + "EnvironmentVariables": "[{\"name\":\"BUILD_CONFIGURATION\",\"value\":\"{{BUILD_CONFIGURATION value}}\",\"type\":\"PLAINTEXT\"}]", + "ProjectName": "client-app-build" + }, + "outputArtifacts": [ + { + "name": "BuildArtifact" + } + ], + "inputArtifacts": [ + { + "name": "SourceArtifact" + } + ], + "region": "us-east-1", + "namespace": "BuildVariables" + } + ] + } + ], + "version": 1 + }, + "metadata": { + "pipelineArn": "pipelineArn", + "created": 1586327944.749, + "updated": 1587023189.403 + } +} + diff --git a/scripts/quality-check.sh b/scripts/quality-check.sh new file mode 100755 index 00000000..9abbc336 --- /dev/null +++ b/scripts/quality-check.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +cd .. +echo "Start linting" +linterResult=$(npm run lint); +echo "Start audit" +auditResult=$(npm audit); +echo "Start testing" +npm run nowatch-test +echo "linter: $linterResult"; +echo "audit: $auditResult"; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" diff --git a/scripts/update-pipeline-definition.sh b/scripts/update-pipeline-definition.sh new file mode 100755 index 00000000..5d0570ba --- /dev/null +++ b/scripts/update-pipeline-definition.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# Check if jq is installed +pathToJq=$(which jq) +if [ -z $pathToJq ]; then + echo "Error: jq isn't installed"; + echo " You have to install it to make this work done" + echo " Debian and Ubuntu repositories. Install using 'sudo apt-get install jq'" + echo " MacOS: Use Homebrew to install jq 1.6 with 'brew install jq'" + echo " Windows: Use Chocolatey NuGet to install jq 1.5 with 'chocolatey install jq'" + echo " For more information please read manual instruction on https://stedolan.github.io/jq/download/" + echo + exit 1; +fi + +filePath=$1 && shift; +# Check if filename was passed +if [ ! -f $filePath ] ; then + echo "Error: Path to file is incorrect please try again with valid one" + echo + exit 1 +fi + +# Check if required properties exist +if [ $(jq '.pipeline' $filePath | jq 'has("version")') == false ]; then + echo "Error: Version property is missed in file" + exit 1 +fi +if [ $(jq '.pipeline.stages[0].actions[0].configuration' $filePath | jq 'has("Branch")') == false ]; then + echo "Error: Branch property is missed in action 'Source'" + exit 1 +fi +if [ $(jq '.pipeline.stages[0].actions[0].configuration' $filePath | jq 'has("Owner")') == false ]; then + echo "Error: Owner property is missed in action 'Source'" + exit 1 +fi +if [ $(jq '.pipeline.stages[0].actions[0].configuration' $filePath | jq 'has("PollForSourceChanges")') == false ]; then + echo "Error: PollForSourceChanges property is missed in action 'Source'" + exit 1 +fi + +# Parse named arguments +branch="main" +isPipelineAutoStart=false +while [ $# -gt 0 ]; do + if [[ $1 == "--branch" ]]; then + branch=$2 + # echo "Branch is $branch" + shift + elif [[ $1 == "--owner" ]]; then + # echo "Owner is $2" + owner=$2 + shift; + elif [[ $1 == "--poll-for-source-changes" ]]; then + # echo "Deactivate the automatic pipeline execution is $2" + isPipelineAutoStart=$2 + shift; + elif [[ $1 == "--configuration" ]]; then + # echo "Configuration is $2" + config=$2 + shift; + fi + shift +done +# echo filename is $filePath + +# Delete old metadata +updatedFileName=$(date -I'seconds') +result=$(jq 'del(.metadata)' $filePath); +# Update version version.; +increasedVersion=$(cat <<< $result | jq '.pipeline.version+1'); +result=$(cat <<< $result | jq --arg version $increasedVersion 'setpath(["pipeline","version"]; $version)'); +# Set branch +result=$(cat <<< $result | jq --arg branch $branch '.pipeline.stages[0].actions[0].configuration.Branch=$branch'); +# Set owner +if [ ! -z $owner ]; then + result=$(cat <<< $result | jq --arg owner $owner '.pipeline.stages[0].actions[0].configuration.Owner=$owner'); +fi +# Set pipeline autostart +result=$(cat <<< $result | jq --arg isPipelineAutoStart $isPipelineAutoStart '.pipeline.stages[0].actions[0].configuration.PollForSourceChanges=$isPipelineAutoStart'); +# Set EnvironmentVariables in each action TODO +if [ ! -z $config ]; then + changedQualityGate=$(cat <<< $result | jq --arg value [{\"BUILD_CONFIGURATION\":\"$config\"}] '.pipeline.stages | map(select(.name == "QualityGate").actions[0].configuration.EnvironmentVariables=$value)'); + changedBuldAndQG=$(cat <<< $changedQualityGate | jq --arg value [{\"BUILD_CONFIGURATION\":\"$config\"}] 'map(select(.name == "Build").actions[0].configuration.EnvironmentVariables=$value)') + result=$(cat <<< $result | jq --arg newStages "$changedBuldAndQG" '.pipeline.stages=$newStages'); +fi + +echo $result | jq '.pipeline.stages | fromjson' > pipeline-$updatedFileName.json +