Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 1, 2025

Converting "check workflow timestamp" to JavaScript

This PR converts the inline bash script for checking workflow file timestamps into a dedicated JavaScript file, following the pattern established by other safety checks like check_stop_time.cjs.

Summary

This change improves code consistency and maintainability by:

  • Extracting inline bash script into a dedicated JavaScript file
  • Following the same pattern as other safety checks (check_stop_time, check_membership, check_command_position)
  • Adding comprehensive test coverage for the JavaScript implementation
  • Enabling independent testing of the timestamp check logic

Plan

  • Analyze the current inline bash implementation
  • Identify the JavaScript file pattern to follow
  • Create check_workflow_timestamp.cjs JavaScript file
  • Add embedded resource directive to js.go
  • Update compiler_jobs.go to use the JavaScript script
  • Add comprehensive tests for the new JavaScript file
  • Add Go test to verify compiled workflow uses JavaScript
  • Fix test import issue
  • Create test workflow for manual verification
  • Move test workflow to correct directory
  • Verify build, tests, and compilation work correctly

Benefits

  • Consistency: Aligns with the existing pattern used for other checks (stop-time, membership, command position)
  • Testability: JavaScript can be tested independently with proper test coverage (11 test cases)
  • Maintainability: Centralizes workflow timestamp logic in a dedicated file
  • Error handling: Provides better structured error messages through core.setFailed()
  • Cross-platform: JavaScript fs module is more portable than bash -nt operator

Implementation Details

The JavaScript implementation:

  1. Uses Node.js fs module to check file existence and get modification times
  2. Compares timestamps using mtime.getTime() for precise comparison
  3. Outputs warnings via core.error() and adds to step summary via core.summary
  4. Gracefully handles missing files without failing the workflow
  5. Uses actions/github-script@v8 action instead of inline bash

Changes

  • Created: pkg/workflow/js/check_workflow_timestamp.cjs - JavaScript implementation using Node.js fs module
  • Created: pkg/workflow/js/check_workflow_timestamp.test.cjs - Comprehensive JavaScript test suite (11 test cases)
  • Created: pkg/workflow/check_workflow_timestamp_js_test.go - Go test to verify compilation output
  • Created: pkg/cli/workflows/test-timestamp-js.md - Test workflow in correct location
  • Modified: pkg/workflow/js.go - Added embed directive for new script
  • Modified: pkg/workflow/compiler_jobs.go - Replaced 15 lines of inline bash with 7 lines calling JavaScript
  • Modified: .gitignore - Added entries to prevent tracking test files in .github/workflows

Test Coverage

JavaScript tests cover:

  • Missing environment variables (GITHUB_WORKSPACE, GITHUB_WORKFLOW)
  • Missing files (source only, lock only, both missing)
  • Lock file up to date scenarios
  • Lock file outdated scenarios
  • Different workflow naming patterns (hyphens, underscores)
  • Step summary generation
  • Error message formatting

Go tests verify:

  • Compiled workflow contains "Check workflow file timestamps" step
  • Step uses actions/github-script@ instead of run: |
  • JavaScript references GITHUB_WORKSPACE and GITHUB_WORKFLOW
  • No inline bash variable assignments present
Original prompt

Convert "check workflow timestamp" to JavaScript.

Note

Custom agent used: shell-2-script
Extract inline bash scripts from Go compiler code into separate .sh files with embedded resources for improved maintainability, organization, and reusability


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Nov 1, 2025
Copilot AI and others added 4 commits November 1, 2025 16:12
- Created check_workflow_timestamp.cjs with fs-based timestamp comparison
- Added embedded resource directive to js.go
- Updated compiler_jobs.go to use JavaScript instead of inline bash
- Added comprehensive test suite with vitest

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Convert check workflow timestamp to JavaScript Convert workflow timestamp check from bash to JavaScript Nov 1, 2025
Copilot AI requested a review from pelikhan November 1, 2025 16:17
@@ -0,0 +1,9 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot move to folder with other test workflows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved test workflow to pkg/cli/workflows/ directory in commit 250d1df.

@pelikhan pelikhan marked this pull request as ready for review November 1, 2025 16:22
Copilot AI review requested due to automatic review settings November 1, 2025 16:22
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 from inline bash script to a dedicated JavaScript implementation that runs via actions/github-script. The change improves testability, maintainability, and consistency with other GitHub Actions scripts in the codebase.

Key changes:

  • Replaced inline bash timestamp check with JavaScript implementation
  • Added comprehensive unit tests for the timestamp check logic
  • Added Go integration test to verify the JavaScript is properly embedded in compiled workflows

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/workflow/js/check_workflow_timestamp.cjs New JavaScript implementation of workflow timestamp checking logic
pkg/workflow/js/check_workflow_timestamp.test.cjs Comprehensive test suite for the timestamp check script
pkg/workflow/js.go Added embed directive to include the new timestamp check script
pkg/workflow/compiler_jobs.go Replaced inline bash with JavaScript script via actions/github-script
pkg/workflow/check_workflow_timestamp_js_test.go Go integration test verifying JavaScript embedding
.github/workflows/test-timestamp-js.md Test workflow file for manual verification

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

Comment on lines +1 to +4
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import fs from "fs";
import path from "path";
import os from "os";
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

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

Test files using CommonJS (.cjs extension) should use require() instead of ES6 import syntax. While Vitest supports ES6 imports in .cjs files, using require() is more consistent with the CommonJS module system. All the script being tested (check_workflow_timestamp.cjs) uses require(), so the test should match this pattern for consistency.

Suggested change
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import fs from "fs";
import path from "path";
import os from "os";
const { describe, it, expect, beforeEach, afterEach, vi } = require("vitest");
const fs = require("fs");
const path = require("path");
const os = require("os");

Copilot uses AI. Check for mistakes.
Moved test-timestamp-js.md from .github/workflows/ to pkg/cli/workflows/
to align with other test workflows. Added .gitignore entries to prevent
the .github/workflows version from being tracked.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan November 1, 2025 16:28
@pelikhan pelikhan merged commit acf7b98 into main Nov 1, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/convert-workflow-timestamp-js branch November 1, 2025 16:38
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