Release And Deploy #39
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: | |
merge_group: | |
branches: [ main ] | |
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 | |
beta: | |
required: false | |
type: boolean | |
description: deploy beta version on AKS | |
default: false | |
version: | |
required: false | |
type: choice | |
description: Select the version | |
options: | |
- patch | |
- 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, 'skip')) }} | |
run: echo "SEMVER=skip" >> $GITHUB_ENV | |
- if: ${{ (github.event.pull_request.merged && contains(github.event.pull_request.labels.*.name, 'patch')) }} | |
run: echo "SEMVER=patch" >> $GITHUB_ENV | |
- if: ${{ (github.event.pull_request.merged && contains(github.event.pull_request.labels.*.name, 'minor')) }} | |
run: echo "SEMVER=minor" >> $GITHUB_ENV | |
- if: ${{ (github.event.pull_request.merged && contains(github.event.pull_request.labels.*.name, 'major')) }} | |
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 }} | |
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 ] | |
if: ${{ needs.setup.outputs.semver != 'skip' }} | |
outputs: | |
version: ${{ steps.release.outputs.version }} | |
steps: | |
- name: Make Release | |
id: release | |
uses: pagopa/github-actions-template/maven-release@4a4c25ce28feeec9e619b3132b5327f52023d441 # v1.14.2 | |
with: | |
semver: ${{ needs.setup.outputs.semver }} | |
github_token: ${{ secrets.BOT_TOKEN_GITHUB }} | |
beta: ${{ inputs.beta }} | |
skip_ci: true | |
prerelease: ${{ github.ref_name != 'main' }} | |
only_tag: false | |
image: | |
needs: [ setup, release ] | |
name: Build and Push Docker Image | |
runs-on: ubuntu-latest | |
if: ${{ needs.setup.outputs.semver != 'skip' }} | |
steps: | |
- name: Build and Push | |
id: semver | |
uses: pagopa/github-actions-template/ghcr-build-push@d91a1fd0b913c9830589be5d86cdb71c90813fae # v1.5.4 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ needs.release.outputs.version }} | |
deploy_aks: | |
name: Deploy on AKS | |
needs: [ setup, release, image ] | |
if: ${{ always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} | |
uses: ./.github/workflows/deploy_with_github_runner.yml | |
with: | |
environment: ${{ needs.setup.outputs.environment }} | |
secrets: inherit | |
notify: | |
needs: [ setup, release, deploy_aks ] | |
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_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 }} |