How cybrota/scharf works
Main Components
• CLI Frontend: The entry point of the application (main.go) handles command-line arguments, routing commands (such as “find” and “lookup”), and displaying outputs.
• Workflow Analyzer (Scanner Module): This is represented by scanner.go and its associated tests (scanner_test.go). Its role is to traverse directories (as provided by the “--root” flag) and parse GitHub workflow files to identify third-party actions.
• Resolver/Lookup Module: The resolver component (resolver.go with tests in resolver_test.go) is dedicated to determining the correct commit SHA for a given GitHub Action reference.
• Git Integration Module: The git.go (with git_test.go) likely interfaces with GitHub repositories or local Git data to verify or fetch commit information.
• Reporting Engine: Although implicit, this part of the system takes the output from scan and lookup operations and formats it into CSV, JSON, or Syslog reports for analysis.
• CI/CD Pipeline and Release Automation: The .github/workflows directory with YAML files (ci.yml, release.yml, security.yml), along with .goreleaser.yaml, indicate automated testing, building, and release processes.
• Installer Script: install.sh provides a user-friendly script for installing the binary on supported systems.
Relationships and Interactions
• Command invocations (find or lookup) are handled by the CLI frontend, which then delegates functionality:
– For “find” – it calls the Workflow Analyzer to scan file trees and parse workflow files.
– For “lookup” – it utilizes the Resolver to determine the appropriate commit SHA.
• The Git Integration Module is likely used by both the scanner and resolver components to interact with Git repositories or query remote GitHub APIs.
• The Reporting Engine takes processed data from either the scanning or lookup flows to generate the desired output formats.
• The CI/CD components (represented by the GitHub workflows) ensure that code quality and security checks are automated, and that releases are generated automatically via the release configuration.
Architectural Patterns/Design Principles
• Separation of Concerns: Each major functionality (“scanning”, “resolving”, and “reporting”) is handled in its own module, making the code modular and easier to maintain.
• Test-Driven Approach: Multiple test files (e.g., git_test.go, resolver_test.go, scanner_test.go) show that the project emphasizes unit testing and code robustness.
• CLI Design Pattern: The tool uses a common CLI pattern to parse and route commands along with command-specific options.
• Automation and Continuous Integration: CI/CD workflows and release automation reflect mature software development practices.
Relevant Technologies and Frameworks
• Go Language: The entire project is written in Go, leveraging its native binary compilation.
• GitHub Actions: Used in the project’s workflow files (.github/workflows) to manage CI/CD.
• goreleaser: As indicated by the .goreleaser.yaml, this tool is used for releasing the binary.
• Shell Scripting: The install.sh script provides an installation mechanism for end users on Linux and Mac OS.