Skip to content

Commit

Permalink
Use workflow_run for deployment (#19)
Browse files Browse the repository at this point in the history
* Use artifact instead of release for automation
  • Loading branch information
Hekku2 authored Jul 11, 2024
1 parent 7dd66f2 commit b51c2bf
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions .github/workflows/deploy-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ name: Production deployment
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to deploy'
default: 'latest'
run_id:
description: 'Workflow run ID'

release:
types: [released]
workflow_run:
workflows: [Build and Test code]
types:
- completed
branches: [main]

permissions:
id-token: write
Expand All @@ -24,16 +26,34 @@ jobs:
env:
RESOURCE_GROUP: ${{ secrets.PRODUCTION_RESOURCE_GROUP }}
APP_NAME: ${{ secrets.PRODUCTION_APP_NAME }}
TAG: ${{ github.event_name != 'release' && 'latest' || format('tags/{0}', github.event.release.tag_name) }}
RUN_ID: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.id || inputs.run_id }}

steps:

- name: Fetch release asset
uses: dsaltares/fetch-gh-release-asset@master
- uses: actions/checkout@v4

- name: 'Download artifact'
uses: actions/github-script@v7
with:
repo: ${{ github.repository }}
version: ${{ env.TAG }}
file: 'publish.zip'
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
Expand All @@ -42,12 +62,10 @@ jobs:
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true

- uses: actions/checkout@v4

- name: Deploy binaries
uses: azure/powershell@v2
with:
azPSVersion: "latest"
inlineScript: |
./scripts/Deploy-FunctionApp.ps1 -ResourceGroup $env:RESOURCE_GROUP -AppName $env:APP_NAME -ZipFile publish.zip
./scripts/Deploy-FunctionApp.ps1 -ResourceGroup $env:RESOURCE_GROUP -AppName $env:APP_NAME -ZipFile "$($env:GITHUB_WORKSPACE)/publish.zip"

0 comments on commit b51c2bf

Please sign in to comment.