Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

chore: add support for separate module versioning to CI #1519

chore: add support for separate module versioning to CI

chore: add support for separate module versioning to CI #1519

Workflow file for this run

name: ci
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Terraform
uses: coder/coder/.github/actions/setup-tf@main
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
# We're using the latest version of Bun for now, but it might be worth
# reconsidering. They've pushed breaking changes in patch releases
# that have broken our CI.
# Our PR where issues started to pop up: https://github.com/coder/modules/pull/383
# The Bun PR that broke things: https://github.com/oven-sh/bun/pull/16067
bun-version: latest
- name: Install dependencies
run: bun install
- name: Run tests
run: bun test
pretty:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed to get tags
- uses: coder/coder/.github/actions/setup-tf@main
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup
run: bun install
- name: Format
run: bun fmt:ci
- name: typos-action
uses: crate-ci/[email protected]
- name: Lint
run: bun lint
- name: Check module versions
shell: bash
run: |
# For PRs: Check that modules with changes have their README versions updated
# For merged commits: Check that versions match tags
# First, identify which modules have changes
echo "Identifying modules with changes..."
CHANGED_MODULES=$(./modules-version.sh | grep "Module " | cut -d: -f1 | sed 's/Module //')
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "Pull request detected - checking if versions need updating..."
# Extract the base branch (usually main)
BASE_BRANCH="${{ github.base_ref }}"
echo "Base branch: $BASE_BRANCH"
# For each changed module, check if the version in README.md has been incremented
# compared to the latest tag for that module
EXIT_CODE=0
for module in $CHANGED_MODULES; do
echo "Checking module: $module"
# Skip modules without tags
if ! git tag -l "release/$module/v*" | grep -q .; then
echo "Module $module has no previous tags, skipping version check"
continue
fi
# Get latest tag version for this module
LATEST_TAG=$(git tag -l "release/$module/v*" | sort -V | tail -n 1)
TAG_VERSION=$(echo "$LATEST_TAG" | sed "s|release/$module/v||")
# Extract version from README.md in the PR
README_VERSION=$(grep -o 'version *= *"[0-9]\+\.[0-9]\+\.[0-9]\+"' "$module/README.md" | head -1 | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' || echo "0.0.0")
echo "Module $module - Latest tag: $TAG_VERSION, PR version: $README_VERSION"
# Compare versions using simple numeric comparison (assumes semantic versioning)
TAG_VERSION_NUM=$(echo "$TAG_VERSION" | sed 's/\.//g')
README_VERSION_NUM=$(echo "$README_VERSION" | sed 's/\.//g')
if [ "$README_VERSION_NUM" -le "$TAG_VERSION_NUM" ]; then
echo "ERROR: Version in $module/README.md ($README_VERSION) must be greater than the latest tag ($TAG_VERSION)"
echo "Please update the version in $module/README.md using one of these methods:"
echo " - Run: ./modules-version.sh --bump=patch $module"
echo " - Run: ./modules-version.sh --bump=minor $module"
echo " - Run: ./modules-version.sh --bump=major $module"
EXIT_CODE=1
else
echo "✓ Version in $module/README.md has been properly incremented"
fi
done
exit $EXIT_CODE
else
# For pushes to main, run the regular check to ensure versions match tags
echo "Push to branch detected - checking versions match tags..."
./modules-version.sh --check
fi