Skip to content

Commit

Permalink
chore: update workflow triggers and order (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleyjtaylor authored Mar 10, 2024
1 parent aeb6b4c commit 99c2afd
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 30 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,3 @@ jobs:
NODE_VERSION: ${{ env.NODE_VERSION }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

# trigger-deploy:
# if: github.ref == 'refs/heads/main'
# runs-on: ubuntu-latest
# needs: [audit, lint, test, build, sonarcloud]
# steps:
# - uses: actions/checkout@v4
# - run: gh workflow run deploy.yml -f environment=dev
# env:
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: deploy

env:
NODE_VERSION: 20

permissions: write-all

concurrency: ${{ github.workflow }}-${{ github.ref }}

on:
workflow_run:
workflows: [ci]
types:
- completed

jobs:
infrastructure:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- run: gh workflow run infrastructure.yml -f environment=dev
82 changes: 62 additions & 20 deletions .github/workflows/infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,31 @@ permissions:
contents: read

on:
push:
branches:
- main
paths:
- '.github/workflows/infrastructure.yml'
- 'infrastructure/**'
- '!**/*.md'
workflow_call:
inputs:
environment:
description: 'Environment to deploy'
type: string
required: true
default: 'dev'

jobs:
infrastructure:
changes:
runs-on: ubuntu-latest
outputs:
files: ${{ steps.filter.outputs.changes }}
steps:
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
baseimage:
- 'infrastructure/src/images/Dockerfile.base'
infrastructure:
- '.github/workflows/infrastructure.yml'
- 'infrastructure/**'
tools:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -27,17 +42,10 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install
run: npm ci

- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
images:
- '**/*/Dockerfile.base'
- name: Build
working-directory: ./infrastructure
run: |
Expand All @@ -56,7 +64,7 @@ jobs:
uses: aws-actions/amazon-ecr-login@v2

- name: Deploy base image
if: ${{ steps.filter.outputs.images == 'true' }}
if: ${{ needs.changes.outputs.files.baseimage == 'true' }}
working-directory: ./infrastructure
run: |
aws ecr describe-repositories --repository-names $REPOSITORY || aws ecr create-repository --repository-name $REPOSITORY
Expand All @@ -67,10 +75,44 @@ jobs:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.BASE_IMAGE_NAME }}

- name: Synth
- name: Cdk Synth
working-directory: ./infrastructure
run: npx cdk synth --require-approval never

- name: Deploy
- name: Cdk Deploy
working-directory: ./infrastructure
run: npx cdk deploy --require-approval never

dev:
if: ${{ needs.changes.outputs.files.infrastructure == 'true' }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install
run: npm ci

- name: Build
working-directory: ./infrastructure
run: npx cdk deploy --require-approval never
run: |
npm run lint
npm run build
- name: Assume OIDC Role
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/oidc-provider-role
role-session-name: gh-dev-deploy-session
aws-region: ${{ env.AWS_REGION }}

- name: Synth
run: npx cdk synth Dev* --require-approval never

- name: Deploy
run: npx cdk deploy Dev* --require-approval never

0 comments on commit 99c2afd

Please sign in to comment.