Skip to content

Commit 748fb9c

Browse files
committed
feat: add github workflows for rust lib
1 parent 9725e62 commit 748fb9c

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed

.github/workflows/assigne.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Pull request assignee
2+
3+
on:
4+
pull_request:
5+
types: [assigned, unassigned, synchronize]
6+
7+
jobs:
8+
assignee:
9+
name: 'check assignee'
10+
11+
steps:
12+
- name: Check if there is at least one assignee
13+
uses: actions/github-script@v2
14+
with:
15+
github-token: ${{ secrets.GITHUB_TOKEN }}
16+
script: |
17+
const { data: pull } = await github.pulls.get({
18+
owner: context.repo.owner,
19+
repo: context.repo.repo,
20+
pull_number: context.payload.pull_request.number,
21+
});
22+
if (pull.assignees.length > 0) {
23+
return;
24+
}
25+
throw new Error('Should have at least one assignee');

.github/workflows/changelog.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Pull request changelog
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, labeled, unlabeled]
6+
7+
jobs:
8+
changelog:
9+
name: 'check changelog change'
10+
11+
steps:
12+
- name: Fail if no changelog change when needed
13+
uses: actions/github-script@v2
14+
with:
15+
github-token: ${{ secrets.GITHUB_TOKEN }}
16+
script: |
17+
const labelsWhereChangelogChangeIsRequired = [
18+
'Action: patch bump',
19+
'Action: minor bump',
20+
'Action: major bump',
21+
];
22+
const { data: labels } = await github.issues.listLabelsOnIssue({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
issue_number: context.payload.pull_request.number,
26+
per_page: 100,
27+
});
28+
const matchingLabels = labels
29+
.filter(label => labelsWhereChangelogChangeIsRequired.includes(label.name))
30+
if (matchingLabels.length === 0) {
31+
console.log('::debug ::No label requiring changelog change. Nothing to do')
32+
return;
33+
}
34+
const { data: files } = await github.pulls.listFiles({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
pull_number: context.payload.pull_request.number,
38+
per_page: 100,
39+
});
40+
const fileNotDeletedNames = files
41+
.filter(file => file.status === 'added' || file.status === 'modified')
42+
.map(file => file.filename)
43+
if (!fileNotDeletedNames.includes('CHANGELOG.md')) {
44+
throw new Error('CHANGELOG.md Unreleased section shoud have line additions when PR is not a no-release')
45+
}

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Continuous integration
2+
3+
on:
4+
pull_request:
5+
types: [push, synchronize]
6+
7+
jobs:
8+
clippy_check:
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: actions-rs/toolchain@v1
12+
with:
13+
toolchain: stable
14+
components: clippy
15+
- uses: actions-rs/clippy-check@v1
16+
with:
17+
token: ${{ secrets.GITHUB_TOKEN }}
18+
args: --all-features
19+
build_and_test:
20+
name: Build CI
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: actions-rs/toolchain@v1
24+
with:
25+
toolchain: stable
26+
- uses: actions-rs/cargo@v1
27+
with:
28+
command: test
29+
args: --verbose
30+
- uses: actions-rs/cargo@v1
31+
with:
32+
command: check
33+
args: --all-features --verbose

.github/workflows/label.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Pull request labels
2+
3+
on:
4+
pull_request:
5+
types: [labeled, unlabeled, synchronize]
6+
7+
jobs:
8+
version-labels:
9+
name: 'check version label'
10+
runs-on: self-hosted
11+
12+
steps:
13+
- name: Check if version label is present
14+
uses: actions/github-script@v2
15+
with:
16+
github-token: ${{ secrets.GITHUB_TOKEN }}
17+
script: |
18+
const versionLabels = [
19+
'Action: no bump',
20+
'Action: beta bump',
21+
'Action: patch bump',
22+
'Action: minor bump',
23+
'Action: major bump',
24+
];
25+
const { data: labels } = await github.issues.listLabelsOnIssue({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
issue_number: context.payload.pull_request.number,
29+
per_page: 100,
30+
});
31+
const versionLabelsPresent = labels
32+
.filter(label => versionLabels.includes(label.name))
33+
if (versionLabelsPresent.length === 1) {
34+
return;
35+
}
36+
console.log(`::debug ::${versionLabelsPresent.length} matching labels`);
37+
throw new Error(`Should have one and only one of ${versionLabels.join(', ')} labels`);

0 commit comments

Comments
 (0)