Skip to content

ssssswwwwwqqqqq

ssssswwwwwqqqqq #14

name: PR Triggered Tests
on:
# Using pull_request_target so we can access secrets
pull_request_target:
types: [opened, synchronize, reopened]
jobs:
trigger-azure-pipeline:
runs-on: ubuntu-latest
if: contains(github.event.pull_request.base.ref, 'develop') # optional: trigger only if PR is into main
steps:
- name: Check if authorized to run tests
id: check
run: |
# Implement your logic here. For example, check PR labels using GitHub CLI:
# gh pr view ${{ github.event.pull_request.number }} --json labels
# if no label or unauthorized contributor, exit
# For simplicity, we just say we always trigger. In reality, add conditions.
echo "ok=true" >> $GITHUB_OUTPUT
- name: Trigger Azure DevOps Pipeline
if: steps.check.outputs.ok == 'true'
run: |
PAT="${{ secrets.AZURE_DEVOPS_PAT }}"
ORG="sergiovelderrain"
PROJECT="sergiovelderrain"
PIPELINE_ID="1"
API_VERSION="6.0-preview.1"
AUTH=$(echo -n ":$PAT" | base64)
# We can specify a branch or a commit ref from the PR. Usually you'd run tests against the PR's branch.
# Since we're using pull_request_target, be careful with checking out code from PR.
# It's safer to just run pipeline against the PR's head commit reference retrieved from the event payload.
PR_HEAD_REF="${{ github.event.pull_request.head.ref }}"
REPO_NAME="${{ github.event.pull_request.head.repo.name }}"
# If your Azure DevOps pipeline is configured to use the same repo, specify it here:
# Ensure that your pipeline definition knows how to handle arbitrary refs.
JSON_BODY='{
"resources": {
"repositories": {
"self": {
"refName": "refs/heads/'"${PR_HEAD_REF}"'"
}
}
}
}'
curl -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"