chore: add test trigger; #5
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: deploy | |
on: | |
push: | |
paths-ignore: | |
- 'Makefile' | |
- '**.md' | |
- 'docs/**' | |
branches: | |
- master | |
- chore/adhere-to-awesome-go-guideline | |
jobs: | |
preparation: | |
name: Prepare Deployment | |
runs-on: ubuntu-latest | |
outputs: | |
deploy-game: ${{ (steps.changes.outputs.lambda == 'true') || (steps.changes.outputs.all == 'true') }} | |
steps: | |
- name: Checkout Current Commit | |
uses: actions/checkout@v2 | |
- name: Run Automated Tests | |
run: make test | |
- name: Determine Changes | |
uses: dorny/paths-filter@v2 | |
id: changes | |
with: | |
base: ${{ github.ref }} | |
filters: | | |
all: | |
- "internal/**" | |
- ".github/workflows/deploy-dev.yml" | |
- ".github/workflows/run-tests.yml" | |
- "go.mod" | |
- "go.sum" | |
lambda: | |
- "build/package/lambda/**" | |
- "cmd/lambda/**" | |
- "internal/driven/storage/dynamodb/**" | |
- "deploy/aws/lambda/infras.yml" | |
- "deploy/aws/lambda/service.yml" | |
- name: Notify To Slack If Failed | |
uses: lazy-actions/[email protected] | |
if: failure() | |
with: | |
type: ${{ job.status }} | |
job_name: "*[hex-monscape]* ${{ github.job }}" | |
mention: "here" | |
mention_if: "failure" | |
channel: "#solutions-team-ci-cd" | |
icon_emoji: ":haraaj:" | |
username: "ci/cd-reporter" | |
url: ${{ secrets.SOLUTIONS_TEAM_SLACK_WEBHOOK }} | |
commit: true | |
token: ${{ secrets.GITHUB_TOKEN }} | |
deploy-game: | |
name: Deploy Game | |
needs: preparation | |
runs-on: ubuntu-latest | |
if: ${{ needs.preparation.outputs.deploy-game == 'true' }} | |
env: | |
AWS_REGION: eu-west-1 | |
INFRA_STACK_NAME_DEV: hex-monscape-infras | |
steps: | |
- name: Checkout Current Commit | |
uses: actions/checkout@v2 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.OSS_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.OSS_AWS_SECRET_ACCESS_KEY }} | |
role-to-assume: ${{ secrets.OSS_AWS_DEPLOY_ROLE_ARN }} | |
role-duration-seconds: 3600 | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Deploy Infrastructure | |
run: | | |
aws cloudformation deploy \ | |
--region ${{ env.AWS_REGION }} \ | |
--template-file ./deploy/aws/lambda/infras.yml \ | |
--stack-name ${{ env.INFRA_STACK_NAME_DEV }} \ | |
--capabilities CAPABILITY_NAMED_IAM | |
- name: Deploy Game Service | |
run: | | |
# prepare necessary parameters | |
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) | |
ECR_REPO_NAME_DEV=$(aws cloudformation describe-stack-resource \ | |
--stack-name ${{ env.INFRA_STACK_NAME_DEV }} \ | |
--logical-resource-id ECRRepo \ | |
--query "StackResourceDetail.PhysicalResourceId" --output text) | |
REMOTE_REPO_DEV=${AWS_ACCOUNT_ID}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${ECR_REPO_NAME_DEV} | |
IMAGE_URI=${REMOTE_REPO_DEV}:${GITHUB_SHA} | |
# build docker image | |
docker build \ | |
--build-arg VITE_API_STAGE_PATH=/Dev \ | |
--build-arg FRONTEND_MODE=lambda \ | |
-t hex-monscape-lambda:latest -f ./build/package/lambda/Dockerfile . | |
docker tag hex-monscape-lambda:latest ${IMAGE_URI} | |
# push docker image to ECR | |
aws ecr get-login-password | docker login --username AWS --password-stdin ${REMOTE_REPO_DEV} | |
docker push ${IMAGE_URI} | |
# deploy service | |
sam deploy \ | |
--region ${AWS_REGION} \ | |
--stack-name hex-monscape \ | |
--image-repository ${REMOTE_REPO_DEV} \ | |
--template-file ./deploy/aws/lambda/service.yml \ | |
--capabilities CAPABILITY_NAMED_IAM \ | |
--parameter-overrides \ | |
InfraStackName=${{ env.INFRA_STACK_NAME_DEV }} \ | |
ImageUri=${IMAGE_URI} | |
- name: Notify To Slack | |
uses: lazy-actions/[email protected] | |
if: always() | |
with: | |
type: ${{ job.status }} | |
job_name: "*[hex-monscape]* ${{ github.job }}" | |
mention: "here" | |
mention_if: "failure" | |
channel: "#solutions-team-ci-cd" | |
icon_emoji: ":haraaj:" | |
username: "ci/cd-reporter" | |
url: ${{ secrets.SOLUTIONS_TEAM_SLACK_WEBHOOK }} | |
commit: true | |
token: ${{ secrets.GITHUB_TOKEN }} |