Skip to content

Commit

Permalink
Adding manual deployment that will tag and select the type of deployment
Browse files Browse the repository at this point in the history
required
  • Loading branch information
thiagoesteves committed Jun 3, 2024
1 parent 4f99881 commit 860d8c6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name: Publish a release file/version to AWS
name: Deploy a full deployment package/version to AWS

on:
push:
branches:
- main
workflow_call:
inputs:
tag:
required: true
type: string

env:
MIX_ENV: prod

jobs:
build:
name: Building Calori release and publishing it at AWS
name: Building a release and publishing it at AWS
runs-on: ubuntu-20.04
permissions:
contents: write
Expand All @@ -27,16 +29,13 @@ jobs:
GITHUB_SHORT_SHA=$(git rev-parse --short ${{ github.sha }})
echo "GITHUB_SHORT_SHA=${GITHUB_SHORT_SHA}" >> $GITHUB_ENV
- name: Capture and update project mix version
- name: Update project mix version
run: |
MIX_VERSION=`grep "version:" mix.exs | awk -F'"' '{print $2}'`
CALORI_VERSION=${MIX_VERSION}-${GITHUB_SHORT_SHA}
echo "CALORI_VERSION=${CALORI_VERSION}" >> $GITHUB_ENV
sed -i "s/.*version:.*/ version: \"${CALORI_VERSION}\",/" mix.exs
sed -i "s/.*version:.*/ version: \"${{ inputs.tag }}\",/" mix.exs
- name: Create Release file version
run: |
echo "{\"version\":\"${CALORI_VERSION}\",\"hash\":\"${GITHUB_SHA}\"}" | jq > current.json
echo "{\"version\":\"${{ inputs.tag }}\",\"hash\":\"${GITHUB_SHA}\"}" | jq > current.json
- name: Install Elixir dependencies
run: mix do deps.get, compile
Expand All @@ -46,21 +45,21 @@ jobs:

- name: Generate a Release
run: mix release

- name: Copy a release file to the s3 distribution folder
uses: prewk/s3-cp-action@v2
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_region: "sa-east-1"
source: '_build/prod/*.tar.gz'
dest: 's3://calori-${{ secrets.CLOUD_ENV_NAME }}-distribution/dist/calori/calori-${CALORI_VERSION}.tar.gz'
source: "_build/prod/*.tar.gz"
dest: "s3://calori-${{ secrets.CLOUD_ENV_NAME }}-distribution/dist/calori/calori-${{ inputs.tag }}.tar.gz"

- name: Copy a version file to the s3 version folder
uses: prewk/s3-cp-action@v2
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_region: "sa-east-1"
source: 'current.json'
dest: 's3://calori-${{ secrets.CLOUD_ENV_NAME }}-distribution/versions/calori/${{ secrets.CLOUD_ENV_NAME }}/current.json'
source: "current.json"
dest: "s3://calori-${{ secrets.CLOUD_ENV_NAME }}-distribution/versions/calori/${{ secrets.CLOUD_ENV_NAME }}/current.json"
50 changes: 50 additions & 0 deletions .github/workflows/manual-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Manual Deployment with tags

on:
workflow_dispatch:
inputs:
deployment:
description: "Type of deployment"
required: true
default: "full"
type: choice
options:
- "full-deployment"
- "hot-upgrade"

jobs:
create-tag:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.save-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Capture GITHUB_SHORT_SHA
run: |
GITHUB_SHORT_SHA=$(git rev-parse --short ${{ github.sha }})
echo "GITHUB_SHORT_SHA=${GITHUB_SHORT_SHA}" >> $GITHUB_ENV
- name: Capture and update project mix version
id: save-tag
run: |
MIX_VERSION=`grep "version:" mix.exs | awk -F'"' '{print $2}'`
PROJ_TAG=${MIX_VERSION}-${GITHUB_SHORT_SHA}
echo "PROJ_TAG=${PROJ_TAG}" >> $GITHUB_ENV
echo "tag=$PROJ_TAG" >> "$GITHUB_OUTPUT"
echo "Creating the tag: $PROJ_TAG"
- uses: rickstaa/action-create-tag@v1
id: "tag_create"
with:
tag: ${{ env.PROJ_TAG }}
message: "Created ${{ inputs.deployment }} tag ${{ env.PROJ_TAG }}"

deploy:
needs: create-tag
uses: ./.github/workflows/full-deployment.yaml
with:
tag: ${{ needs.create-tag.outputs.tag }}
secrets: inherit

0 comments on commit 860d8c6

Please sign in to comment.