Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does other thing #3

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions .github/workflows/ci-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
ENVIRONMENT_NAME: dev
ARTIFACT_BUCKET: trek10-sam-us-east-1
ARTIFACT_PREFIX: artifacts
CHANGE_SET_NAME: release-${GITHUB_RUN_NUMBER}-${GITHUB_RUN_ATTEMPT}
CHANGE_SET_DESCRIPTION: ${{ github.event.head_commit.message }}
HOSTED_ZONE_NAME: sandbox.trek10.com
DOMAIN_NAME: dev.serverless-starter.sandbox.trek10.com
Expand All @@ -25,7 +26,7 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/trek10inc/serverless-starter-cicd-image:latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install dependencies
run: |
make dependencies
Expand All @@ -40,9 +41,9 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/trek10inc/serverless-starter-cicd-image:latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.TARGET_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand All @@ -54,7 +55,7 @@ jobs:
run: |
make package
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ env.APPLICATION_NAME }}-${{ github.run_id }}
path: artifacts/
Expand All @@ -64,14 +65,14 @@ jobs:
container: ghcr.io/trek10inc/serverless-starter-cicd-image:latest
environment: dev
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: ${{ env.APPLICATION_NAME }}-${{ github.run_id }}
path: artifacts/
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.TARGET_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand All @@ -83,6 +84,11 @@ jobs:
name: Create Change Set
run: |
make create-change-set
export CHANGE_SET_STATUS_REASON="$(cat artifacts/${STACK_NAME}-${CHANGE_SET_NAME}.json | jq -r .StatusReason)"
if [[ "$CHANGE_SET_STATUS_REASON" == "The submitted information didn't contain changes. Submit different information to create a change set." ]];
then
echo "no_changes=true" >> $GITHUB_OUTPUT
fi;
- name: Execute Change Set
if: ${{ steps.create_change_set.outputs.no_changes != 'true' }}
run: |
Expand All @@ -92,9 +98,9 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/trek10inc/serverless-starter-cicd-image:latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.TARGET_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand Down
29 changes: 18 additions & 11 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ env:
APPLICATION_NAME: serverless-starter
ARTIFACT_BUCKET: trek10-sam-us-east-1
ARTIFACT_PREFIX: artifacts
CHANGE_SET_NAME: release-${GITHUB_RUN_NUMBER}-${GITHUB_RUN_ATTEMPT}
CHANGE_SET_DESCRIPTION: ${{ github.event.pull_request.title }}
HOSTED_ZONE_NAME: sandbox.trek10.com

