Skip to content

fix kpi configuration inputs #100

fix kpi configuration inputs

fix kpi configuration inputs #100

name: Release And Deploy
# 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
default: dev
version:
required: false
type: choice
description: Select the version
options:
- ''
- skip_or_promote
- new_release
- breaking_change
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.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
# force semver if dev, !=main or skip release
- if: ${{ inputs.version == 'new_release' }}
run: echo "SEMVER=minor" >> $GITHUB_ENV
- if: ${{ inputs.version == 'breaking_change' }}
run: echo "SEMVER=major" >> $GITHUB_ENV
- if: ${{ github.ref_name != 'main' }}
run: echo "SEMVER=buildNumber" >> $GITHUB_ENV
- if: ${{ inputs.version == 'skip_or_promote' }}
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 || inputs.environment == '' }}
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/node-release@241d9bfcaa2a623cb78a2d993716d761af158c0c # v1.6.6
with:
semver: ${{ needs.setup.outputs.semver }}
github_token: ${{ secrets.BOT_TOKEN_GITHUB }}
skip_ci: false
deploy:
runs-on: ubuntu-latest
needs: [setup, release]
name: Deploy ${{ needs.setup.outputs.environment }}
environment: ${{ needs.setup.outputs.environment }}
steps:
- name: Checkout
id: checkout
# from https://github.com/actions/checkout/commits/main
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707
with:
persist-credentials: false
- name: Set Node.js 22
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3
with:
node-version: 22.13.1
- name: Build Webapp
run: |
echo ">>>>>>>>>>> Building for ${{ needs.setup.outputs.environment}} environment"
if [[ ${{ needs.setup.outputs.environment}} == "prod" ]]; then
export SERVER_API_URL='https://api.platform.pagopa.it/smo/cruscotto/v1/'
else
export SERVER_API_URL='https://api.${{ needs.setup.outputs.environment }}.platform.pagopa.it/smo/cruscotto/v1/'
fi
echo ">>>>>>>>>>> SERVER_API_URL=$SERVER_API_URL"
npm install
npm run webapp:prod
- name: Login
id: login
# from https://github.com/Azure/login/commits/master
uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2
with:
client-id: ${{ secrets.CLIENT_ID }}
tenant-id: ${{ secrets.TENANT_ID }}
subscription-id: ${{ secrets.SUBSCRIPTION_ID }}
- name: Deploy
uses: azure/CLI@4db43908b9df2e7ac93c8275a8f9a448c59338dd # v1
with:
azcliversion: latest
inlineScript: |
az storage blob sync --container '$web' --account-name ${{ vars.STORAGE_ACCOUNT }} -s "./target/classes/static" --connection-string '${{ secrets.BLOB_CONNECTION_STRING }}'
- name: date
run: |
date=$(date --date="15 min ago" '+%Y-%m-%dT%H:%MZ')
echo "DATE=$date" >> $GITHUB_ENV
- name: Remove Old Files
uses: azure/CLI@4db43908b9df2e7ac93c8275a8f9a448c59338dd # v1
with:
azcliversion: latest
inlineScript: |
az storage blob delete-batch -s '$web' --account-name ${{ vars.STORAGE_ACCOUNT }} --connection-string '${{ secrets.BLOB_CONNECTION_STRING }}' --if-unmodified-since ${{env.DATE}}
- name: Purge
uses: azure/CLI@4db43908b9df2e7ac93c8275a8f9a448c59338dd # v1
with:
azcliversion: latest
inlineScript: |
az cdn endpoint purge -g ${{ vars.CDN_RESOURCE_GROUP }} -n ${{ vars.CDN_ENDPOINT }} --profile-name ${{ vars.CDN_PROFILE }} --content-paths "/*"
# notify:
# needs: [ setup, release, deploy ]
# runs-on: ubuntu-latest
# 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.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 }}