Release And Deploy #84
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: Release And Deploy | |
# Controls when the workflow will run | |
on: | |
# pull_request: | |
# types: [ closed ] CURRENTLY COMMENTED IN ORDER TO AVOID AUTOMATIC DEPLOY ON DEV AFTER PR CLOSING | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
inputs: | |
environment: | |
required: true | |
type: choice | |
description: Select the Environment | |
options: | |
- dev | |
- uat | |
- prod | |
component: | |
required: true | |
type: choice | |
description: Select fdr or cron | |
default: "fdr" | |
options: | |
- fdr | |
- cron | |
- prf | |
beta: | |
required: false | |
type: boolean | |
description: deploy beta version on AKS | |
default: false | |
skip_release: | |
required: false | |
type: boolean | |
description: skip the release. Only deploy | |
default: false | |
permissions: | |
packages: write | |
contents: write | |
issues: write | |
id-token: write | |
actions: read | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
setup: | |
name: Setup | |
runs-on: ubuntu-22.04 | |
outputs: | |
semver: ${{ steps.get_semver.outputs.semver }} | |
environment: ${{ steps.get_env.outputs.environment }} | |
working_dir: ${{ steps.set_working_directory.outputs.helm_folder }} | |
steps: | |
- name: pull request rejected | |
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged != true | |
run: | | |
echo "❌ PR was closed without a merge" | |
exit 1 | |
# Set Semvar | |
- run: echo "SEMVER=patch" >> $GITHUB_ENV | |
- if: ${{ (github.event.pull_request.merged && contains(github.event.pull_request.labels.*.name, 'breaking-change')) }} | |
run: echo "SEMVER=major" >> $GITHUB_ENV | |
- if: ${{ inputs.environment == 'uat' }} | |
run: echo "SEMVER=minor" >> $GITHUB_ENV | |
- if: ${{ inputs.environment == 'prod' }} | |
run: echo "SEMVER=skip" >> $GITHUB_ENV | |
- if: ${{ github.ref_name != 'main' }} | |
run: echo "SEMVER=buildNumber" >> $GITHUB_ENV | |
- if: ${{ inputs.skip_release }} | |
run: echo "SEMVER=skip" >> $GITHUB_ENV | |
- id: get_semver | |
name: Set Output | |
run: echo "semver=${{env.SEMVER}}" >> $GITHUB_OUTPUT | |
# Set Environment | |
- run: echo "ENVIRNOMENT=${{ inputs.environment}}" >> $GITHUB_ENV | |
- if: ${{ inputs.environment == null }} | |
run: echo "ENVIRNOMENT=dev" >> $GITHUB_ENV | |
- id: get_env | |
name: Set Output | |
run: echo "environment=${{env.ENVIRNOMENT}}" >> $GITHUB_OUTPUT | |
release: | |
name: Create a New Release | |
runs-on: ubuntu-22.04 | |
needs: [setup] | |
outputs: | |
version: ${{ steps.release.outputs.version }} | |
steps: | |
- name: Make Release | |
id: release | |
uses: pagopa/github-actions-template/sbt-release@a93315d4b293eb883c4f126c2bae7dcef2f70c20 # v1.21.0 | |
with: | |
semver: ${{ needs.setup.outputs.semver }} | |
github_token: ${{ secrets.BOT_TOKEN_GITHUB }} | |
beta: ${{ inputs.beta }} | |
skip_ci: false | |
working_directory: helm-${{ inputs.component }} | |
image: | |
needs: [ setup, release ] | |
name: Build and Push Docker Image | |
runs-on: ubuntu-22.04 | |
if: ${{ inputs.semver != 'skip' }} | |
steps: | |
- name: Checkout Java | |
uses: actions/checkout@v4 | |
- name: Setup Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '11' | |
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 | |
with: | |
ref: ${{ github.ref_name }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0 | |
with: | |
images: ghcr.io/${{ github.repository }} | |
tags: | | |
latest | |
${{ needs.release.outputs.version }} | |
type=ref,event=branch | |
type=sha | |
- name: Create Dockerfile | |
env: | |
LIGHTBEND_KEY: ${{ secrets.LIGHTBEND_KEY }} | |
run: | | |
./sbt -v docker:stage | |
- name: Build and push | |
uses: docker/build-push-action@0a97817b6ade9f46837855d676c4cca3a2471fc9 # v4 | |
with: | |
context: ./fdr/target/docker/stage | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
secrets: | | |
GH_TOKEN=${{ secrets.READ_PACKAGES_TOKEN }} | |
deploy_aks: | |
name: Deploy on AKS | |
needs: [ setup, release, image ] | |
if: ${{ always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} | |
strategy: | |
matrix: | |
environment: [ dev, uat, prod ] | |
uses: ./.github/workflows/04h_deploy_with_github_runner.yml | |
with: | |
environment: ${{ matrix.environment }} | |
target: ${{ needs.setup.outputs.environment }} | |
component: ${{ inputs.component }} | |
secrets: inherit | |
notify: | |
needs: [ setup, release, deploy_aks ] | |
runs-on: ubuntu-22.04 | |
name: Notify | |
if: always() | |
steps: | |
- name: Report Status | |
if: ${{ needs.setup.outputs.environment == 'prod' }} | |
uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v2 | |
with: | |
status: ${{ needs.deploy_aks.result }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
notification_title: 'New Release on Production ${{ needs.release.outputs.version }} has {status_message}' | |
message_format: '{emoji} <{run_url}|{workflow}> {status_message} in <{repo_url}|{repo}>' | |
footer: 'Linked to <{workflow_url}| workflow file>' | |
icon_success: ':white_check_mark:' | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |