Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 2, 2025

Add shallow git checkout step in activation job to enable lock file timestamp check

Problem

The activation job includes a timestamp check that compares the source .md workflow file against the compiled .lock.yml file. However, there were two issues:

  1. The activation job didn't checkout the repository, so the files didn't exist in the workspace
  2. The JavaScript was using GITHUB_WORKFLOW (workflow name) instead of the actual filename

Solution

  • Add a shallow checkout step in the activation job before the timestamp check
  • Only checkout the .github/workflows directory (sparse checkout)
  • Use depth: 1 for shallow clone to minimize checkout time
  • Add persist-credentials: false for security
  • Use sparse-checkout-cone-mode: false for non-cone pattern support
  • Pass lock filename as GH_AW_WORKFLOW_FILE environment variable
  • Update JavaScript to use GH_AW_WORKFLOW_FILE instead of GITHUB_WORKFLOW
  • Add quotes around filename to handle special characters in YAML
  • Update tests to verify the checkout step is present in compiled workflows
  • Update existing tests to be more specific about which job they check
  • Add new test TestActivationJobCheckoutStep to verify activation checkout
  • Run existing tests to ensure no regressions
  • Recompile example workflows to verify changes

Changes Made

  1. Modified pkg/workflow/compiler_jobs.go:
    • Added checkout step in buildActivationJob() function
    • Extract lock filename and pass to buildActivationJob
    • Add GH_AW_WORKFLOW_FILE environment variable with quoted value
  2. Modified pkg/workflow/js/check_workflow_timestamp.cjs:
    • Changed to use GH_AW_WORKFLOW_FILE instead of GITHUB_WORKFLOW
    • Updated variable names for clarity (workflowMdFile instead of workflowFile)
  3. Modified pkg/workflow/js/check_workflow_timestamp.test.cjs:
    • Updated all tests to use GH_AW_WORKFLOW_FILE environment variable
  4. Updated test assertions:
    • checkout_optimization_test.go: Check for checkout in agent job specifically
    • task_and_reaction_permissions_test.go: Expect checkout in activation job
    • trial_mode_test.go: Look for token in agent job checkout
  5. Added pkg/workflow/activation_checkout_test.go: New test to verify activation checkout behavior

Testing

  • All unit tests pass
  • JavaScript tests pass
  • All 67 workflows recompile successfully
  • Manual verification of compiled workflow output

Example Output

The activation job now includes:

activation:
  runs-on: ubuntu-slim
  steps:
    - name: Checkout workflows
      uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
      with:
        sparse-checkout: |
          .github/workflows
        sparse-checkout-cone-mode: false
        fetch-depth: 1
        persist-credentials: false
    - name: Check workflow file timestamps
      uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
      env:
        GH_AW_WORKFLOW_FILE: "dev.lock.yml"
      with:
        script: |
          # ... timestamp check script using GH_AW_WORKFLOW_FILE
Original prompt

Add shallow git checkout step in activation job to enable lock file timestamp check

Only checkout actions workflow folder


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Added sparse checkout of .github/workflows in activation job
- Uses fetch-depth: 1 for shallow clone to minimize performance impact
- Uses sparse-checkout-cone-mode: false for non-cone pattern support
- Sets persist-credentials: false for security
- Updated tests to check for checkout in agent job specifically
- Added new test TestActivationJobCheckoutStep to verify activation checkout
- Updated TestActivationAndAddReactionJobsPermissions to expect checkout in activation job
- Updated TestTrialModeCompilation to look for checkout in agent job

Co-authored-by: pelikhan <[email protected]>
Copilot AI changed the title [WIP] Add shallow git checkout step in activation job Add shallow checkout to activation job for timestamp verification Nov 2, 2025
Copilot AI requested a review from pelikhan November 2, 2025 22:43
Copilot finished work on behalf of pelikhan November 2, 2025 22:43
@pelikhan
Copy link
Contributor

pelikhan commented Nov 2, 2025

@copilot the check time JavaScript is trying to read the wrong file... it seems that it is using the workflow name instead of the actual workflow file.

See action run logs at https://github.com/githubnext/gh-aw/actions/runs/19019309841/job/54311838605#step:3:1

