Skip to content

Add GitHub Actions workflow for automated testing (#26) #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

mattfsourcecode
Copy link
Owner

@mattfsourcecode mattfsourcecode commented Feb 15, 2025

Validation Workflow: Reliable Testing for bootstrapper-script-generator

This pull request introduces an automated GitHub Actions workflow to validate the bootstrapper-script-generator CLI tool, ensuring that the bin command consistently produces valid results with each pull request. The workflow simulates a real-world use case by generating and testing bootstrap scripts based on the project's own structure.


Benefits

  • Automated Validation: Ensures the make-bootstrapper-script command produces functional and consistent output with every update.
  • Real-World Testing: Uses the actual project directory as input to reflect realistic scenarios.
  • Regression Prevention: Compares the output (test-output) with the source (test-source) to verify correctness.
  • Cross-Environment Consistency: Handles file format issues (e.g., line endings, blank lines) to avoid differences across local and CI environments.

How It Works

  1. Environment Setup:

    • Sets up Node.js 20 and pnpm to install dependencies.
    • Builds the project using the pnpm build command.
  2. Input Example:

    • Copies the project directory to test-source, excluding unnecessary files (node_modules, .git, etc.).
    • Normalizes file formats to ensure compatibility across environments.
  3. Installing the CLI:

    • npm pack: Packages the project as a .tgz file, simulating a published version of the CLI.
    • npm install -g: Installs the packaged .tgz globally to test the bin command (make-bootstrapper-script).
  4. Script Generation and Execution:

    • Generates a bootstrap script using the globally installed make-bootstrapper-script command, targeting the test-source directory.
    • Executes the generated script, creating the test-output directory.
  5. Validation:

    • Compares test-source and test-output using diff, checking for inconsistencies in structure and content.
    • Normalizes files by removing trailing spaces and ensuring consistent line endings to prevent false-positive differences.
  6. Debugging:

    • If differences are detected, logs detailed information about mismatched files, including their hex dumps, for fast troubleshooting.

Key Features

  • Real-World Input: The workflow uses the project itself as input for the bootstrap script, ensuring the generator works as expected with real examples.
  • Global Installation Test: By simulating a production installation (npm install -g), the workflow validates the usability of the published package.
  • Comprehensive Comparison: Verifies the generated output is an exact match of the input directory structure and content.

Testing Details

  1. Input and Output Comparison:

    • Uses rsync to prepare test-source as the input directory.
    • Runs diff to validate the generated test-output.
  2. File Normalization:

    • Removes trailing spaces and blank lines from all files to eliminate discrepancies due to formatting.
  3. Debugging Differences:

    • Logs mismatched files and their hex dumps, enabling precise debugging of content-level issues.

This setup supports a process where a version bump is the last change merged before the updated version is published to npm. This final step adds an additional layer of validation to ensure that the npm package, including any version updates, functions correctly. By testing the package’s functionality in the CI/CD pipeline, it confirms the integrity of the package and verifies that it works as intended before being made publicly available.

Closes #26

@mattfsourcecode mattfsourcecode force-pushed the add-github-actions-workflow-to-test-npm-package branch 30 times, most recently from 658e0d3 to 1621a58 Compare February 15, 2025 03:48
@mattfsourcecode mattfsourcecode force-pushed the add-github-actions-workflow-to-test-npm-package branch 10 times, most recently from 02de4d5 to 240d4ed Compare February 15, 2025 04:12
@mattfsourcecode mattfsourcecode force-pushed the add-github-actions-workflow-to-test-npm-package branch from 240d4ed to 2159a2d Compare February 15, 2025 04:16
@mattfsourcecode mattfsourcecode changed the title WIP: Add GitHub Actions workflow for automated testing Add GitHub Actions workflow for automated testing Feb 15, 2025
@mattfsourcecode mattfsourcecode marked this pull request as ready for review February 15, 2025 04:19
@mattfsourcecode mattfsourcecode changed the title Add GitHub Actions workflow for automated testing Add GitHub Actions workflow for automated testing (#26) Feb 15, 2025
@mattfsourcecode mattfsourcecode merged commit 8a750e8 into master Feb 15, 2025
1 check passed
@mattfsourcecode mattfsourcecode deleted the add-github-actions-workflow-to-test-npm-package branch February 15, 2025 04:30
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.

Add a GitHub Actions workflow for automated testing of the installed npm package
1 participant