|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +--- |
| 18 | +name: Label tests-only PRs |
| 19 | + |
| 20 | +on: # yamllint disable-line rule:truthy |
| 21 | + pull_request: |
| 22 | + types: [opened, synchronize, reopened] |
| 23 | + |
| 24 | +permissions: |
| 25 | + contents: read |
| 26 | + pull-requests: write |
| 27 | + |
| 28 | +jobs: |
| 29 | + label-tests-only: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Check if all files are tests and add label |
| 33 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 34 | + with: |
| 35 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + script: | |
| 37 | + // Get list of changed files in the PR |
| 38 | + const files = await github.paginate(github.rest.pulls.listFiles, { |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + pull_number: context.issue.number, |
| 42 | + }); |
| 43 | +
|
| 44 | + const changedFiles = files.map(file => file.filename); |
| 45 | + console.log(`Found ${changedFiles.length} changed files.`); |
| 46 | +
|
| 47 | + const testPatterns = [ |
| 48 | + /^airflow-core\/tests\//, |
| 49 | + /^task-sdk\/tests\//, |
| 50 | + /^airflow-ctl-tests\//, |
| 51 | + /^airflow-e2e-tests\//, |
| 52 | + /^clients\/.*\/test.*\.py$/, |
| 53 | + /^devel-common\/tests\//, |
| 54 | + /^dev\/breeze\/tests\//, |
| 55 | + /^docker-tests\//, |
| 56 | + /^helm-tests\//, |
| 57 | + /^kubernetes-tests\//, |
| 58 | + /^task-sdk-integration-tests\//, |
| 59 | + /^providers\/.*\/tests\// |
| 60 | + ]; |
| 61 | +
|
| 62 | + const allTests = changedFiles.every(file => |
| 63 | + testPatterns.some(pattern => pattern.test(file)) |
| 64 | + ); |
| 65 | +
|
| 66 | + if (allTests && changedFiles.length > 0) { |
| 67 | + console.log('All changed files are tests. Adding kind:tests label.'); |
| 68 | + await github.rest.issues.addLabels({ |
| 69 | + owner: context.repo.owner, |
| 70 | + repo: context.repo.repo, |
| 71 | + issue_number: context.issue.number, |
| 72 | + labels: ['kind:tests'] |
| 73 | + }); |
| 74 | + } else { |
| 75 | + console.log('PR contains non-test files or no files changed.'); |
| 76 | + changedFiles.forEach(file => { |
| 77 | + const isTest = testPatterns.some(pattern => pattern.test(file)); |
| 78 | + if (!isTest) { |
| 79 | + console.log(` Non-test file: ${file}`); |
| 80 | + } |
| 81 | + }); |
| 82 | + } |
0 commit comments