Expand All @@ -36,14 +37,15 @@ jobs:
name: Testing
run: |
echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
echo "SHORT_REF: ${GITHUB_HEAD_REF/feature\/}"
echo ::set-output name=short_ref::$(echo ${GITHUB_HEAD_REF/feature\//} | cut -c -16)
export SHORT_REF=$(echo ${GITHUB_HEAD_REF/feature\//} | cut -c -16)
echo "SHORT_REF: ${SHORT_REF}"
echo "short_ref=${SHORT_REF}" >> $GITHUB_OUTPUT
test:
if: startsWith(github.head_ref, 'feature/')
runs-on: ubuntu-latest
container: ghcr.io/trek10inc/serverless-starter-cicd-image:latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install dependencies
run: |
make dependencies
Expand All @@ -58,9 +60,9 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/trek10inc/serverless-starter-cicd-image:latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.TARGET_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand All @@ -72,7 +74,7 @@ jobs:
run: |
make package
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ env.APPLICATION_NAME }}-${{ github.run_id }}
path: artifacts/
Expand All @@ -86,14 +88,14 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/trek10inc/serverless-starter-cicd-image:latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: ${{ env.APPLICATION_NAME }}-${{ github.run_id }}
path: artifacts/
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.TARGET_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand All @@ -105,6 +107,11 @@ jobs:
name: Create Change Set
run: |
make create-change-set
export CHANGE_SET_STATUS_REASON="$(cat artifacts/${STACK_NAME}-${CHANGE_SET_NAME}.json | jq -r .StatusReason)"
if [[ "$CHANGE_SET_STATUS_REASON" == "The submitted information didn't contain changes. Submit different information to create a change set." ]];
then
echo "no_changes=true" >> $GITHUB_OUTPUT
fi;
- name: Execute Change Set
if: ${{ steps.create_change_set.outputs.no_changes != 'true' }}
run: |
Expand All @@ -119,9 +126,9 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/trek10inc/serverless-starter-cicd-image:latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.TARGET_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand Down
39 changes: 25 additions & 14 deletions .github/workflows/ci-qa-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
APPLICATION_NAME: serverless-starter
ARTIFACT_BUCKET: trek10-sam-us-east-1
ARTIFACT_PREFIX: artifacts
CHANGE_SET_NAME: release-${GITHUB_RUN_NUMBER}-${GITHUB_RUN_ATTEMPT}
CHANGE_SET_DESCRIPTION: ${{ github.event.head_commit.message }}

permissions:
Expand All @@ -23,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/trek10inc/serverless-starter-cicd-image:latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install dependencies
run: |
make dependencies
Expand All @@ -38,9 +39,9 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/trek10inc/serverless-starter-cicd-image:latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.QA_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand All @@ -52,7 +53,7 @@ jobs:
run: |
make package
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ env.APPLICATION_NAME }}-${{ github.run_id }}
path: artifacts/
Expand All @@ -66,14 +67,14 @@ jobs:
HOSTED_ZONE_NAME: qa.serverless-starter.sandbox.trek10.com
DOMAIN_NAME: qa.serverless-starter.sandbox.trek10.com
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: ${{ env.APPLICATION_NAME }}-${{ github.run_id }}
path: artifacts/
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.QA_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand All @@ -85,6 +86,11 @@ jobs:
name: Create Change Set
run: |
make create-change-set
export CHANGE_SET_STATUS_REASON="$(cat artifacts/${STACK_NAME}-${CHANGE_SET_NAME}.json | jq -r .StatusReason)"
if [[ "$CHANGE_SET_STATUS_REASON" == "The submitted information didn't contain changes. Submit different information to create a change set." ]];
then
echo "no_changes=true" >> $GITHUB_OUTPUT
fi;
- name: Execute Change Set
if: ${{ steps.create_change_set.outputs.no_changes != 'true' }}
run: |
Expand All @@ -97,9 +103,9 @@ jobs:
ENVIRONMENT_NAME: qa
DOMAIN_NAME: qa.serverless-starter.sandbox.trek10.com
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.QA_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand All @@ -121,14 +127,14 @@ jobs:
outputs:
no_changes: ${{ steps.create_change_set.outputs.no_changes }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: ${{ env.APPLICATION_NAME }}-${{ github.run_id }}
path: artifacts/
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.PROD_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand All @@ -140,6 +146,11 @@ jobs:
name: Create Change Set
run: |
make create-change-set
export CHANGE_SET_STATUS_REASON="$(cat artifacts/${STACK_NAME}-${CHANGE_SET_NAME}.json | jq -r .StatusReason)"
if [[ "$CHANGE_SET_STATUS_REASON" == "The submitted information didn't contain changes. Submit different information to create a change set." ]];
then
echo "no_changes=true" >> $GITHUB_OUTPUT
fi;
deploy_prod_change_set:
needs: deploy_prod
if: needs.deploy_prod.outputs.no_changes != 'true'
Expand All @@ -149,9 +160,9 @@ jobs:
env:
ENVIRONMENT_NAME: prod
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.PROD_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/cleanup-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ jobs:
name: Testing
run: |
echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
echo "SHORT_REF: ${GITHUB_HEAD_REF/feature\/}"
echo ::set-output name=short_ref::$(echo ${GITHUB_HEAD_REF/feature\//} | cut -c -16)
export SHORT_REF=$(echo ${GITHUB_HEAD_REF/feature\//} | cut -c -16)
echo "SHORT_REF: ${SHORT_REF}"
echo "short_ref=${SHORT_REF}" >> $GITHUB_OUTPUT
cleanup-pr:
runs-on: ubuntu-latest
container: ghcr.io/trek10inc/serverless-starter-cicd-image:latest
needs: get_short_ref
env:
ENVIRONMENT_NAME: ${{ needs.get_short_ref.outputs.short_ref }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Assume role
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ env.TARGET_ACCOUNT_ID }}:role/${{ env.APPLICATION_NAME }}
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ MAKEFLAGS=--warn-undefined-variables

APPLICATION_NAME ?= serverless-starter
STACK_NAME ?= ${APPLICATION_NAME}-${ENVIRONMENT_NAME}
CHANGE_SET_NAME ?= "release-${GITHUB_RUN_NUMBER}-${GITHUB_RUN_ATTEMPT}"
CHANGE_SET_NAME ?= "release"
AWS_REGION ?= us-east-1
TEST_ARGS ?=

Expand Down Expand Up @@ -56,6 +56,7 @@ debug:
package: artifacts/template.packaged.yml

create-change-set:
mkdir -p artifacts
@echo "Deploying ${STACK_NAME} with changeset ${CHANGE_SET_NAME}"
aws cloudformation create-change-set \
--stack-name ${STACK_NAME} \
Expand All @@ -76,11 +77,11 @@ create-change-set:
while [[ "$$CHANGE_SET_STATUS" != "CREATE_COMPLETE" && "$$CHANGE_SET_STATUS" != "FAILED" ]]; do \
CHANGE_SET_STATUS=$$(aws cloudformation describe-change-set --stack-name ${STACK_NAME} --change-set-name ${CHANGE_SET_NAME} --output text --query 'Status'); \
done; \
aws cloudformation describe-change-set --stack-name ${STACK_NAME} --change-set-name ${CHANGE_SET_NAME} > artifacts/${STACK_NAME}-${CHANGE_SET_NAME}.json; \
if [[ "$$CHANGE_SET_STATUS" == "FAILED" ]]; then \
CHANGE_SET_STATUS_REASON=$$(aws cloudformation describe-change-set --stack-name ${STACK_NAME} --change-set-name ${CHANGE_SET_NAME} --output text --query 'StatusReason'); \
if [[ "$$CHANGE_SET_STATUS_REASON" == "The submitted information didn't contain changes. Submit different information to create a change set." ]]; then \
echo "ChangeSet contains no changes."; \
echo "::set-output name=no_changes::true"; \
else \
echo "Change set failed to create."; \
exit 1; \
Expand Down
1 change: 1 addition & 0 deletions src/handlers/api/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports.handler = async (event, context) => {
const res = {
items: data.Items,
message: 'hello, world!',
foo: 'bar',
};
return res;
};
1 change: 1 addition & 0 deletions src/handlers/api/data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('src/handlers/api/data.js', async () => {
expect(res).deep.equals({
items: [{ id: '123' }],
message: 'hello, world!',
foo: 'bar',
});
sinon.assert.calledOnceWithExactly(dbc.scan, {
TableName: 'dummy',
Expand Down