diff --git a/.github/workflows/detect-pr-pipeline.yaml b/.github/workflows/detect-pr-pipeline.yaml new file mode 100644 index 0000000..ae48a28 --- /dev/null +++ b/.github/workflows/detect-pr-pipeline.yaml @@ -0,0 +1,73 @@ +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' + run: | + gh pr edit "${{ github.event.pull_request.number }}" \ + --add-label "${{ steps.detect.outputs.pipeline-type }}"