Skip to content

Commit

Permalink
Create UploadAndNotify.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
tshanep authored Feb 7, 2024
1 parent ac1e7fc commit 38dcf69
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/UploadAndNotify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Upload to Azure Blob Storage, Generate SAS Token, and Notify Teams

on:
workflow_dispatch:
inputs:
message:
description: 'Message to include in Teams notification'
required: true
default: 'File uploaded to Azure Blob Storage successfully!'

jobs:
deploy:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2

- name: Create a text file
run: echo "Hello, World!" > simplefile.txt

- name: Log in to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Upload file to Blob Storage
run: |
az storage blob upload --account-name poweraccelerators --container-name accelerators --name simplefile.txt --file simplefile.txt --auth-mode login
- name: Generate SAS Token
run: |
$expiry = (Get-Date).AddDays(365).ToString("yyyy-MM-ddTHH:mm:ssZ")
$sas = az storage blob generate-sas --account-name poweraccelerators --container-name accelerators --name simplefile.txt --permissions r --expiry $expiry --auth-mode login --output tsv
echo "SAS_URL=https://poweraccelerators.blob.core.windows.net/accelerators/simplefile.txt?$sas" >> $GITHUB_ENV
shell: pwsh

- name: Post Adaptive Card to Microsoft Teams
run: |
$body = @{
type = "message"
attachments = @(
@{
contentType = "application/vnd.microsoft.card.adaptive"
contentUrl = $null
content = @{
'$schema' = "http://adaptivecards.io/schemas/adaptive-card.json"
type = "AdaptiveCard"
version = "1.2"
body = @(
@{
type = "TextBlock"
text = "${{ env.SAS_URL }}"
}
)
actions = @(
@{
type = "Action.OpenUrl"
title = "Download Azure Blob File"
url = "${{ env.SAS_URL }}"
}
)
}
}
)
} | ConvertTo-Json -Depth 10
curl -H "Content-Type: application/json" -d "$body" ${{ secrets.TEAMS_WEBHOOK_URL }}
shell: pwsh

0 comments on commit 38dcf69

Please sign in to comment.