Files
org/.github/workflows/detect-pr-pipeline.yaml
T
Chris Farhood 487058ed5e fix: use GitHub API directly instead of gh CLI
The gh CLI is not installed on the runners. Use curl and the GitHub API
directly to set PR labels.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-11 12:43:13 +00:00

83 lines
2.4 KiB
YAML

name: Detect PR Pipeline Type
on:
pull_request:
branches: [main, dev, uat]
workflow_call:
permissions:
contents: read
pull-requests: write
jobs:
detect-pipeline:
runs-on: runners-privilegedescalation
timeout-minutes: 5
outputs:
pipeline-type: ${{ steps.detect.outputs.pipeline-type }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files_separator: '\n'
- name: Detect pipeline type
id: detect
run: |
echo "Changed files:"
echo "${{ steps.changed-files.outputs.all_changed_files }}"
pipeline="pipeline-a"
if [ -n "${{ steps.changed-files.outputs.all_changed_files }}" ]; then
all_infra=true
while IFS= read -r file; do
filename=$(basename "$file")
dirname=$(dirname "$file")
if [ "$dirname" = ".github" ] || \
[[ "$filename" == *.md ]] || \
[[ "$filename" == .eslintrc* ]] || \
[[ "$filename" == .prettierrc* ]] || \
[[ "$filename" == renovate.json* ]] || \
[[ "$filename" == .gitignore ]] || \
[[ "$filename" == .editorconfig ]] || \
[[ "$filename" == LICENSE ]]; then
continue
else
all_infra=false
echo "Non-infra file found: $file"
break
fi
done <<< "${{ steps.changed-files.outputs.all_changed_files }}"
if [ "$all_infra" = true ]; then
pipeline="pipeline-b"
fi
fi
echo "pipeline-type=$pipeline" >> $GITHUB_OUTPUT
echo "Detected pipeline: $pipeline"
- name: Set PR label
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PIPELINE_TYPE: ${{ steps.detect.outputs.pipeline-type }}
run: |
curl -sf \
-X POST \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${REPO}/issues/${PR_NUMBER}/labels" \
-d "{\"labels\":[\"${PIPELINE_TYPE}\"]}"