Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2025-06-09T09:30:36Z by kres 2469b9b-dirty.

name: Lock old issues
"on":
schedule:
- cron: 0 2 * * *
permissions:
issues: write
jobs:
action:
runs-on:
- ubuntu-latest
steps:
- name: Lock old issues
uses: dessant/lock-threads@v5.0.1
with:
issue-inactive-days: "60"
log-output: "true"
process-only: issues
27 changes: 27 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2025-06-05T12:39:56Z by kres fc6afbe-dirty.

name: Close stale issues and PRs
"on":
schedule:
- cron: 30 1 * * *
permissions:
issues: write
pull-requests: write
jobs:
stale:
runs-on:
- ubuntu-latest
steps:
- name: Close stale issues and PRs
uses: actions/stale@v9.1.0
with:
close-issue-message: This issue was closed because it has been stalled for 7 days with no activity.
days-before-issue-close: "5"
days-before-issue-stale: "180"
days-before-pr-close: "-1"
days-before-pr-stale: "45"
operations-per-run: "2000"
stale-issue-message: This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
stale-pr-message: This PR is stale because it has been open 45 days with no activity.
2 changes: 1 addition & 1 deletion cmd/kres/cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func runGen() error {
case "drone":
outputs = append(outputs, output.Wrap[drone.Compiler](drone.NewOutput()))
case "ghaction":
outputs = append(outputs, output.Wrap[ghworkflow.Compiler](ghworkflow.NewOutput(options.MainBranch, !options.CompileGithubWorkflowsOnly)))
outputs = append(outputs, output.Wrap[ghworkflow.Compiler](ghworkflow.NewOutput(options.MainBranch, !options.CompileGithubWorkflowsOnly, !options.SkipStaleWorkflow)))
}

if err := proj.Compile(outputs); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions internal/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,10 @@ const (
// VTProtobufVersion is the version of vtprotobuf.
// renovate: datasource=go depName=github.com/planetscale/vtprotobuf
VTProtobufVersion = "v0.6.0"
// StaleActionVersion is the version of stale github action.
// renovate: datasource=github-releases depName=actions/stale
StaleActionVersion = "v9.1.0"
// LockThreadsActionVersion is the version of lock threads github action.
// renovate: datasource=github-releases depName=dessant/lock-threads
LockThreadsActionVersion = "v5.0.1"
)
70 changes: 69 additions & 1 deletion internal/output/ghworkflow/gh_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type Output struct {
}

// NewOutput creates new .github/workflows/ci.yaml output.
func NewOutput(mainBranch string, withDefaultJob bool) *Output {
func NewOutput(mainBranch string, withDefaultJob bool, withStaleJob bool) *Output {
workflows := map[string]*Workflow{
ciWorkflow: {
Name: "default",
Expand Down Expand Up @@ -143,6 +143,74 @@ func NewOutput(mainBranch string, withDefaultJob bool) *Output {
},
}

if withStaleJob {
workflows[".github/workflows/lock.yml"] = &Workflow{
Name: "Lock old issues",
On: On{
Schedule: []Schedule{
{
Cron: "0 2 * * *", // Every day at 2 AM
},
},
},
Permissions: map[string]string{
"issues": "write",
},
Jobs: map[string]*Job{
"action": {
RunsOn: []string{"ubuntu-latest"},
Steps: []*JobStep{
{
Name: "Lock old issues",
Uses: "dessant/lock-threads@" + config.LockThreadsActionVersion,
With: map[string]string{
"issue-inactive-days": "60",
"process-only": "issues",
"log-output": "true",
},
},
},
},
},
}

workflows[".github/workflows/stale.yml"] = &Workflow{
Name: "Close stale issues and PRs",
On: On{
Schedule: []Schedule{
{
Cron: "30 1 * * *", // Every day at 1:30 AM
},
},
},
Permissions: map[string]string{
"issues": "write",
"pull-requests": "write",
},
Jobs: map[string]*Job{
"stale": {
RunsOn: []string{"ubuntu-latest"},
Steps: []*JobStep{
{
Name: "Close stale issues and PRs",
Uses: "actions/stale@" + config.StaleActionVersion,
With: map[string]string{
"stale-issue-message": "This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.",
"stale-pr-message": "This PR is stale because it has been open 45 days with no activity.",
"close-issue-message": "This issue was closed because it has been stalled for 7 days with no activity.",
"days-before-issue-stale": "180",
"days-before-pr-stale": "45",
"days-before-issue-close": "5",
"days-before-pr-close": "-1", // never close PRs
"operations-per-run": "2000", // the maximum number of operations to perform per run
},
},
},
},
},
}
}

if withDefaultJob {
workflows[ciWorkflow].Jobs = map[string]*Job{
"default": {
Expand Down
1 change: 1 addition & 0 deletions internal/output/ghworkflow/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Workflow struct {
Name string `yaml:"name"`
Concurrency `yaml:"concurrency,omitempty"`
On `yaml:"on"`
Permissions map[string]string `yaml:"permissions,omitempty"`
Env map[string]string `yaml:"env,omitempty"`
Jobs map[string]*Job `yaml:"jobs"`
}
Expand Down
3 changes: 3 additions & 0 deletions internal/project/common/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type Repository struct { //nolint:govet
LicenseChecks []licensepolicy.Spec `yaml:"licenseChecks"`

BotName string `yaml:"botName"`

SkipStaleWorkflow bool `yaml:"skipStaleWorkflow"`
}

// LicenseConfig configures the license.
Expand Down Expand Up @@ -100,6 +102,7 @@ func NewRepository(meta *meta.Options) *Repository {
// AfterLoad maps back main branch override to meta.
func (r *Repository) AfterLoad() error {
r.meta.MainBranch = r.MainBranch
r.meta.SkipStaleWorkflow = r.SkipStaleWorkflow

return nil
}
Expand Down
3 changes: 3 additions & 0 deletions internal/project/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ type Options struct { //nolint:govet

// HelmChartDir is the path to helm chart directory.
HelmChartDir string

// SkipStaleWorkflow indicates that stale workflow should not be generated.
SkipStaleWorkflow bool
}

// Command defines Golang executable build configuration.
Expand Down