name: Deploy lambda

run-name: deploy ${{ inputs.LAMBDA_NAME }} ${{ inputs.VERSION_TO_DEPLOY }} to ${{ inputs.ENV_NAME }}

permissions:
  id-token: write
  contents: write

on:
  workflow_dispatch:
    inputs:
      ENV_NAME:
        type: choice
        description: Environment to deploy
        options:
        - ahsoka
        - anakin
        - solo
        - vader
        - boba
        - jabba
        - rey
        - r2d2
        - palpatine
        - bb8
        - c3po
        - staging
        - production
        - production-eu
        required: true
        default: palpatine
      LAMBDA_NAME:
        type: choice
        description: Lambda to deploy
        required: true
        options:
        - swg-lambda-fetch-profile
        - swg-lambda-compute-profile
      VERSION_TO_DEPLOY:
        description: Deploy this lambda version (example 1.2.3, without 'v')
        required: true
      ENV_FILE_VERSION:
        required: false
        description: The version of .env file to deploy (example v8-ENV_VARS)

env:
  ENV_NAME: ${{ inputs.ENV_NAME }}
  LAMBDA_NAME: ${{ inputs.LAMBDA_NAME }}
  VERSION_TO_DEPLOY: ${{ inputs.VERSION_TO_DEPLOY }}
  AWS_REGION: us-east-1
  AWS_SECRET_REGION: 'eu-west-2'
  NODE_VERSION: 20
  NEXUS_REPOSITORY: https://nexus.perimeter81.com
  NEXUS_SCOPE: p81-sdpv2
  NEXUS_USER: svc.nexus@perimeter81.com
  BUILD_NUMBER: ${{ github.run_number }}
  ENV_FILE_VERSION: ${{ inputs.ENV_FILE_VERSION }}
  LAMBDA_ROOT_PATH: src

jobs:
  deploy_lambda:
    runs-on: ubuntu-22.04
    environment: ${{ inputs.ENV_NAME }}
    steps:
    - name: deploy lambda
      uses: perimeter-81/actions/actions/lambdas/deploy@main
      with:
        ENV_NAME: ${{ inputs.ENV_NAME }}
        LAMBDA_NAME: ${{ env.LAMBDA_NAME }}
        VERSION_TO_DEPLOY: ${{ inputs.VERSION_TO_DEPLOY }}
        ENV_FILE_VERSION: ${{ inputs.ENV_FILE_VERSION }}
