Skip to content

Commit 99a2bfc

Browse files
authored
ci: Update CI workflows (#131)
Brings in some updated workflows from [CQCL/hugr](http://github.com/CQCL/hugr). - Adds new issues to the hugrverse project. - Checks the conventional commit format in the PR titles, and lets @hugrbot post help messages. - Automate publishing to crates.io with release-plz - Simplifies the changelog format configuration (using the one from CQCL/tket2).
1 parent 71453e8 commit 99a2bfc

File tree

5 files changed

+133
-82
lines changed

5 files changed

+133
-82
lines changed
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Add issues to project
2+
3+
on:
4+
issues:
5+
types:
6+
- opened
7+
8+
jobs:
9+
add-to-project:
10+
name: Add issue to project
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/[email protected]
14+
with:
15+
project-url: https://github.com/orgs/CQCL-DEV/projects/10
16+
github-token: ${{ secrets.HUGRBOT_PAT }}
17+
id: add-project

.github/workflows/pr-title.yml

+95-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Check Conventional Commits format
33
on:
44
pull_request_target:
55
branches:
6-
- main
6+
- main
77
types:
88
- opened
99
- edited
@@ -14,7 +14,7 @@ on:
1414
types: [checks_requested]
1515

1616
permissions:
17-
pull-requests: read
17+
pull-requests: write
1818

1919
jobs:
2020
main:
@@ -23,8 +23,15 @@ jobs:
2323
# The action does not support running on merge_group events,
2424
# but if the check succeeds in the PR there is no need to check it again.
2525
if: github.event_name == 'pull_request_target'
26+
outputs:
27+
# Whether the PR title indicates a breaking change.
28+
breaking: ${{ steps.breaking.outputs.breaking }}
29+
# Whether the PR body contains a "BREAKING CHANGE:" footer describing the breaking change.
30+
has_breaking_footer: ${{ steps.breaking.outputs.has_breaking_footer }}
2631
steps:
27-
- uses: amannn/action-semantic-pull-request@v5
32+
- name: Validate the PR title format
33+
uses: amannn/action-semantic-pull-request@v5
34+
id: lint_pr_title
2835
env:
2936
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3037
with:
@@ -69,4 +76,88 @@ jobs:
6976
# labels change, you might want to use the `labeled` and `unlabeled`
7077
# event triggers in your workflow.
7178
ignoreLabels: |
72-
ignore-semantic-pull-request
79+
ignore-semantic-pull-request
80+
81+
# `action-semantic-pull-request` does not parse the title, so it cannot
82+
# detect if it is marked as a breaking change.
83+
#
84+
# Since at this point we know the PR title is a valid conventional commit,
85+
# we can use a simple regex that looks for a '!:' sequence. It could be
86+
# more complex, but we don't care about false positives.
87+
- name: Check for breaking change flag
88+
id: breaking
89+
run: |
90+
if [[ "${PR_TITLE}" =~ ^.*\!:.*$ ]]; then
91+
echo "breaking=true" >> $GITHUB_OUTPUT
92+
else
93+
echo "breaking=false" >> $GITHUB_OUTPUT
94+
fi
95+
96+
# Check if the PR comment has a "BREAKING CHANGE:" footer describing
97+
# the breaking change.
98+
if [[ "${PR_BODY}" != *"BREAKING CHANGE:"* ]]; then
99+
echo "has_breaking_footer=false" >> $GITHUB_OUTPUT
100+
else
101+
echo "has_breaking_footer=true" >> $GITHUB_OUTPUT
102+
fi
103+
env:
104+
PR_TITLE: ${{ github.event.pull_request.title }}
105+
PR_BODY: ${{ github.event.pull_request.body }}
106+
107+
# Post a help comment if the PR title indicates a breaking change but does
108+
# not contain a "BREAKING CHANGE:" footer.
109+
- name: Require "BREAKING CHANGE:" footer for breaking changes
110+
id: breaking-comment
111+
if: ${{ steps.breaking.outputs.breaking == 'true' && steps.breaking.outputs.has_breaking_footer == 'false' }}
112+
uses: marocchino/sticky-pull-request-comment@v2
113+
with:
114+
header: pr-title-lint-error
115+
message: |
116+
Hey there and thank you for opening this pull request! 👋🏼
117+
118+
It looks like your proposed title indicates a breaking change. If that's the case,
119+
please make sure to include a "BREAKING CHANGE:" footer in the body of the pull request
120+
describing the breaking change and any migration instructions.
121+
GITHUB_TOKEN: ${{ secrets.HUGRBOT_PAT }}
122+
- name: Fail if the footer is required but missing
123+
if: ${{ steps.breaking.outputs.breaking == 'true' && steps.breaking.outputs.has_breaking_footer == 'false' }}
124+
run: exit 1
125+
126+
- name: Post a comment if the PR badly formatted
127+
uses: marocchino/sticky-pull-request-comment@v2
128+
# When the previous steps fails, the workflow would stop. By adding this
129+
# condition you can continue the execution with the populated error message.
130+
if: always() && (steps.lint_pr_title.outputs.error_message != null)
131+
with:
132+
header: pr-title-lint-error
133+
message: |
134+
Hey there and thank you for opening this pull request! 👋🏼
135+
136+
We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/)
137+
and it looks like your proposed title needs to be adjusted.
138+
139+
Your title should look like this. The scope field is optional.
140+
```
141+
<type>(<scope>): <description>
142+
```
143+
144+
If the PR includes a breaking change, mark it with an exclamation mark:
145+
```
146+
<type>!: <description>
147+
```
148+
and include a "BREAKING CHANGE:" footer in the body of the pull request.
149+
150+
Details:
151+
```
152+
${{ steps.lint_pr_title.outputs.error_message }}
153+
```
154+
GITHUB_TOKEN: ${{ secrets.HUGRBOT_PAT }}
155+
156+
# Delete previous comments when the issues have been resolved
157+
# This step doesn't run if any of the previous checks fails.
158+
- name: Delete previous comments
159+
uses: marocchino/sticky-pull-request-comment@v2
160+
with:
161+
header: pr-title-lint-error
162+
delete: true
163+
GITHUB_TOKEN: ${{ secrets.HUGRBOT_PAT }}

.github/workflows/release-plz.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: Release-plz
1+
# Automatic changelog, version bumping, and semver-checks with release-plz for rust projects
2+
name: Release-plz 🦀
23

34
permissions:
45
pull-requests: write
@@ -22,7 +23,6 @@ jobs:
2223
uses: dtolnay/rust-toolchain@stable
2324
- name: Run release-plz
2425
uses: MarcoIeni/[email protected]
25-
with:
26-
command: release-pr
2726
env:
28-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
GITHUB_TOKEN: ${{ secrets.HUGRBOT_PAT }}
28+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

cliff.toml

-73
This file was deleted.

release-plz.toml

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
[workspace]
2-
changelog_config = "cliff.toml" # use a custom git-cliff configuration
2+
pr_draft = true
3+
4+
[changelog]
5+
sort_commits = "oldest"
6+
7+
commit_parsers = [
8+
{ message = "^feat", group = "New Features" },
9+
{ message = "^fix", group = "Bug Fixes" },
10+
{ message = "^docs", group = "Documentation" },
11+
{ message = "^style", group = "Styling" },
12+
{ message = "^refactor", group = "Refactor" },
13+
{ message = "^perf", group = "Performance" },
14+
{ message = "^test", group = "Testing" },
15+
{ message = "^chore", group = "Miscellaneous Tasks", skip = true },
16+
{ message = "^revert", group = "Reverted changes", skip = true },
17+
{ message = "^ci", group = "CI", skip = true },
18+
]

0 commit comments

Comments
 (0)