Skip to content

refactor: extract inline bash into testable scripts with CI pipeline#132

Merged
0x46616c6b merged 6 commits intomainfrom
refactor/extract-scripts-and-tests
Apr 23, 2026
Merged

refactor: extract inline bash into testable scripts with CI pipeline#132
0x46616c6b merged 6 commits intomainfrom
refactor/extract-scripts-and-tests

Conversation

@0x46616c6b
Copy link
Copy Markdown
Contributor

Type of Change

  • Refactoring

Description

Extracts all inline bash logic from action.yml into separate, testable script files and adds a comprehensive test suite and CI pipeline. This improves maintainability, testability, and reliability without changing any external behavior.

Script extraction:
All inline bash from action.yml is moved into individual scripts under scripts/, each with a single responsibility. The action.yml shrinks from 464 to ~290 lines and becomes pure orchestration — referencing scripts via ${{ github.action_path }}/scripts/*.sh with inputs passed as environment variables.

GitHub Deployments via actions/github-script:
Replaces the manual curl + jq deployment creation with actions/github-script using Octokit. This provides automatic retry/rate-limiting, type-safe API access, and proper error handling without manual HTTP status parsing.

Deduplication and improvements:

  • 4x duplicated while IFS= read loops → single process_file_updates() function
  • push || push || pushretry_with_backoff 5 2 with exponential backoff
  • array=($line) (shellcheck SC2206) → read -r file field
  • Shared utility library: logging, retry, input validation, output helpers

Test suite (64 bats-core tests):
Covers tag generation (all branch/tag combinations), architecture validation, image retagging (with curl mocks), GitOps functions (update, commit, push, annotations), and the full update orchestrator.

CI pipeline:
New workflow with shellcheck linting, bats test execution, and action structure validation (verifies all referenced scripts exist and are executable).

Backward compatibility: All 29 inputs, 3 outputs, and existing step IDs (preparation, docker_build, docker_retag, update_image) remain unchanged. Consumers do not need to modify their workflows.

Checklist

  • Write tests
  • Make sure all tests pass
  • Update documentation
  • Review the Contributing Guideline and sign CLA
  • Reference relevant issue(s) and close them after merging

The changes and the PR were generated by Claude.

Extract all inline bash logic from action.yml into separate script files
under scripts/, add 64 bats-core tests, shellcheck linting, and a CI
workflow. Replace curl-based GitHub Deployment creation with
actions/github-script using Octokit for type safety and automatic
retry/rate-limiting.

Key changes:
- Extract tag generation, architecture verification, image retagging,
  and GitOps update logic into individual scripts
- Add shared utility library (logging, retry with backoff, validation)
- Deduplicate 4x identical file-update loops into process_file_updates()
- Replace manual curl+jq deployment creation with actions/github-script
- Improve git push retry: exponential backoff (5 attempts) instead of
  simple chaining (3 attempts)
- Fix shellcheck warnings (SC2206: array=($line) -> read -r)
- Add CI pipeline: shellcheck, bats tests, action structure validation

All inputs (29), outputs (3), and step IDs remain unchanged.
Consumers do not need to modify their workflows.

Co-Authored-By: Claude <claude@anthropic.com>
@0x46616c6b 0x46616c6b marked this pull request as ready for review April 22, 2026 17:26
@0x46616c6b 0x46616c6b requested review from a team as code owners April 22, 2026 17:26
Comment thread .github/workflows/ci.yml
Comment thread .github/workflows/ci.yml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you test the whole refactored implementation already in another repository? 🤔

Copy link
Copy Markdown
Contributor Author

@0x46616c6b 0x46616c6b Apr 23, 2026

Choose a reason for hiding this comment

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

The PR includes 64 unit tests that cover all extracted bash logic (tag generation, architecture validation, retagging, GitOps updates, deployment annotations). These validate the refactored scripts behave identically to the original inline bash.

I will test it today and report back.

Copy link
Copy Markdown
Contributor Author

@0x46616c6b 0x46616c6b Apr 23, 2026

0x46616c6b and others added 5 commits April 23, 2026 09:09
- Merge main to include PR #131 (deactivate stale deployments)
- Port deactivate_stale_deployments from bash/curl to Octokit in the
  actions/github-script step
- Add mise.toml with bats-core and shellcheck for local dev setup
- Update CI workflow to use jdx/mise-action

Co-Authored-By: Claude <claude@anthropic.com>
Replace manual npm/git-clone installation of bats and shellcheck
with jdx/mise-action, consistent with the local mise.toml setup.

Co-Authored-By: Claude <claude@anthropic.com>
Co-Authored-By: Claude <claude@anthropic.com>
Co-Authored-By: Claude <claude@anthropic.com>
Fixes Node.js 20 deprecation warning. Node.js 20 actions will be
forced to Node.js 24 starting June 2nd, 2026.

Co-Authored-By: Claude <claude@anthropic.com>
@0x46616c6b 0x46616c6b merged commit 18bc422 into main Apr 23, 2026
10 checks passed
@0x46616c6b 0x46616c6b deleted the refactor/extract-scripts-and-tests branch April 23, 2026 09:27
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants