Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/actions/get-ado-token/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Get Azure DevOps Access Token
description: Get an access token to authenticate with Azure DevOps
inputs:
client-id:
description: "The client ID of the application calling Azure DevOps"
required: true
tenant-id:
description: "The tenant ID of the application calling Azure DevOps"
required: true
organization:
description: "The Azure DevOps organization to authenticate with"
required: true
outputs:
token:
description: "The access token to authenticate with Azure DevOps"
value: ${{ steps.ADOAuth.outputs.token }}

runs:
using: "composite"
steps:
- name: OIDC Login with AzPowershell
uses: azure/login@v2
with:
client-id: ${{ inputs.client-id }}
tenant-id: ${{ inputs.tenant-id }}
allow-no-subscriptions: true
enable-AzPSSession: true
- id: ADOAuth
name: Get ADO Access Token
uses: azure/powershell@v1
with:
azPSVersion: "latest"
inlineScript: |
function decodeToken([string]$token) {
$t = $token.split('.')[1]
while($t.Length % 4 -ne 0) { $t += '=' }
ConvertFrom-Json ([System.Text.Encoding]::Ascii.GetString([System.Convert]::FromBase64String($t)))
}

$accessToken = az account get-access-token --resource="https://${{inputs.organization}}.visualstudio.com" --query accessToken
decodeToken($accessToken)
"token=$accessToken" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
72 changes: 72 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Pull Request Build and Validation

on:
pull_request:
branches:
- main

env:
AzDevOpsPipelineId: 31435

permissions:
id-token: write
contents: read

jobs:
build:
if: (github.event.pull_request.base.repo.full_name == github.event.pull_request.head.repo.full_name) && (github.event_name == 'pull_request') && (github.actor != 'dependabot[bot]')
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Get Azure DevOps Access Token
id: getToken
uses: "./.github/actions/get-ado-token"
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
organization: ${{ vars.AZDEVOPS_ORGANIZATION }}

- name: Trigger Azure DevOps Pipeline
id: trigger
run: |
response=$(curl -v -X POST \
-H "Authorization: Bearer ${{ steps.getToken.outputs.token }}" \
-H "Content-Type: application/json" \
-d '{"resources": {"repositories": {"self": {"refName": "refs/heads/main"}}},"variables": {"ProjectBranch": {"value": "${{ github.head_ref || github.ref_name }}"}}}' \
${{ vars.AZDEVOPS_URL }}/_apis/pipelines/${{ env.AzDevOpsPipelineId }}/runs?api-version=7.1)
echo $BRANCH_NAME
echo $response
echo "::set-output name=run_id::$(echo $response | jq -r .id)"
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
# -d '{"resources": {"repositories": {"self": {"refName": "refs/heads/main"}}}}' \
# refs/heads/users/mbarbour/pipelineUpdate

- name: Monitor Pipeline Run
run: |
run_id=${{ steps.trigger.outputs.run_id }}
status="inProgress"
while [ "$status" == "inProgress" ] || [ "$status" == "notStarted" ] || [ "$status" == "canceling" ] ; do
response=$(curl -X GET \
-H "Authorization: Bearer ${{ steps.getToken.outputs.token }}" \
${{ vars.AZDEVOPS_URL }}/_apis/pipelines/${{ env.AzDevOpsPipelineId }}/runs/$run_id?api-version=7.1)
status=$(echo $response | jq -r .state)
r1=$(echo $response | jq -r .result)
weblink=$(echo $response | jq -r ._links.web.href)
echo "Pipeline status: $status"
echo "Result response: $r1"
echo "WebLink: $weblink"
if [ "$status" == "completed" ]; then
result=$(echo $response | jq -r .result)
if [ "$result" == "succeeded" ]; then
echo "Pipeline succeeded"
exit 0
else
echo "::error file={name},line={line},endLine={endLine},title={title}::Pipeline failed with result: $result"
echo "Pipeline failed with result: $result"
exit 1
fi
fi
sleep 10
done
Loading
Loading