|
| 1 | +name: Labeler |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + issues: |
| 8 | + types: [opened] |
| 9 | + pull_request: |
| 10 | + types: |
| 11 | + - opened |
| 12 | + - reopened |
| 13 | + - synchronize |
| 14 | + - labeled |
| 15 | + - unlabeled |
| 16 | + branches: |
| 17 | + - main |
| 18 | + |
| 19 | +jobs: |
| 20 | + |
| 21 | + label-sync: |
| 22 | + if: github.event_name == 'push' |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Check out the repository |
| 26 | + uses: actions/checkout@v3 |
| 27 | + - name: Run Labeler |
| 28 | + |
| 29 | + with: |
| 30 | + yaml-file: .github/labels.yaml |
| 31 | + skip-delete: false |
| 32 | + dry-run: false |
| 33 | + |
| 34 | + version-label-check: |
| 35 | + if: | |
| 36 | + github.event_name == 'pull_request' && |
| 37 | + github.actor != 'dependabot[bot]' && |
| 38 | + ( |
| 39 | + contains( github.event.labels.*.name, 'BUMP_MAJOR' ) || |
| 40 | + contains( github.event.pull_request.labels.*.name, 'BUMP_MINOR' ) || |
| 41 | + contains( github.event.pull_request.labels.*.name, 'BUMP_PATCH' ) || |
| 42 | + join(github.event.issue.labels) == '' || |
| 43 | + ( |
| 44 | + !contains( github.event.labels.*.name, 'BUMP_MAJOR' ) && |
| 45 | + !contains( github.event.pull_request.labels.*.name, 'BUMP_MINOR' ) && |
| 46 | + !contains( github.event.pull_request.labels.*.name, 'BUMP_PATCH') |
| 47 | + ) |
| 48 | + ) |
| 49 | + runs-on: ubuntu-latest |
| 50 | + concurrency: |
| 51 | + group: ${{ github.ref }} |
| 52 | + steps: |
| 53 | + - uses: actions/github-script@v6 |
| 54 | + id: script |
| 55 | + with: |
| 56 | + script: | |
| 57 | + var total_labels = 0 |
| 58 | + const labels = await github.rest.issues.listLabelsOnIssue({ |
| 59 | + owner: context.repo.owner, |
| 60 | + repo: context.repo.repo, |
| 61 | + issue_number: context.issue.number, |
| 62 | + }) |
| 63 | + console.log(labels.data) |
| 64 | + for (const label of labels.data) { |
| 65 | + if (label.name === 'BUMP_PATCH') { |
| 66 | + total_labels += 1 |
| 67 | + var version = 'patch' |
| 68 | + } else if (label.name === 'BUMP_MINOR') { |
| 69 | + total_labels += 1 |
| 70 | + var version = 'minor' |
| 71 | + } else if (label.name === 'BUMP_MAJOR') { |
| 72 | + total_labels += 1 |
| 73 | + var version = 'major' |
| 74 | + } |
| 75 | + } |
| 76 | + console.log(total_labels) |
| 77 | + if (total_labels != 1) { |
| 78 | + var status = 'error' |
| 79 | + } else { |
| 80 | + var status = 'success' |
| 81 | + } |
| 82 | + console.log(status) |
| 83 | + core.setOutput('status', status) |
| 84 | + console.log(version) |
| 85 | + core.setOutput('version', version) |
| 86 | + - uses: marocchino/sticky-pull-request-comment@v2 |
| 87 | + if: steps.script.outputs.status != 'success' |
| 88 | + with: |
| 89 | + header: improper-version-labels |
| 90 | + message: | |
| 91 | + # Improper Version Labels |
| 92 | + You don't have the proper labels on this Pull Request to increment the version. |
| 93 | +
|
| 94 | + You must provide one and only one of the following labels to increment the version number: |
| 95 | + - `BUMP_MAJOR` |
| 96 | + - `BUMP_MINOR` |
| 97 | + - `BUMP_PATCH` |
| 98 | + delete: true |
| 99 | + - uses: marocchino/sticky-pull-request-comment@v2 |
| 100 | + if: steps.script.outputs.status == 'success' |
| 101 | + with: |
| 102 | + header: improper-version-labels |
| 103 | + delete: true |
| 104 | + - if: steps.script.outputs.status != 'success' |
| 105 | + run: | |
| 106 | + echo "Incompatible Version Bump Labels Applied" |
| 107 | + exit 1 |
| 108 | +
|
| 109 | + apply-triage-label: |
| 110 | + if: github.event_name == 'issues' |
| 111 | + runs-on: ubuntu-latest |
| 112 | + steps: |
| 113 | + - uses: actions/github-script@v6 |
| 114 | + with: |
| 115 | + script: | |
| 116 | + github.rest.issues.addLabels({ |
| 117 | + issue_number: context.issue.number, |
| 118 | + owner: context.repo.owner, |
| 119 | + repo: context.repo.repo, |
| 120 | + labels: ['triage'] |
| 121 | + }) |
0 commit comments