PR Triggered Tests #50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR Triggered Tests | |
on: | |
pull_request_target: | |
types: [opened, synchronize, reopened] | |
workflow_dispatch: | |
permissions: | |
contents: read | |
jobs: | |
trigger-azure-pipeline: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check if authorized to run tests | |
id: check | |
run: | | |
echo "ok=true" >> $GITHUB_OUTPUT | |
- name: Trigger Azure DevOps Pipeline | |
id: trigger_pipeline | |
if: steps.check.outputs.ok == 'true' | |
run: | | |
PAT="${{ secrets.AZURE_DEVOPS_PAT }}" | |
ORG="sergiovelderrain" | |
PROJECT="sergiovelderrain" | |
PIPELINE_ID="3" | |
API_VERSION="7.0" | |
if [ -z "$PAT" ]; then | |
echo "AZURE_DEVOPS_PAT is not set or empty!" | |
exit 1 | |
fi | |
AUTH=$(echo -n ":$PAT" | base64 | tr -d '\n') | |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
PR_HEAD_REF="develop" | |
else | |
PR_HEAD_REF="${{ github.event.pull_request.head.ref }}" | |
fi | |
JSON_BODY='{ | |
"resources": { | |
"repositories": { | |
"self": { | |
"refName": "refs/heads/'"${PR_HEAD_REF}"'" | |
} | |
} | |
} | |
}' | |
echo "Triggering Azure DevOps pipeline with JSON:" | |
echo "$JSON_BODY" | |
RESPONSE=$(curl --fail --http1.1 -s -X POST \ | |
-H "Authorization: Basic $AUTH" \ | |
-H "Content-Type: application/json" \ | |
-d "$JSON_BODY" \ | |
"https://dev.azure.com/$ORG/$PROJECT/_apis/pipelines/$PIPELINE_ID/runs?api-version=$API_VERSION") | |
echo "Pipeline trigger response:" | |
echo "$RESPONSE" | |
if ! echo "$RESPONSE" | grep -q '^{'; then | |
echo "The response is not JSON, cannot parse with jq." | |
echo "$RESPONSE" | |
exit 1 | |
fi | |
echo "response<<EOF" >> $GITHUB_OUTPUT | |
echo "$RESPONSE" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT |