Skip to content

feat: add GitHub Actions workflow for automatic version bumping #137

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DevelopmentCats
Copy link
Contributor

Version Bump Workflow

Automates module version bumping when PR labels are applied.

Usage

Add one of these labels to a PR:

  • version:patch - Bug fixes (1.2.3 → 1.2.4)
  • version:minor - New features (1.2.3 → 1.3.0)
  • version:major - Breaking changes (1.2.3 → 2.0.0)

What it does

  1. Detects modified modules from PR changes
  2. Gets current version from latest release tag or README
  3. Calculates new version based on label
  4. Updates README versions in module documentation
  5. Commits changes to the PR
  6. Comments summary on the PR

Example

If a PR modifies registry/coder/git-clone/ and has label version:patch:

Current: release/coder/git-clone/v1.0.18
New: v1.0.19
Updates: All versions for git-clone module = "1.0.19" in README

Version Detection

  • Tagged modules: Uses latest release/namespace/module/vX.Y.Z tag
  • Untagged modules: Extracts version from README version = "X.Y.Z"
  • New modules: Start from v1.0.0

Notes

  • Only updates READMEs that contain version references
  • Warns about modules missing proper git tags
  • Requires write permissions on repository

This commit introduces a new workflow that triggers on pull request labeling to automatically detect version bumps (patch, minor, major) for Coder modules. It processes modified modules, updates their version references in README files, and commits the changes. Additionally, it comments on the pull request with a summary of the version bumps and any modules without existing git tags.
@DevelopmentCats DevelopmentCats requested a review from matifali June 5, 2025 01:15
Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

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

Can you extract this to a script in ./scripts/update_veraion.sh that we can reuse in GitHub workflow?

Also the script should be able to run locally and bump versions for individual or multiple modules.

blink-so bot added a commit that referenced this pull request Jun 5, 2025
- Add .github/scripts/version-bump.sh with extracted logic from PR #137
- Add version-check.yaml workflow to verify module versions are updated
- Add version-bump.yaml workflow that uses the script for label-triggered bumps
- Update CONTRIBUTING.md with instructions on using the version bump script
- Script supports patch/minor/major bumps and validates semantic versioning
- CI will now check that module versions are properly updated in PRs
DevelopmentCats added a commit that referenced this pull request Jun 11, 2025
# Extract Version Bump Logic into Reusable Script

This PR extracts the version bump logic from the GitHub Actions workflow
(PR #137) into a reusable script and implements the requirements as
requested.

## ✅ What This PR Delivers

### 🔧 **Version Bump Script**: `.github/scripts/version-bump.sh`
- Extracts all version bump logic from the original workflow
- Supports `patch`, `minor`, and `major` version bumps
- Configurable base reference for diff comparison (defaults to
`origin/main`)
- Comprehensive error handling and semantic version validation
- Can be used standalone or in workflows

### 🔍 **Version Check Workflow**: `.github/workflows/version-check.yaml`
- **Required CI check** that runs on all PRs modifying modules
- Verifies that module versions have been properly updated
- Fails if versions need bumping but haven't been updated
- Provides clear instructions on how to fix version issues

### 🚀 **Version Bump Workflow**: `.github/workflows/version-bump.yaml`
- Simplified workflow that uses the extracted script
- Triggered by PR labels (`version:patch`, `version:minor`,
`version:major`)
- Automatically commits version updates and comments on PR

### 📚 **Updated Documentation**: `CONTRIBUTING.md`
- Clear instructions on how to use the version bump script
- Examples for different bump types
- Information about PR labels as an alternative
- Explains that CI will check version updates

## 🎯 Key Features

✅ **Script Logic Extracted**: All complex bash logic moved from workflow
to reusable script
✅ **Required CI Check**: Version check workflow ensures versions are
updated
✅ **Diff Verification**: Script checks git diff to detect modified
modules
✅ **Contribution Docs Updated**: Clear instructions for contributors  
✅ **Backward Compatible**: Maintains all original functionality  
✅ **Error Handling**: Comprehensive validation and clear error messages

## 📖 Usage Examples

```bash
# For bug fixes
./.github/scripts/version-bump.sh patch

# For new features  
./.github/scripts/version-bump.sh minor

# For breaking changes
./.github/scripts/version-bump.sh major
```

## 🔄 Workflow Integration

1. **Developer makes changes** to modules
2. **CI runs version-check** workflow automatically
3. **If versions need updating**, CI fails with instructions
4. **Developer runs script** or adds PR label
5. **Versions get updated** automatically
6. **CI passes** and PR can be merged

## 🧪 Testing

The script has been tested with:
- ✅ Valid and invalid bump types
- ✅ Module detection from git diff
- ✅ Version calculation and validation
- ✅ README version updates
- ✅ Error handling for edge cases

This implementation addresses all the original requirements while making
the logic more maintainable and reusable.

---------

Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com>
Co-authored-by: DevelopmentCats <[email protected]>
@DevelopmentCats
Copy link
Contributor Author

Script exists.

Is there a way we can test this workflow in an existing PR before Pushing?

I ran some simulated tests that worked fine, but I haven't run this in an actual GH Workflow so i'm not entirely sure if this works as intended in the context of being run as a workflow.

@DevelopmentCats DevelopmentCats requested a review from matifali June 13, 2025 02:03
@DevelopmentCats
Copy link
Contributor Author

Let me know if you are good with merging this now. @matifali

@matifali
Copy link
Member

I still think we should not try to commit changes and instead check for diff and fail CI.

Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

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

Instead of committing opt for failing CI and making it a required check.

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