diff --git a/.github/workflows/agentics-maintenance.yml b/.github/workflows/agentics-maintenance.yml index 226acf666f4..95c05e7fd29 100644 --- a/.github/workflows/agentics-maintenance.yml +++ b/.github/workflows/agentics-maintenance.yml @@ -350,8 +350,9 @@ jobs: - name: Build gh-aw run: make build - - name: Cache activity report logs - uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + - name: Restore activity report logs cache + id: activity_report_logs_cache + uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: path: ./.cache/gh-aw/activity-report-logs key: ${{ runner.os }}-activity-report-logs-${{ github.repository }}-${{ github.ref_name }}-${{ github.run_id }} @@ -372,6 +373,13 @@ jobs: const { main } = require('${{ runner.temp }}/gh-aw/actions/run_activity_report.cjs'); await main(); + - name: Save activity report logs cache + if: ${{ always() }} + uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: ./.cache/gh-aw/activity-report-logs + key: ${{ steps.activity_report_logs_cache.outputs.cache-primary-key }} + close_agentic_workflows_issues: if: ${{ (github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call') && inputs.operation == 'close_agentic_workflows_issues' && (!(github.event.repository.fork)) }} runs-on: ubuntu-slim diff --git a/pkg/workflow/maintenance_workflow_test.go b/pkg/workflow/maintenance_workflow_test.go index a8174de8eb0..0ec6a3cb3ca 100644 --- a/pkg/workflow/maintenance_workflow_test.go +++ b/pkg/workflow/maintenance_workflow_test.go @@ -384,8 +384,17 @@ func TestGenerateMaintenanceWorkflow_OperationJobConditions(t *testing.T) { t.Errorf("Job activity_report should set timeout-minutes: 120 in:\n%s", activityReportSection) } } - if !strings.Contains(yaml, "Cache activity report logs") { - t.Errorf("Job activity_report should include a cache step in:\n%s", yaml) + if !strings.Contains(yaml, "Restore activity report logs cache") { + t.Errorf("Job activity_report should include a cache restore step in:\n%s", yaml) + } + if !strings.Contains(yaml, "Save activity report logs cache") { + t.Errorf("Job activity_report should include a cache save step in:\n%s", yaml) + } + if !strings.Contains(yaml, "if: ${{ always() }}") { + t.Errorf("Job activity_report should save cache even when earlier steps fail in:\n%s", yaml) + } + if !strings.Contains(yaml, "steps.activity_report_logs_cache.outputs.cache-primary-key") { + t.Errorf("Job activity_report cache save step should use cache primary key output in:\n%s", yaml) } if !strings.Contains(yaml, "${{ github.run_id }}") { t.Errorf("Job activity_report cache key should include run_id for latest-cache resolution in:\n%s", yaml) diff --git a/pkg/workflow/maintenance_workflow_yaml.go b/pkg/workflow/maintenance_workflow_yaml.go index 91a701fb911..dd55cc3ffec 100644 --- a/pkg/workflow/maintenance_workflow_yaml.go +++ b/pkg/workflow/maintenance_workflow_yaml.go @@ -384,8 +384,9 @@ jobs: `) yaml.WriteString(generateInstallCLISteps(actionMode, version, actionTag, resolver)) - yaml.WriteString(` - name: Cache activity report logs - uses: ` + getActionPin("actions/cache") + ` + yaml.WriteString(` - name: Restore activity report logs cache + id: activity_report_logs_cache + uses: ` + getActionPin("actions/cache/restore") + ` with: path: ./.cache/gh-aw/activity-report-logs key: ${{ runner.os }}-activity-report-logs-${{ github.repository }}-${{ github.ref_name }}-${{ github.run_id }} @@ -406,6 +407,13 @@ jobs: setupGlobals(core, github, context, exec, io, getOctokit); const { main } = require('${{ runner.temp }}/gh-aw/actions/run_activity_report.cjs'); await main(); + + - name: Save activity report logs cache + if: ${{ always() }} + uses: ` + getActionPin("actions/cache/save") + ` + with: + path: ./.cache/gh-aw/activity-report-logs + key: ${{ steps.activity_report_logs_cache.outputs.cache-primary-key }} `) // Add close_agentic_workflows_issues job for workflow_dispatch with operation == 'close_agentic_workflows_issues' diff --git a/pkg/workflow/side_repo_maintenance.go b/pkg/workflow/side_repo_maintenance.go index a490ee7a171..add1c5d87e5 100644 --- a/pkg/workflow/side_repo_maintenance.go +++ b/pkg/workflow/side_repo_maintenance.go @@ -459,8 +459,9 @@ jobs: `) yaml.WriteString(generateInstallCLISteps(actionMode, version, actionTag, resolver)) - yaml.WriteString(` - name: Cache activity report logs - uses: ` + getActionPin("actions/cache") + ` + yaml.WriteString(` - name: Restore activity report logs cache + id: activity_report_logs_cache + uses: ` + getActionPin("actions/cache/restore") + ` with: path: ./.cache/gh-aw/activity-report-logs key: ${{ runner.os }}-activity-report-logs-` + repoSlug + `-${{ github.ref_name }}-${{ github.run_id }} @@ -482,6 +483,13 @@ jobs: setupGlobals(core, github, context, exec, io, getOctokit); const { main } = require('${{ runner.temp }}/gh-aw/actions/run_activity_report.cjs'); await main(); + + - name: Save activity report logs cache + if: ${{ always() }} + uses: ` + getActionPin("actions/cache/save") + ` + with: + path: ./.cache/gh-aw/activity-report-logs + key: ${{ steps.activity_report_logs_cache.outputs.cache-primary-key }} `) // Add validate_workflows job for workflow_dispatch/workflow_call with operation == 'validate' diff --git a/pkg/workflow/side_repo_maintenance_integration_test.go b/pkg/workflow/side_repo_maintenance_integration_test.go index 9cdfcb3cec6..fe9ff6905fe 100644 --- a/pkg/workflow/side_repo_maintenance_integration_test.go +++ b/pkg/workflow/side_repo_maintenance_integration_test.go @@ -90,8 +90,14 @@ This workflow operates on a separate repository. // Must have activity_report job. assert.Contains(t, contentStr, "activity_report:", "generated workflow should include activity_report job") - assert.Contains(t, contentStr, "Cache activity report logs", - "generated workflow should include cache step for activity_report logs") + assert.Contains(t, contentStr, "Restore activity report logs cache", + "generated workflow should include cache restore step for activity_report logs") + assert.Contains(t, contentStr, "Save activity report logs cache", + "generated workflow should include cache save step for activity_report logs") + assert.Contains(t, contentStr, "if: ${{ always() }}", + "generated workflow should save activity_report logs cache even if report generation fails") + assert.Contains(t, contentStr, "steps.activity_report_logs_cache.outputs.cache-primary-key", + "generated workflow should save activity_report logs using the cache primary key") assert.Contains(t, contentStr, "GH_AW_ACTIVITY_REPORT_OUTPUT_DIR: ./.cache/gh-aw/activity-report-logs", "generated workflow should set GH_AW_ACTIVITY_REPORT_OUTPUT_DIR for activity_report logs") assert.Contains(t, contentStr, "actions: read\n contents: read\n issues: write",