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
18 changes: 9 additions & 9 deletions .github/workflows/agentics-maintenance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ on:
description: 'Optional maintenance operation to run'
required: false
type: choice
default: ''
default: 'none'
options:
- ''
- 'none'
- 'disable'
- 'enable'
- 'update'
Expand Down Expand Up @@ -95,7 +95,7 @@ permissions: {}

jobs:
close-expired-discussions:
if: ${{ (!(github.event.repository.fork)) && github.event_name != 'push' && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '') }}
if: ${{ (!(github.event.repository.fork)) && github.event_name != 'push' && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '' || inputs.operation == 'none') }}
runs-on: ubuntu-slim
permissions:
discussions: write
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
const { main } = require(path.join(actionsDir, 'close_expired_discussions.cjs'));
await main();
close-expired-issues:
if: ${{ (!(github.event.repository.fork)) && github.event_name != 'push' && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '') }}
if: ${{ (!(github.event.repository.fork)) && github.event_name != 'push' && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '' || inputs.operation == 'none') }}
runs-on: ubuntu-slim
permissions:
issues: write
Expand Down Expand Up @@ -153,7 +153,7 @@ jobs:
const { main } = require(path.join(actionsDir, 'close_expired_issues.cjs'));
await main();
close-expired-pull-requests:
if: ${{ (!(github.event.repository.fork)) && github.event_name != 'push' && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '') }}
if: ${{ (!(github.event.repository.fork)) && github.event_name != 'push' && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '' || inputs.operation == 'none') }}
runs-on: ubuntu-slim
permissions:
pull-requests: write
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
await main();

cleanup-cache-memory:
if: ${{ (!(github.event.repository.fork)) && github.event_name != 'push' && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '' || inputs.operation == 'clean_cache_memories') }}
if: ${{ (!(github.event.repository.fork)) && github.event_name != 'push' && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '' || inputs.operation == 'none' || inputs.operation == 'clean_cache_memories') }}
runs-on: ubuntu-slim
permissions:
actions: write
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
await main();

