Compare commits
3 Commits
main
...
cat/versio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fac76efbfe | ||
|
|
a5ebd5e14b | ||
|
|
21fc9618a7 |
12
.github/scripts/version-bump.sh
vendored
12
.github/scripts/version-bump.sh
vendored
@ -1,26 +1,29 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Version Bump Script
|
# Version Bump Script
|
||||||
# Usage: ./version-bump.sh [--ci] <bump_type> [base_ref]
|
# Usage: ./version-bump.sh [--ci] <bump_type> [base_ref] [head_ref]
|
||||||
# --ci: CI mode - run bump, check for changes, exit 1 if changes needed
|
# --ci: CI mode - run bump, check for changes, exit 1 if changes needed
|
||||||
# bump_type: patch, minor, or major
|
# bump_type: patch, minor, or major
|
||||||
# base_ref: base reference for diff (default: origin/main)
|
# base_ref: base reference for diff (default: origin/main)
|
||||||
|
# head_ref: head reference for diff (default: HEAD)
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
CI_MODE=false
|
CI_MODE=false
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $0 [--ci] <bump_type> [base_ref]"
|
echo "Usage: $0 [--ci] <bump_type> [base_ref] [head_ref]"
|
||||||
echo " --ci: CI mode - validates versions are already bumped (exits 1 if not)"
|
echo " --ci: CI mode - validates versions are already bumped (exits 1 if not)"
|
||||||
echo " bump_type: patch, minor, or major"
|
echo " bump_type: patch, minor, or major"
|
||||||
echo " base_ref: base reference for diff (default: origin/main)"
|
echo " base_ref: base reference for diff (default: origin/main)"
|
||||||
|
echo " head_ref: head reference for diff (default: HEAD, used for fork PRs)"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " $0 patch # Update versions with patch bump"
|
echo " $0 patch # Update versions with patch bump"
|
||||||
echo " $0 minor # Update versions with minor bump"
|
echo " $0 minor # Update versions with minor bump"
|
||||||
echo " $0 major # Update versions with major bump"
|
echo " $0 major # Update versions with major bump"
|
||||||
echo " $0 --ci patch # CI check: verify patch bump has been applied"
|
echo " $0 --ci patch # CI check: verify patch bump has been applied"
|
||||||
|
echo " $0 --ci patch base_sha head_sha # CI check with explicit refs (for fork PRs)"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,12 +128,13 @@ main() {
|
|||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
|
if [ $# -lt 1 ] || [ $# -gt 3 ]; then
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local bump_type="$1"
|
local bump_type="$1"
|
||||||
local base_ref="${2:-origin/main}"
|
local base_ref="${2:-origin/main}"
|
||||||
|
local head_ref="${3:-HEAD}"
|
||||||
|
|
||||||
case "$bump_type" in
|
case "$bump_type" in
|
||||||
"patch" | "minor" | "major") ;;
|
"patch" | "minor" | "major") ;;
|
||||||
@ -144,7 +148,7 @@ main() {
|
|||||||
echo "🔍 Detecting modified modules..."
|
echo "🔍 Detecting modified modules..."
|
||||||
|
|
||||||
local changed_files
|
local changed_files
|
||||||
changed_files=$(git diff --name-only "${base_ref}"...HEAD)
|
changed_files=$(git diff --name-only "${base_ref}".."${head_ref}")
|
||||||
local modules
|
local modules
|
||||||
modules=$(echo "$changed_files" | grep -E '^registry/[^/]+/modules/[^/]+/' | cut -d'/' -f1-4 | sort -u)
|
modules=$(echo "$changed_files" | grep -E '^registry/[^/]+/modules/[^/]+/' | cut -d'/' -f1-4 | sort -u)
|
||||||
|
|
||||||
|
|||||||
42
.github/workflows/version-bump.yaml
vendored
42
.github/workflows/version-bump.yaml
vendored
@ -1,13 +1,14 @@
|
|||||||
name: Version Bump
|
name: Version Bump
|
||||||
|
|
||||||
|
# Using pull_request_target to allow commenting on PRs from forks.
|
||||||
|
# SECURITY: Executable code (scripts, package.json) comes from the BASE branch only.
|
||||||
|
# Only the registry/ directory (data files) is checked out from the PR for version checking.
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request_target:
|
||||||
types: [labeled]
|
types: [labeled]
|
||||||
paths:
|
|
||||||
- "registry/**/modules/**"
|
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@ -19,24 +20,50 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
issues: write
|
issues: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout base branch
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
|
ref: ${{ github.event.pull_request.base.sha }}
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Fetch PR head
|
||||||
|
run: |
|
||||||
|
git fetch origin refs/pull/${{ github.event.pull_request.number }}/head:pr-head
|
||||||
|
echo "PR_HEAD_SHA=$(git rev-parse pr-head)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Check for module changes
|
||||||
|
id: check-modules
|
||||||
|
run: |
|
||||||
|
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }}..pr-head)
|
||||||
|
if echo "$CHANGED_FILES" | grep -qE '^registry/[^/]+/modules/'; then
|
||||||
|
echo "has_module_changes=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "✅ PR contains module changes"
|
||||||
|
else
|
||||||
|
echo "has_module_changes=false" >> $GITHUB_OUTPUT
|
||||||
|
echo "ℹ️ PR does not contain module changes, skipping version bump check"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Checkout PR module files
|
||||||
|
if: steps.check-modules.outputs.has_module_changes == 'true'
|
||||||
|
run: git checkout pr-head -- registry/
|
||||||
|
|
||||||
- name: Set up Bun
|
- name: Set up Bun
|
||||||
|
if: steps.check-modules.outputs.has_module_changes == 'true'
|
||||||
uses: oven-sh/setup-bun@v2
|
uses: oven-sh/setup-bun@v2
|
||||||
with:
|
with:
|
||||||
bun-version: latest
|
bun-version: latest
|
||||||
|
|
||||||
- name: Set up Terraform
|
- name: Set up Terraform
|
||||||
|
if: steps.check-modules.outputs.has_module_changes == 'true'
|
||||||
uses: coder/coder/.github/actions/setup-tf@main
|
uses: coder/coder/.github/actions/setup-tf@main
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
if: steps.check-modules.outputs.has_module_changes == 'true'
|
||||||
run: bun install
|
run: bun install
|
||||||
|
|
||||||
- name: Extract bump type from label
|
- name: Extract bump type from label
|
||||||
|
if: steps.check-modules.outputs.has_module_changes == 'true'
|
||||||
id: bump-type
|
id: bump-type
|
||||||
run: |
|
run: |
|
||||||
case "${{ github.event.label.name }}" in
|
case "${{ github.event.label.name }}" in
|
||||||
@ -56,10 +83,11 @@ jobs:
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
- name: Check version bump
|
- name: Check version bump
|
||||||
run: ./.github/scripts/version-bump.sh --ci "${{ steps.bump-type.outputs.type }}" origin/main
|
if: steps.check-modules.outputs.has_module_changes == 'true'
|
||||||
|
run: ./.github/scripts/version-bump.sh --ci "${{ steps.bump-type.outputs.type }}" ${{ github.event.pull_request.base.sha }} ${{ env.PR_HEAD_SHA }}
|
||||||
|
|
||||||
- name: Comment on PR - Version bump required
|
- name: Comment on PR - Version bump required
|
||||||
if: failure()
|
if: failure() && steps.check-modules.outputs.has_module_changes == 'true'
|
||||||
uses: actions/github-script@v8
|
uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user