Skip to content

Deploy to Elastic Beanstalk #13

Deploy to Elastic Beanstalk

Deploy to Elastic Beanstalk #13

name: Deploy to Elastic Beanstalk
on:
workflow_dispatch:
inputs:
environment:
description: 'Select the environment'
required: true
default: 'dev'
type: choice
options:
- dev
- prod
jobs:
build:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
outputs:
app_name: ${{ steps.get_project_info.outputs.app_name }}
version_label: ${{ steps.get_project_info.outputs.version_label }}
steps:
- uses: actions/checkout@v2
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: 21
distribution: 'temurin'
- name: Extract project name and version from gradle.properties
id: get_project_info
run: |
projectName=$(grep '^projectName=' gradle.properties | cut -d'=' -f2)
version=$(grep '^version=' gradle.properties | cut -d'=' -f2)
appName="${projectName}-${version}"
timestamp=$(date +%s)
versionLabel="${version}-${timestamp}"
echo "APP_NAME=$appName" >> $GITHUB_ENV
echo "::set-output name=app_name::${appName}"
echo "::set-output name=version_label::${versionLabel}"
- name: Set executable permission for Gradlew
run: chmod +x ./gradlew
- name: Clean and Build
run: ./gradlew clean build
- name: Upload JAR
uses: actions/upload-artifact@v2
with:
name: jar-artifact
path: simple-app/build/libs/${{ env.APP_NAME }}.jar
deploy:
needs: build
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Download JAR
uses: actions/download-artifact@v2
with:
name: jar-artifact
- name: Deploy to Elastic Beanstalk
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ vars.AWS_APPLICATION_NAME }}
environment_name: ${{ vars.AWS_ENVIRONMENT_NAME }}
version_label: ${{ needs.build.outputs.version_label }}
region: ${{ secrets.AWS_REGION }}
deployment_package: ${{ needs.build.outputs.app_name }}.jar