run_operation:
if: ${{ (github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call') && inputs.operation != '' && inputs.operation != 'safe_outputs' && inputs.operation != 'create_labels' && inputs.operation != 'activity_report' && inputs.operation != 'close_agentic_workflows_issues' && inputs.operation != 'clean_cache_memories' && inputs.operation != 'update_pull_request_branches' && inputs.operation != 'validate' && inputs.operation != 'forecast' && (!(github.event.repository.fork)) }}
if: ${{ (github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call') && inputs.operation != '' && inputs.operation != 'none' && inputs.operation != 'safe_outputs' && inputs.operation != 'create_labels' && inputs.operation != 'activity_report' && inputs.operation != 'close_agentic_workflows_issues' && inputs.operation != 'clean_cache_memories' && inputs.operation != 'update_pull_request_branches' && inputs.operation != 'validate' && inputs.operation != 'forecast' && (!(github.event.repository.fork)) }}
runs-on: ubuntu-slim
permissions:
actions: write
Expand Down Expand Up @@ -844,7 +844,7 @@ jobs:
await main();

compile-workflows:
if: ${{ (!(github.event.repository.fork)) && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '') }}
if: ${{ (!(github.event.repository.fork)) && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '' || inputs.operation == 'none') }}
runs-on: ubuntu-slim
concurrency:
group: ${{ github.workflow }}-compile-workflows-${{ github.repository }}
Expand Down Expand Up @@ -894,7 +894,7 @@ jobs:
await main();

secret-validation:
if: ${{ (!(github.event.repository.fork)) && github.event_name != 'push' && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '') }}
if: ${{ (!(github.event.repository.fork)) && github.event_name != 'push' && (github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '' || inputs.operation == 'none') }}
runs-on: ubuntu-slim
permissions:
contents: read
Expand Down
55 changes: 47 additions & 8 deletions pkg/workflow/maintenance_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,51 @@ import "github.com/github/gh-aw/pkg/logger"

var maintenanceConditionsLog = logger.New("workflow:maintenance_conditions")

// maintenanceNoOperationValue is the sentinel value used for the workflow_dispatch
// "operation" choice input to represent "no operation selected". It replaces an
// empty string option, since actionlint rejects empty strings as workflow_dispatch
// choice options and requires the default to be one of the declared options.
// The workflow_call "operation" input remains a plain string with an empty-string
// default (not subject to the choice/options restriction), so the empty value and
// this sentinel value are treated as "no operation" throughout the generated conditions.
const maintenanceNoOperationValue = "none"

// buildOperationIsEmptyCondition creates a condition that is true when the
// `inputs.operation` value represents "no operation selected", i.e. it is
// either an empty string (workflow_call default) or the choice sentinel value
// used by the workflow_dispatch "operation" input.
func buildOperationIsEmptyCondition() ConditionNode {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkg/workflow/maintenance_conditions.go:16-50: yagni: two tiny helpers for one extra / branch. Inline the comparisons directly at the call sites.

return BuildOr(
BuildEquals(
BuildPropertyAccess("inputs.operation"),
BuildStringLiteral(""),
),
BuildEquals(
BuildPropertyAccess("inputs.operation"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] The two new helpers buildOperationIsEmptyCondition and buildOperationIsNotEmptyCondition have no direct unit tests. Coverage currently comes only from the integration-style string-match tests in maintenance_workflow_jobs_test.go, which means a logic error inside either helper (e.g. swapping BuildOr for BuildAnd) would produce a wrong condition string that the existing tests would catch only incidentally.

💡 Suggested test

Add a small table-driven test in maintenance_conditions_test.go (or equivalent):

func TestBuildOperationIsEmptyCondition(t *testing.T) {
    node := buildOperationIsEmptyCondition()
    got := renderCondition(node) // use whatever renderer is available
    want := `inputs.operation == '' || inputs.operation == 'none'`
    require.Equal(t, want, got)
}

func TestBuildOperationIsNotEmptyCondition(t *testing.T) {
    node := buildOperationIsNotEmptyCondition()
    got := renderCondition(node)
    want := `inputs.operation != '' && inputs.operation != 'none'`
    require.Equal(t, want, got)
}

This gives a regression anchor directly on the helpers and documents their intended output as a specification.

@copilot please address this.

BuildStringLiteral(maintenanceNoOperationValue),
),
)
}

// buildOperationIsNotEmptyCondition creates a condition that is true when the
// `inputs.operation` value represents an operation being selected, i.e. it is
// neither the empty string (workflow_call default) nor the choice sentinel
// value used by the workflow_dispatch "operation" input. Built directly from
// BuildNotEquals (rather than negating buildOperationIsEmptyCondition) so it
// renders using the same `!=` style as the other operation exclusion checks.
func buildOperationIsNotEmptyCondition() ConditionNode {
return BuildAnd(
BuildNotEquals(
BuildPropertyAccess("inputs.operation"),
BuildStringLiteral(""),
),
BuildNotEquals(
BuildPropertyAccess("inputs.operation"),
BuildStringLiteral(maintenanceNoOperationValue),
),
)
}

// buildNotForkCondition creates a condition to check the repository is not a fork.
func buildNotForkCondition() ConditionNode {
return &NotNode{
Expand All @@ -26,10 +71,7 @@ func buildNotDispatchOrCallOrEmptyOperation() ConditionNode {
BuildStringLiteral("workflow_call"),
),
),
BuildEquals(
BuildPropertyAccess("inputs.operation"),
BuildStringLiteral(""),
),
buildOperationIsEmptyCondition(),
)
}

Expand Down Expand Up @@ -145,10 +187,7 @@ func buildRunOperationCondition(excludedOperations ...string) ConditionNode {
BuildEventTypeEquals("workflow_dispatch"),
BuildEventTypeEquals("workflow_call"),
),
BuildNotEquals(
BuildPropertyAccess("inputs.operation"),
BuildStringLiteral(""),
),
buildOperationIsNotEmptyCondition(),
)

// Exclude each dedicated operation
Expand Down
10 changes: 5 additions & 5 deletions pkg/workflow/maintenance_workflow_jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,18 @@ func TestGenerateMaintenanceWorkflow_OperationJobConditions(t *testing.T) {
require.Contains(t, yaml, `{"maintenance": false}`)
require.Contains(t, yaml, "https://github.github.com/gh-aw/reference/ephemerals/#manual-maintenance-operations")

operationSkipCondition := `github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == ''`
operationRunCondition := `(github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call') && inputs.operation != '' && inputs.operation != 'safe_outputs' && inputs.operation != 'create_labels' && inputs.operation != 'activity_report' && inputs.operation != 'close_agentic_workflows_issues' && inputs.operation != 'clean_cache_memories' && inputs.operation != 'update_pull_request_branches' && inputs.operation != 'validate' && inputs.operation != 'forecast'`
operationSkipCondition := `github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '' || inputs.operation == 'none'`
operationRunCondition := `(github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call') && inputs.operation != '' && inputs.operation != 'none' && inputs.operation != 'safe_outputs' && inputs.operation != 'create_labels' && inputs.operation != 'activity_report' && inputs.operation != 'close_agentic_workflows_issues' && inputs.operation != 'clean_cache_memories' && inputs.operation != 'update_pull_request_branches' && inputs.operation != 'validate' && inputs.operation != 'forecast'`
applySafeOutputsCondition := `(github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call') && inputs.operation == 'safe_outputs'`
createLabelsCondition := `(github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call') && inputs.operation == 'create_labels'`
updatePullRequestBranchesCondition := `(github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call') && inputs.operation == 'update_pull_request_branches'`
activityReportCondition := `(github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call') && inputs.operation == 'activity_report'`
forecastCondition := `(github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call') && inputs.operation == 'forecast'`
closeAgenticWorkflowIssuesCondition := `(github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call') && inputs.operation == 'close_agentic_workflows_issues'`
cleanCacheMemoriesCondition := `github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '' || inputs.operation == 'clean_cache_memories'`
cleanCacheMemoriesCondition := `github.event_name != 'workflow_dispatch' && github.event_name != 'workflow_call' || inputs.operation == '' || inputs.operation == 'none' || inputs.operation == 'clean_cache_memories'`

const jobSectionSearchRange = 300
const runOpSectionSearchRange = 500
const jobSectionSearchRange = 350
const runOpSectionSearchRange = 550

// Jobs that should be disabled when any non-dedicated operation is set (cleanup-cache-memory has its own dedicated operation)
disabledJobs := []string{
Expand Down
8 changes: 4 additions & 4 deletions pkg/workflow/maintenance_workflow_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ func buildMaintenanceWorkflowTriggerYAML(

// buildMaintenanceDispatchInputsYAML returns the workflow_dispatch trigger block.
func buildMaintenanceDispatchInputsYAML() string {
return ` workflow_dispatch:
return fmt.Sprintf(` workflow_dispatch:
inputs:
operation:
description: 'Optional maintenance operation to run'
required: false
type: choice
default: ''
default: '%[1]s'
options:
- ''
- '%[1]s'
- 'disable'
- 'enable'
- 'update'
Expand All @@ -146,7 +146,7 @@ func buildMaintenanceDispatchInputsYAML() string {
required: false
type: string
default: ''
`
`, maintenanceNoOperationValue)
}

// buildMaintenanceWorkflowCallYAML returns the workflow_call trigger block.
Expand Down
4 changes: 2 additions & 2 deletions pkg/workflow/side_repo_maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ on:
description: 'Optional maintenance operation to run'
required: false
type: choice

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/diagnosing-bugs] String concatenation here is inconsistent with maintenance_workflow_yaml.go, which uses fmt.Sprintf + %[1]s for the same substitution. A future rename of maintenanceNoOperationValue could silently miss this spot.

💡 Suggested change

Adopt the same fmt.Sprintf pattern used in maintenance_workflow_yaml.go:

return fmt.Sprintf(`  workflow_dispatch:
    inputs:
      operation:
        ...
        default: '%[1]s'
        options:
          - '%[1]s'
`, maintenanceNoOperationValue)

This keeps the two YAML-building functions consistent and makes the substitution explicit.

@copilot please address this.

default: ''
default: '` + maintenanceNoOperationValue + `'
options:
- ''
- '` + maintenanceNoOperationValue + `'
- 'safe_outputs'
- 'create_labels'
- 'activity_report'
Expand Down
Loading