Skip to content

Release And Deploy Azure Function #11

Release And Deploy Azure Function

Release And Deploy Azure Function #11

Workflow file for this run

name: Release And Deploy Azure Function
# Controls when the workflow will run
on:
pull_request:
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
- all
beta:
required: false
type: boolean
description: deploy beta function version on Azure
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
env:
REGISTRY: 'ghcr.io'
NAMESPACE: 'pagopa'
IMAGE: 'pagopa-gpd-reporting-batch'
# 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.get_env.outputs.environment }}
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-latest
needs: [ setup ]
outputs:
version: ${{ steps.release.outputs.version }}
steps:
- name: Make Release
id: release
uses: pagopa/github-actions-template/maven-release@v1.5.4
with:
semver: ${{ needs.setup.outputs.semver }}
github_token: ${{ secrets.BOT_TOKEN_GITHUB }}
beta: ${{ inputs.beta }}
skip_ci: false
build-and-push:
needs: [ setup, release ]
name: Build and Push Docker Image
runs-on: ubuntu-latest
if: ${{ inputs.semver != 'skip' }}
environment: ${{ inputs.environment }}
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 }}
deploy_azure_fn:
name: Deploy Azure function
environment: ${{ inputs.environment }}
needs: [ setup, release, build-and-push ]
runs-on: ubuntu-latest
if: ${{ always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v3
- name: 'Login via Azure CLI'
uses: azure/login@v1
with:
client-id: ${{ secrets.CLIENT_ID }}
tenant-id: ${{ secrets.TENANT_ID }}
subscription-id: ${{ secrets.SUBSCRIPTION_ID }}
- name: 'Run Azure Functions Container Action'
uses: Azure/functions-container-action@v1
id: fa
env:
ENV_SHORT: ${{ (contains(github.event.inputs.environment,'dev') && 'd') || (contains(github.event.inputs.environment, 'uat') && 'u') || (contains(github.event.inputs.environment, 'prod') && 'p') }}
TAG: ${{needs.release.outputs.version}}
with:
app-name: pagopa-${{ env.ENV_SHORT }}-weu-fn-gpd-batch
image: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE }}:${{ env.TAG }}
- name: Azure logout
run: |
az logout