Backend Deploy #54
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: Backend Deploy | |
on: | |
workflow_call: | |
inputs: | |
application_name: | |
required: true | |
type: string | |
environment_name: | |
required: true | |
type: string | |
version: | |
required: true | |
type: string | |
secrets: | |
AWS_ACCESS_KEY_ID: | |
required: true | |
AWS_SECRET_ACCESS_KEY: | |
required: true | |
AWS_REGION: | |
required: true | |
token: | |
required: true | |
workflow_dispatch: | |
inputs: | |
application_name: | |
description: Name of the Elastic Beanstalk application to deploy | |
required: true | |
type: string | |
environment_name: | |
description: Name of the Elastic Beanstalk environment to deploy to | |
required: true | |
type: string | |
version: | |
description: Version to deploy. If the version exists as a release, it will use that artifact | |
required: true | |
type: string | |
jobs: | |
backend-deploy: | |
name: Backend Deployment | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set Input Variables | |
id: set-vars | |
run: | | |
echo "::set-output name=version::${{ inputs.version || github.event.inputs.version }}" | |
echo "::set-output name=application_name::${{ inputs.application_name || github.event.inputs.application_name }}" | |
echo "::set-output name=environment_name::${{ inputs.environment_name || github.event.inputs.environment_name }}" | |
- name: Check if tag exists | |
id: check-tag | |
uses: mukunku/[email protected] | |
with: | |
tag: ${{ steps.set-vars.outputs.version }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.token || secrets.GITHUB_TOKEN }} | |
# If the tag already exists, just download the artifact from that release | |
- name: Download Release Artifact | |
if: steps.check-tag.outputs.exists == 'true' | |
uses: robinraju/[email protected] | |
with: | |
repository: CarnegieLearningWeb/UpGrade | |
tag: ${{ steps.set-vars.outputs.version }} | |
fileName: upgrade-backend-${{ steps.set-vars.outputs.version }}.zip | |
# Otherwise, build the artifact | |
- name: Git Checkout | |
if: steps.check-tag.outputs.exists == 'false' | |
uses: actions/checkout@v3 | |
- name: Load Environment Variables | |
if: steps.check-tag.outputs.exists == 'false' | |
uses: tw3lveparsecs/[email protected] | |
- name: Setup NodeJS ${{ env.NODE_VERSION }} | |
if: steps.check-tag.outputs.exists == 'false' | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Build Backend | |
if: steps.check-tag.outputs.exists == 'false' | |
working-directory: backend | |
run: | | |
cp -R ../types packages/Upgrade | |
npm ci | |
zip -qq -r upgrade-backend-${{ steps.set-vars.outputs.version }}.zip node_modules packages/Upgrade Dockerfile Dockerrun.aws.json package.json tsconfig.json | |
mv upgrade-backend-${{ steps.set-vars.outputs.version }}.zip ../ | |
- uses: einaregilsson/beanstalk-deploy@v13 | |
with: | |
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
application_name: ${{ steps.set-vars.outputs.application_name }} | |
environment_name: ${{ steps.set-vars.outputs.environment_name }} | |
version_label: ${{ steps.set-vars.outputs.version }} | |
region: ${{ secrets.AWS_REGION }} | |
deployment_package: upgrade-backend-${{ steps.set-vars.outputs.version }}.zip | |
wait_for_deployment: false | |
use_existing_version_if_available: true |