Skip to content

Commit

Permalink
chore: add mergify and pr lint workflows (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr authored Dec 21, 2023
1 parent 6aef97a commit 824d601
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/pull-request-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Pull Request Lint
on:
pull_request_target:
types:
- opened
- synchronize
- reopened
- edited
branches-ignore:
- mergify/merge-queue/*
jobs:
validate:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |-
feat
fix
docs
chore
rfc
revert
subjectPattern: ^[^A-Z][^:]+[^.]$
subjectPatternError: Subject must start with a lowercase, should not include ':'
and should not end with a period
requireScope: false
3 changes: 3 additions & 0 deletions .github/workflows/redis-pull.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ jobs:
- name: Test
run: wing test
working-directory: redis
- name: Pack
run: wing pack
working-directory: redis
55 changes: 55 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
queue_rules:
- name: default
speculative_checks: 2
conditions:
- -files=.mergify.yml
pull_request_rules:
- name: automatic merge
actions:
comment:
message: >
Thanks for contributing, @{{author}}! This PR will now be added to the
[merge queue](https://mergify.com/merge-queue), or immediately merged
if `{{head}}` is up-to-date with `{{base}}` and the queue is empty.
queue:
name: default
method: squash
commit_message_template: |-
{{ title }} (#{{ number }})
{{ body }}
conditions:
- -files=.mergify.yml
- -title~=(?i)wip
- -label~=(🚧 pr/do-not-merge|⚠️ pr/review-mutation)
- -merged
- -closed
- branch-protection-review-decision=APPROVED
- "#approved-reviews-by>=1"
- "#changes-requested-reviews-by=0"
- "#review-threads-unresolved=0"
- -approved-reviews-by~=author
- check-success=Validate PR title
- base=main
- name: requires manual merge
conditions:
- files=.mergify.yml
- -title~=(?i)wip
- -label~=(🚧 pr/do-not-merge|⚠️ pr/review-mutation|⚠️
mergify/review-config)
- -merged
- -closed
- "#approved-reviews-by>=1"
- "#changes-requested-reviews-by=0"
- "#review-threads-unresolved=0"
- -approved-reviews-by~=author
- check-success=Validate PR title
- base=main
actions:
comment:
message: Thank you for contributing! Your pull request contains mergify
configuration changes and needs manual merge from a maintainer (be
sure to [allow changes to be pushed to your
fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork)).
label:
add:
- ⚠️ mergify/review-config
4 changes: 4 additions & 0 deletions generate-workflows.main.w
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
bring fs;
bring "./library.w" as l;
bring "./stale.w" as stale;
bring "./mergify.w" as mergify;
bring "./pr-lint.w" as prlint;

// clean up
let workflowdir = ".github/workflows";
Expand All @@ -17,3 +19,5 @@ for file in fs.readdir(".") {
}

new stale.StaleWorkflow(workflowdir);
new mergify.MergifyWorkflow();
new prlint.PullRequestLintWorkflow(workflowdir);
72 changes: 72 additions & 0 deletions mergify.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
bring fs;

pub class MergifyWorkflow {
new() {
fs.writeYaml(".mergify.yml", {
"queue_rules": [
{
"name": "default",
"speculative_checks": 2,
"conditions": [
"-files=.mergify.yml",
]
}
],
"pull_request_rules": [
{
"name": "automatic merge",
"actions": {
"comment": {
"message": "Thanks for contributing, @\{\{author\}\}! This PR will now be added to the [merge queue](https://mergify.com/merge-queue), or immediately merged if `\{\{head\}\}` is up-to-date with `\{\{base\}\}` and the queue is empty.\n"
},
"queue": {
"name": "default",
"method": "squash",
"commit_message_template": "\{\{ title \}\} (#\{\{ number \}\})\n\{\{ body \}\}"
}
},
"conditions": [
"-files=.mergify.yml",
"-title~=(?i)wip",
"-label~=(🚧 pr/do-not-merge|⚠️ pr/review-mutation)",
"-merged",
"-closed",
"branch-protection-review-decision=APPROVED",
"#approved-reviews-by>=1",
"#changes-requested-reviews-by=0",
"#review-threads-unresolved=0",
"-approved-reviews-by~=author",
"check-success=Validate PR title",
"base=main",
]
},
{
"name": "requires manual merge",
"conditions": [
"files=.mergify.yml",
"-title~=(?i)wip",
"-label~=(🚧 pr/do-not-merge|⚠️ pr/review-mutation|⚠️ mergify/review-config)",
"-merged",
"-closed",
"#approved-reviews-by>=1",
"#changes-requested-reviews-by=0",
"#review-threads-unresolved=0",
"-approved-reviews-by~=author",
"check-success=Validate PR title",
"base=main"
],
"actions": {
"comment": {
"message": "Thank you for contributing! Your pull request contains mergify configuration changes and needs manual merge from a maintainer (be sure to [allow changes to be pushed to your fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork))."
},
"label": {
"add": [
"⚠️ mergify/review-config"
]
},
}
}
]
});
}
}
35 changes: 35 additions & 0 deletions pr-lint.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
bring fs;

pub class PullRequestLintWorkflow {
new(workflowdir: str) {
fs.writeYaml("{workflowdir}/pull-request-lint.yaml", {
name: "Pull Request Lint",
on: {
pull_request_target: {
types: ["opened", "synchronize", "reopened", "edited"],
"branches-ignore": ["mergify/merge-queue/*"],
},
},
"jobs": {
"validate": {
"name": "Validate PR title",
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "amannn/[email protected]",
"env": {
"GITHUB_TOKEN": "$\{\{ secrets.GITHUB_TOKEN \}\}"
},
"with": {
"types": "feat\nfix\ndocs\nchore\nrfc\nrevert",
"subjectPattern": "^[^A-Z][^:]+[^.]$",
"subjectPatternError": "Subject must start with a lowercase, should not include ':' and should not end with a period",
"requireScope": false
}
}
]
}
}
});
}
}

0 comments on commit 824d601

Please sign in to comment.