Production deployment #22
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
# Workflow for deploying new releases to the production environment | |
name: Production deployment | |
on: | |
workflow_dispatch: | |
inputs: | |
run_id: | |
description: 'Workflow run ID' | |
workflow_run: | |
workflows: [Build and Test code] | |
types: | |
- completed | |
branches: [main] | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
release: | |
name: Deploy release | |
runs-on: ubuntu-latest | |
environment: production | |
env: | |
RESOURCE_GROUP: ${{ secrets.PRODUCTION_RESOURCE_GROUP }} | |
APP_NAME: ${{ secrets.PRODUCTION_APP_NAME }} | |
RUN_ID: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.id || inputs.run_id }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: 'Download artifact' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: process.env.RUN_ID | |
}); | |
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "DiscordImageSender" | |
})[0]; | |
let download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
let fs = require('fs'); | |
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/DiscordImageSender.zip`, Buffer.from(download.data)); | |
- name: 'Unzip artifact' | |
run: unzip DiscordImageSender.zip | |
- name: Login via Az module | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
enable-AzPSSession: true | |
- name: Deploy binaries | |
uses: azure/powershell@v2 | |
with: | |
azPSVersion: "latest" | |
inlineScript: | | |
./scripts/Deploy-FunctionApp.ps1 -ResourceGroup $env:RESOURCE_GROUP -AppName $env:APP_NAME -ZipFile "$($env:GITHUB_WORKSPACE)/publish.zip" |