From 860d8c63d6ca21cecccdf7634f9e09a9c613f165 Mon Sep 17 00:00:00 2001 From: Thiago Esteves Date: Mon, 3 Jun 2024 14:53:39 -0300 Subject: [PATCH] Adding manual deployment that will tag and select the type of deployment required --- .../{release.yaml => full-deployment.yaml} | 31 ++++++------ .github/workflows/manual-deploy.yaml | 50 +++++++++++++++++++ 2 files changed, 65 insertions(+), 16 deletions(-) rename .github/workflows/{release.yaml => full-deployment.yaml} (64%) create mode 100644 .github/workflows/manual-deploy.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/full-deployment.yaml similarity index 64% rename from .github/workflows/release.yaml rename to .github/workflows/full-deployment.yaml index 2eb8abe..4ef1746 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/full-deployment.yaml @@ -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 @@ -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 @@ -46,15 +45,15 @@ 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 @@ -62,5 +61,5 @@ jobs: 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" diff --git a/.github/workflows/manual-deploy.yaml b/.github/workflows/manual-deploy.yaml new file mode 100644 index 0000000..da5b1c2 --- /dev/null +++ b/.github/workflows/manual-deploy.yaml @@ -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