diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 00000000..130e4c69 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,5 @@ +cli: + - changed-files: + - any-glob-to-any-file: + - 'Sources/CLI/**' + - 'Sources/ContainerCommands/**' \ No newline at end of file diff --git a/.github/workflows/pr-label-analysis.yml b/.github/workflows/pr-label-analysis.yml new file mode 100644 index 00000000..e8b20738 --- /dev/null +++ b/.github/workflows/pr-label-analysis.yml @@ -0,0 +1,26 @@ +name: PR Label Analysis + +on: + pull_request: + types: [opened] + +permissions: + contents: read + +jobs: + analyze: + name: Analyze PR for labeling + runs-on: ubuntu-latest + + steps: + - name: Save PR metadata + run: | + mkdir -p ./pr-metadata + echo "${{ github.event.pull_request.number }}" > ./pr-metadata/pr-number.txt + + - name: Upload PR metadata as artifact + uses: actions/upload-artifact@v4 + with: + name: pr-metadata-${{ github.event.pull_request.number }} + path: pr-metadata/ + retention-days: 1 \ No newline at end of file diff --git a/.github/workflows/pr-label-apply.yml b/.github/workflows/pr-label-apply.yml new file mode 100644 index 00000000..a68f8bff --- /dev/null +++ b/.github/workflows/pr-label-apply.yml @@ -0,0 +1,55 @@ +name: PR Label Apply + +on: + workflow_run: + workflows: ["PR Label Analysis"] + types: + - completed + +permissions: + contents: read + +jobs: + apply-labels: + name: Apply labels to PR + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download PR metadata artifact + uses: actions/download-artifact@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + pattern: pr-metadata-* + merge-multiple: false + continue-on-error: true + id: download-artifact + + - name: Read PR number + id: pr-number + run: | + METADATA_DIR=$(find . -type d -name "pr-metadata-*" 2>/dev/null | head -n 1) + + if [ -z "$METADATA_DIR" ]; then + echo "No metadata found" + exit 1 + fi + + PR_NUMBER=$(cat "${METADATA_DIR}/pr-number.txt") + echo "number=${PR_NUMBER}" >> $GITHUB_OUTPUT + echo "PR Number: ${PR_NUMBER}" + + - name: Apply labels using labeler + uses: actions/labeler@v5 + with: + pr-number: ${{ steps.pr-number.outputs.number }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + configuration-path: .github/labeler.yml + sync-labels: true \ No newline at end of file