Release And Deploy #14
Workflow file for this run
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: | |
branches: | |
- main | |
types: [ closed ] | |
# 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 | |
semver: | |
required: false | |
type: choice | |
description: Select the version | |
options: | |
- '' | |
- skip | |
- promote | |
- patch | |
- new_release | |
- breaking_change | |
# promote (skip) | |
# patch (patch) | |
# new_release (minor) | |
# breaking_change (major) | |
# if DEV -> skip, patch, new-release (minor) or breaking-change (major) | |
# if UAT -> promote or patch (patch + branch_name) | |
# if PROD -> promote or patch (patch + branch_name) | |
workflow_call: | |
inputs: | |
environment: | |
required: true | |
type: string | |
semver: | |
required: true | |
type: string | |
default: skip | |
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-latest | |
outputs: | |
semver: ${{ steps.get_semver.outputs.semver }} | |
environment: ${{ steps.output.outputs.environment }} | |
resource_group: ${{ steps.get_rg.outputs.resource_group }} | |
app_name: ${{ steps.get_appname.outputs.app_name }} | |
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 Semver | |
- run: echo "SEMVER=patch" >> $GITHUB_ENV | |
- if: ${{ github.event.pull_request.merged && ( github.event.inputs.environment == 'uat' || github.event.inputs.environment == 'prod') && ( contains(github.event.pull_request.labels.*.name, 'breaking-change') || contains(github.event.pull_request.labels.*.name, 'new-release') || contains(github.event.pull_request.labels.*.name, 'ignore-for-release') ) }} | |
run: | | |
echo "❌ UAT and PROD accept only \"patch\" or \"promote\"" | |
exit 1 | |
- if: ${{ github.event.pull_request.merged && contains(github.event.pull_request.labels.*.name, 'ignore-for-release') }} | |
run: echo "SEMVER=skip" >> $GITHUB_ENV | |
- if: ${{ (github.event.pull_request.merged && contains(github.event.pull_request.labels.*.name, 'new-release')) }} | |
run: echo "SEMVER=minor" >> $GITHUB_ENV | |
- if: ${{ (github.event.pull_request.merged && contains(github.event.pull_request.labels.*.name, 'breaking-change')) }} | |
run: echo "SEMVER=major" >> $GITHUB_ENV | |
# force semver if dev, !=main or skip release | |
- if: ${{ inputs.semver == 'new_release' }} | |
run: echo "SEMVER=minor" >> $GITHUB_ENV | |
- if: ${{ inputs.semver == 'breaking_change' }} | |
run: echo "SEMVER=major" >> $GITHUB_ENV | |
- if: ${{ github.ref_name != 'main' && inputs.semver == '' }} | |
run: echo "SEMVER=buildNumber" >> $GITHUB_ENV | |
- if: ${{ inputs.semver == 'promote' || inputs.semver == 'skip' }} | |
run: echo "SEMVER=skip" >> $GITHUB_ENV | |
- id: get_semver | |
name: Set Output | |
run: echo "semver=${{env.SEMVER}}" >> $GITHUB_OUTPUT | |
# Set Environment | |
- if: ${{ github.event.inputs.environment == null || github.event.inputs.environment == 'dev' }} | |
run: echo "ENVIRONMENT=dev" >> $GITHUB_ENV | |
- if: ${{ github.event.inputs.environment == 'uat' }} | |
run: echo "ENVIRONMENT=uat" >> $GITHUB_ENV | |
- if: ${{ github.event.inputs.environment == 'prod' }} | |
run: echo "ENVIRONMENT=prod" >> $GITHUB_ENV | |
- if: ${{ github.event.inputs.environment == 'all' }} | |
run: echo "ENVIRONMENT=all" >> $GITHUB_ENV | |
- id: output | |
name: Set Output | |
run: echo "environment=${{env.ENVIRONMENT}}" >> $GITHUB_OUTPUT | |
# Set deploy variables | |
- run: echo "ENV_SHORT=$(echo ${{env.ENVIRONMENT}} | cut -c1-1)" >> $GITHUB_ENV | |
- id: get_rg | |
name: Set Resource Group | |
run: echo "resource_group=pagopa-${{env.ENV_SHORT}}-weu-nodo-re-to-datastore-rg" >> $GITHUB_OUTPUT | |
- id: get_appname | |
name: Set App Name | |
run: echo "app_name=pagopa-${{env.ENV_SHORT}}-weu-nodo-re-ts-fn" >> $GITHUB_OUTPUT | |
release: | |
name: Create a New Release | |
runs-on: ubuntu-latest | |
needs: [setup] | |
outputs: | |
version: ${{ steps.release.outputs.version }} | |
steps: | |
- name: Make Release | |
id: release | |
uses: pagopa/github-actions-template/maven-release@main | |
with: | |
semver: ${{ needs.setup.outputs.semver }} | |
github_token: ${{ secrets.BOT_TOKEN_GITHUB }} | |
beta: false | |
build-and-push: | |
needs: [ setup, release ] | |
name: Build and Push Docker Image | |
runs-on: ubuntu-latest | |
if: ${{ needs.setup.outputs.semver != 'skip' }} | |
environment: ${{ needs.setup.outputs.environment }} | |
outputs: | |
registry_image: ${{ steps.get_image.outputs.registry_image }} | |
steps: | |
- name: Build and Push | |
id: semver | |
uses: pagopa/github-actions-template/ghcr-build-push@v1.5.4 | |
with: | |
branch: ${{ github.ref_name}} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ needs.release.outputs.version }} | |
- id: get_image | |
name: Set Registry Image | |
run: echo "registry_image=ghcr.io/pagopa/pagopa-nodo-re-to-tablestorage:${{needs.release.outputs.version}}" >> $GITHUB_OUTPUT | |
deploy_azure_fn: | |
name: Deploy Azure function | |
needs: [ setup, release, build-and-push ] | |
if: ${{ always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} | |
strategy: | |
matrix: | |
environment: [ dev, uat, prod ] | |
uses: ./.github/workflows/04_self_hosted.yml | |
with: | |
environment: ${{ matrix.environment }} | |
target: ${{ needs.setup.outputs.environment }} | |
resource_group: ${{ needs.setup.outputs.resource_group }} | |
app_name: ${{ needs.setup.outputs.app_name }} | |
registry_image: ${{ needs.build-and-push.outputs.registry_image }} | |
secrets: inherit | |
notify: | |
needs: [ setup, release, deploy_azure_fn ] | |
runs-on: ubuntu-latest | |
name: Notify | |
if: always() | |
steps: | |
- name: Report Status | |
if: always() | |
uses: ravsamhq/notify-slack-action@v2 | |
with: | |
status: ${{ needs.deploy_azure_fn.result }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
notification_title: 'New Release on ${{ needs.setup.outputs.environment }} ${{ 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 }} |