diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 00000000..a2954544 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,64 @@ +name: CI/CD โš™๏ธ + +on: + push: + release: + types: + - published + workflow_dispatch: + inputs: + environment: + description: 'Environment to run deploy' + type: environment + required: true + force: + description: 'Deploy even if tests fail' + type: boolean + required: false + default: false + +jobs: + test: + name: Test ๐Ÿงช + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{github.event.pull_request.head.sha || github.sha}} + + - name: Docker API Build + run: docker build -t test -f Dockerfile-test . + + - name: Docker API Test Run + run: docker run -e CHECK_CODEGEN=true test + + deploy-to-dev: + name: Deploy to Development ๐Ÿšง + needs: test + if: github.event_name == 'push' && github.ref_name == 'main' + concurrency: dev + uses: './.github/workflows/deploy.yml' + with: + environment: dev + secrets: inherit + + deploy-to-prod: + name: Deploy to Production ๐ŸŒŸ + needs: test + if: github.event_name == 'release' + concurrency: prod + uses: './.github/workflows/deploy.yml' + with: + environment: prod + secrets: inherit + + manual-deployment: + name: Manual Deployment โ€ผ๏ธ + needs: test + if: github.event_name == 'workflow_dispatch' && (success() || inputs.force == true) + concurrency: ${{ inputs.environment }} + uses: './.github/workflows/deploy.yml' + with: + environment: ${{ inputs.environment }} + secrets: inherit diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..3318b970 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,38 @@ +# A reusable workflow that deploys the contents of a repository to a target environment. +# https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow + +on: + workflow_call: + inputs: + environment: + type: string + required: true + +jobs: + deploy: + name: ๐Ÿš€ + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20.x + cache: 'npm' + + - name: Install dependencies + run: npm install --no-save + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ vars.DEPLOYMENT_ROLE_ARN }} + role-session-name: ${{ github.actor }} + aws-region: ${{ vars.AWS_REGION || 'us-west-2' }} + + - name: Deploy + run: npm run deploy-${{ inputs.environment }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index c8e3c608..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Test - -on: - push: - branches: - - main - pull_request: - types: - - opened - - synchronize - - reopened - - ready_for_review - -jobs: - test: - runs-on: ubuntu-latest - if: github.event.pull_request.draft == false - timeout-minutes: 30 - steps: - - uses: actions/checkout@v3 - with: - ref: ${{github.event.pull_request.head.sha || github.sha}} - - - name: Docker API Build - run: docker build -t test -f Dockerfile-test . - - - name: Docker API Test Run - run: docker run -e CHECK_CODEGEN=true test