-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
51 lines (49 loc) · 1.96 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: 'PSWattTime for Azure regions'
description: 'Get Azure region with optimal carbon emissions from a given set'
branding:
icon: 'loader'
color: 'green'
inputs:
azure_credential:
description: Azure credential secret for azure/login@v1 action
required: true
regions:
description: Comma seperated list of Azure regions to check for current emissions
required: false
default: '"westeurope","northeurope"'
watttime_username:
description: Username for registered watttime.org account
required: true
watttime_password:
description: Password for registered watttime.org account
required: true
outputs:
region:
description: Azure region with the best emissions
value: ${{ steps.invokewatttime.outputs.region}}
percent:
description: Percentage of energy with carbon emissions
value: ${{ steps.invokewatttime.outputs.percent }}
runs:
using: composite
steps:
- id: azurelogin
uses: azure/login@v1
with:
creds: ${{ inputs.azure_credential }}
enable-AzPSSession: true
- id: invokewatttime
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az.Resources
Import-Module Az.Resources
Import-Module ${{ github.action_path }}/src/PSWattTime
$token = Get-WattTimeAuthToken -Username ${{ inputs.watttime_username }} -Password ${{ inputs.watttime_password }}
$result = Get-AzureRegionWithLowestWattTime -Regions ${{ inputs.regions }} -AuthToken $token
"region=$($result.region)" >> $env:GITHUB_OUTPUT
"percent=$($result.percent)" >> $env:GITHUB_OUTPUT
Write-Output "### PSWattTime Azure Region selection" >> $env:GITHUB_STEP_SUMMARY
Write-Output "" >> $env:GITHUB_STEP_SUMMARY
Write-Output "- Azure region with lowest emissions: **$($result.region)**" >> $env:GITHUB_STEP_SUMMARY
Write-Output "- Emissions percentage: **$($result.percent)**" >> $env:GITHUB_STEP_SUMMARY