Skip to content

Commit

Permalink
Cleanup self-hosted runners: switch Azure login logic to our own
Browse files Browse the repository at this point in the history
We now have our own simple workflow to log into Azure, using "az login". As we're moving way from things like the Azure CLI, let's also start using our own login script instead.

Signed-off-by: Dennis Ameling <[email protected]>
  • Loading branch information
dennisameling committed Oct 3, 2024
1 parent 582bde8 commit ab3fad1
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions .github/workflows/cleanup-self-hosted-runners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Process Azure credentials
uses: actions/github-script@v7
env:
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure Login
uses: ./.github/workflows/azure-login
with:
script: |
if (!process.env.AZURE_CREDENTIALS) {
core.setFailed('The AZURE_CREDENTIALS secret is required.')
process.exit(1)
}
const azureCredentials = JSON.parse(process.env.AZURE_CREDENTIALS)
const {clientId, clientSecret, tenantId, subscriptionId} = azureCredentials
core.setSecret(clientId)
core.exportVariable('AZURE_CLIENT_ID', clientId)
core.setSecret(clientSecret)
core.exportVariable('AZURE_CLIENT_SECRET', clientSecret)
core.setSecret(tenantId)
core.exportVariable('AZURE_TENANT_ID', tenantId)
credentials: ${{ secrets.AZURE_CREDENTIALS }}

core.setSecret(subscriptionId)
core.exportVariable('AZURE_SUBSCRIPTION_ID', subscriptionId)
- name: Discover VMs to delete
env:
GH_APP_ID: ${{ secrets.GH_APP_ID }}
GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
run: |
az login --service-principal -u ${{ env.AZURE_CLIENT_ID }} -p ${{ env.AZURE_CLIENT_SECRET }} --tenant ${{ env.AZURE_TENANT_ID }}
az account set --subscription ${{ env.AZURE_SUBSCRIPTION_ID }}
active_vms=$(az vm list -g ${{ secrets.AZURE_RESOURCE_GROUP }} | jq -c '.[] | {name,timeCreated}')
current_time=$(date +%s)
one_hour_ago=$(($current_time - 3600))
Expand Down

0 comments on commit ab3fad1

Please sign in to comment.