-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (93 loc) · 3.41 KB
/
pr_lint.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: PR Validation
on:
pull_request:
jobs:
validate-pr:
runs-on: ubuntu-latest
steps:
- name: Check labels
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const labels = pullRequest.labels.map(label => label.name);
const invalidLabels = ['feature request', 'invalid', 'question'];
const hasInvalidLabel = labels.some(label => invalidLabels.includes(label));
if (labels.length === 0) {
core.setFailed('Pull request must have at least one label!');
}
if (hasInvalidLabel) {
core.setFailed('Pull request must have an invalid label: ' + invalidLabels.join(', '));
}
- name: Check assignees
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
if (pullRequest.assignees.length === 0) {
core.setFailed('Pull request must have an assignee');
}
- name: Check draft status
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
if (pullRequest.draft) {
core.setFailed('Pull request must not be a draft');
}
validate-code:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: '3.12'
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Run Ruff
run: poetry run ruff check --output-format=github .
- name: Run pre-commit hooks
run: poetry run pre-commit run --all-files --show-diff-on-failure
- name: Get version from pyproject.toml
id: get_version
run: |
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT
validate-branch:
runs-on: ubuntu-latest
needs:
- validate-code
if: startsWith(github.head_ref, 'release/')
steps:
- name: Check branch name with version
run: |
# Extract the branch name from the GitHub context
branch_name=${{ github.head_ref }}
# Check if the branch name starts with "release/" and does not match the version
if [[ $branch_name == release/* && $branch_name != "release/${{ needs.validate-code.outputs.version }}" ]]; then
echo "Branch name does not match the version in pyproject.toml"
exit 1
fi