The check_workflow_timestamp.cjs script was using GITHUB_WORKFLOW which contains
the workflow name (e.g., "Dev") instead of the workflow filename. This caused
it to try reading the wrong file.

Fixed by:
- Adding lockFilename parameter to buildActivationJob()
- Passing the lock filename as GH_AW_WORKFLOW_FILE environment variable
- Updated JavaScript to use GH_AW_WORKFLOW_FILE instead of GITHUB_WORKFLOW
- Added quotes around the filename value to handle special characters
- Updated tests to use the new environment variable

Co-authored-by: pelikhan <[email protected]>
Copy link
Contributor Author

Copilot AI commented Nov 2, 2025

@copilot the check time JavaScript is trying to read the wrong file... it seems that it is using the workflow name instead of the actual workflow file.

See action run logs at https://github.com/githu...

Fixed in a63e44b. The script was using GITHUB_WORKFLOW which contains the workflow name (e.g., "Dev") instead of the filename. Now it uses GH_AW_WORKFLOW_FILE environment variable which is set to the actual lock filename (e.g., "dev.lock.yml").

Copilot finished work on behalf of pelikhan November 2, 2025 23:13
@pelikhan pelikhan marked this pull request as ready for review November 2, 2025 23:19
Copilot AI review requested due to automatic review settings November 2, 2025 23:19
@pelikhan pelikhan enabled auto-merge (squash) November 2, 2025 23:19
@pelikhan pelikhan merged commit 1c80b2d into main Nov 2, 2025
42 of 45 checks passed
@pelikhan pelikhan deleted the copilot/add-shallow-checkout-activation-job branch November 2, 2025 23:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the workflow timestamp check mechanism to use a custom environment variable (GH_AW_WORKFLOW_FILE) instead of the GitHub-provided GITHUB_WORKFLOW variable, and adds a sparse checkout step to the activation job for retrieving workflow files needed for timestamp validation.

Key changes:

  • Replaced GITHUB_WORKFLOW environment variable with custom GH_AW_WORKFLOW_FILE
  • Renamed internal workflowFile variable to workflowMdFile to avoid naming conflicts
  • Added sparse checkout of .github/workflows directory to activation jobs
  • Updated all test files to use the new environment variable name

Reviewed Changes

Copilot reviewed 73 out of 73 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/workflow/compiler_jobs.go Passes lock filename to activation job builder and adds sparse checkout step with environment variable
pkg/workflow/js/check_workflow_timestamp.cjs Refactors to use GH_AW_WORKFLOW_FILE and renames variables to avoid conflicts
pkg/workflow/js/check_workflow_timestamp.test.cjs Updates all test cases to use new environment variable
pkg/workflow/task_and_reaction_permissions_test.go Updates test expectations to verify checkout step exists in activation job
pkg/workflow/trial_mode_test.go Refactors to check for checkout step only within agent job scope
pkg/workflow/checkout_optimization_test.go Extracts agent job section before checking for checkout presence
pkg/workflow/activation_checkout_test.go New test file validating activation job checkout configuration
*.lock.yml files Regenerated workflow files with new checkout step and environment variable

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

github-actions bot added a commit that referenced this pull request Nov 3, 2025
Synchronized instructions file with documentation changes from the new docs structure added in commit 1c80b2d.

### Changes Made

- Added new frontmatter fields: description, source, github-token, roles, strict, features, environment, container, services
- Added reaction and manual-approval fields to on: trigger configuration
- Added engine.env, engine.args, and engine.error_patterns configuration options
- Updated network permissions to include firewall configuration for Copilot engine (AWF support)
- Added search toolset to GitHub tools documentation
- Added recommendation to prefer toolset over allowed for GitHub tools configuration
- Updated engine network permissions section to reflect multi-engine support and AWF

### Documentation Commits Reviewed

- 1c80b2d Add shallow checkout to activation job for timestamp verification (#3013)

### Validation

- Followed prompting best practices (imperative mood, minimal examples)
- Maintained technical tone and brevity
- Updated only necessary sections
- Verified accuracy against current documentation
- Removed outdated content where applicable

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants