95d8d8056d
Problem: --depth=1 fetch does not bring in the PR head branch name as a ref, causing 'origin/gandalf/pri-1593-fix-main' to be unknown. Fix: fetch all PR head refs with full refspec and diff against HEAD instead of a non-existent remote branch ref. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
82 lines
2.6 KiB
YAML
82 lines
2.6 KiB
YAML
name: Detect PR Pipeline Type
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [main, dev, uat]
|
|
workflow_call:
|
|
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
test-detection-logic:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 2
|
|
|
|
env:
|
|
HEAD_REF: ${{ github.head_ref }}
|
|
BASE_REF: ${{ github.base_ref }}
|
|
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
git clone --depth=1 "https://x-access-token:${{ secrets.GITEA_TOKEN }}@git.farh.net/${{ github.repository }}.git" .
|
|
git fetch origin "$BASE_REF" --depth=1
|
|
git fetch origin +refs/pull/*/head:refs/pull/*/head --depth=1
|
|
git checkout "${{ github.sha }}"
|
|
|
|
- name: Run detection tests
|
|
run: bash scripts/test-detect-pipeline.sh
|
|
|
|
detect-pipeline:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 5
|
|
|
|
env:
|
|
HEAD_REF: ${{ github.head_ref }}
|
|
BASE_REF: ${{ github.base_ref }}
|
|
|
|
outputs:
|
|
pipeline-type: ${{ steps.detect.outputs.pipeline-type }}
|
|
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
git clone --depth=1 "https://x-access-token:${{ secrets.GITEA_TOKEN }}@git.farh.net/${{ github.repository }}.git" .
|
|
git fetch origin "$BASE_REF" --depth=1
|
|
git fetch origin +refs/pull/*/head:refs/pull/*/head --depth=1
|
|
git checkout "${{ github.sha }}"
|
|
|
|
- name: Get changed files
|
|
run: |
|
|
mkdir -p /tmp/pr-detect
|
|
git fetch origin "$BASE_REF" --depth=1 2>/dev/null
|
|
git fetch origin +refs/pull/*/head:refs/pull/*/head --depth=1 2>/dev/null
|
|
git diff --name-only "origin/$BASE_REF"...HEAD > /tmp/pr-detect/changed_files.txt
|
|
echo "Files found: $(wc -l < /tmp/pr-detect/changed_files.txt)"
|
|
cat /tmp/pr-detect/changed_files.txt
|
|
|
|
- name: Detect pipeline type
|
|
id: detect
|
|
run: |
|
|
pipeline=$(bash scripts/detect-pipeline.sh < /tmp/pr-detect/changed_files.txt)
|
|
|
|
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}\"]}"
|