Skip to content

Instantly share code, notes, and snippets.

@tpeczek
Created October 7, 2022 19:21
Show Gist options
  • Save tpeczek/eba5b757fb465dadf28cc11be85c1114 to your computer and use it in GitHub Desktop.
Save tpeczek/eba5b757fb465dadf28cc11be85c1114 to your computer and use it in GitHub Desktop.
GitHub Actions Workflow for Commits Promotion to Azure Databricks Repo
name: Commits Promotion To Azure Databricks Repo
on: push
jobs:
promote-commits:
runs-on: ubuntu-latest
steps:
- name: Update Azure Databricks Repos Through API
shell: pwsh
env:
AZURE_SP_TENANT_ID: ${{ secrets.AZURE_SP_TENANT_ID }}
AZURE_SP_CLIENT_ID: ${{ secrets.AZURE_SP_CLIENT_ID }}
AZURE_SP_CLIENT_SECRET: ${{ secrets.AZURE_SP_CLIENT_SECRET }}
AZURE_DATABRICKS_WORKSPACE_INSTANCE_NAME: ${{ secrets.AZURE_DATABRICKS_WORKSPACE_INSTANCE_NAME }}
GITHUB_REPOSITORY_URL: ${{ github.repositoryUrl }}
GITHUB_BRANCH_NAME: ${{ github.ref_name }}
run: |
$githubRepositoryUrl = $env:GITHUB_REPOSITORY_URL.replace("git://","https://")
$azureAdAccessTokenUri = "https://login.microsoftonline.com/$env:AZURE_SP_TENANT_ID/oauth2/v2.0/token"
$azureAdAccessTokenHeaders = @{ "Content-Type" = "application/x-www-form-urlencoded" }
$azureAdAccessTokenBody = "client_id=$env:AZURE_SP_CLIENT_ID&grant_type=client_credentials&scope=2ff814a6-3304-4ab8-85cb-cd0e6f879c1d%2F.default&client_secret=$env:AZURE_SP_CLIENT_SECRET"
$azureAdAccessTokenResponse = Invoke-RestMethod -Method POST -Uri $azureAdAccessTokenUri -Headers $azureAdAccessTokenHeaders -Body $azureAdAccessTokenBody
$azureAdAccessToken = $azureAdAccessTokenResponse.access_token
$azureDatabricksReposUri = "https://$env:AZURE_DATABRICKS_WORKSPACE_INSTANCE_NAME/api/2.0/repos"
$azureDatabricksReposHeaders = @{ Authorization = "Bearer $azureAdAccessToken" }
$azureDatabricksReposResponse = Invoke-RestMethod -Method GET -Uri $azureDatabricksReposUri -Headers $azureDatabricksReposHeaders
foreach ($azureDatabricksRepo in $azureDatabricksReposResponse.repos)
{
if (($azureDatabricksRepo.url -eq $githubRepositoryUrl) -and ($azureDatabricksRepo.branch -eq $env:GITHUB_BRANCH_NAME))
{
$azureDatabricksRepoId = $azureDatabricksRepo.id;
$azureDatabricksRepoUri = "https://$env:AZURE_DATABRICKS_WORKSPACE_INSTANCE_NAME/api/2.0/repos/$azureDatabricksRepoId"
$updateAzureDatabricksRepoBody = @{ "branch" = $azureDatabricksRepo.branch }
Invoke-RestMethod -Method PATCH -Uri $azureDatabricksRepoUri -Headers $azureDatabricksReposHeaders -Body ($updateAzureDatabricksRepoBody|ConvertTo-Json)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment