Skip to content

Commit

Permalink
Merge pull request #114 from Associated-Engineering/update-ci-scripts
Browse files Browse the repository at this point in the history
Update CI scripts
  • Loading branch information
andreram authored Apr 13, 2021
2 parents 5ded2e6 + 2b2a294 commit 8da31cb
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 13 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/deploy-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Deploy
on:
push:
branches: [main]

env:
REGION: us-west-2

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Sets up AWS profile.
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.CI_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CI_SECRET_ACCESS_KEY }}
aws-region: ${{ env.REGION }}
# Install CDK
- name: Install CDK
run: sudo npm install -g [email protected]
# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
# Build and deploy the backend
- name: Build backend
run: |
cd $GITHUB_WORKSPACE
dotnet tool install -g Amazon.Lambda.Tools
chmod 700 deployBackend.sh
./deployBackend.sh -c -e test || exit 1
# Install frontend packages
- name: Install packages
run: |
sudo npm install -g yarn
cd Frontend
yarn install
# Run E2E tests
- name: Cypress tests
uses: cypress-io/github-action@v2
with:
working-directory: ./Frontend
browser: chrome
headless: true
start: yarn start || exit 1
wait-on: 'http://localhost:3000'
deploy:
name: Deploy
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Sets up AWS profile.
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.PROD_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PROD_SECRET_ACCESS_KEY }}
aws-region: ${{ env.REGION }}
# Install CDK
- name: Install CDK
run: sudo npm install -g [email protected]
# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
# Build and deploy to production
- name: Build and deploy
run: |
cd $GITHUB_WORKSPACE
dotnet tool install -g Amazon.Lambda.Tools
chmod 700 deploy.sh
./deploy.sh -e prod || exit 1
5 changes: 3 additions & 2 deletions .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ jobs:
- name: Build backend
run: |
cd $GITHUB_WORKSPACE
chmod 700 deployCI.sh
./deployCI.sh
dotnet tool install -g Amazon.Lambda.Tools
chmod 700 deployBackend.sh
./deployBackend.sh -c -e test || exit 1
# Install frontend packages
- name: Install packages
run: |
Expand Down
File renamed without changes.
50 changes: 48 additions & 2 deletions deployBackend.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
while getopts "p:e:c" opt; do
case $opt in
p)
userProfile=$OPTARG
echo "User profile set to: $userProfile"
;;
e)
export DEPLOY_ENVIRONMENT=$OPTARG
echo "Deploy environment: $DEPLOY_ENVIRONMENT"
copy /b src/Project/ProjectStack.cs +,,
;;
c)
clean=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done




# Run the commented command manually if you haven't before
# dotnet tool install -g Amazon.Lambda.Tools
cd Handler/src/Handler
Expand All @@ -6,5 +34,23 @@ dotnet build -c Release
dotnet lambda package
cd ../../..
echo "***Deploying backend***"
cdk deploy ProjectStack --outputs-file Frontend/src/endpoint.json --require-approval never
echo "Done"
if [ $userProfile ]
then
cdk deploy ProjectStack --outputs-file Frontend/src/endpoint.json --require-approval never --profile $userProfile
if [ $clean ]
then
dbinitName=`aws lambda list-functions --profile $userProfile | awk '/ProjectStack-databaseInit/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'`
dropTablesName=`aws lambda list-functions --profile $userProfile | awk '/ProjectStack-databaseDropAll/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'`
aws lambda invoke --function-name $dropTablesName --profile $userProfile response.json
aws lambda invoke --function-name $dbinitName --profile $userProfile response.json
fi
else
cdk deploy ProjectStack --outputs-file Frontend/src/endpoint.json --require-approval never
if [ $clean ]
then
dbinitName=`aws lambda list-functions | awk '/ProjectStack-databaseInit/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'`
dropTablesName=`aws lambda list-functions | awk '/ProjectStack-databaseDropAll/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'`
aws lambda invoke --function-name $dropTablesName sresponse.json
aws lambda invoke --function-name $dbinitName response.json
fi
fi
9 changes: 0 additions & 9 deletions deployCI.sh

This file was deleted.

0 comments on commit 8da31cb

Please sign in to comment.