Skip to content

Commit

Permalink
chore: move update-version to ci
Browse files Browse the repository at this point in the history
Eliminate the GitHub workflow for automatic README updates and adjust the README files to reflect the new version tag. This change streamlines the process by removing redundant steps and ensures explicit control over version increments.

chore: add dependabot.yml (#302)

chore(deps): bump oven-sh/setup-bun from 1 to 2 (#305)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Update checkout action to fetch all tags

Improve version update script to handle errors

- Change version increment logic to handle missing tags.
- Add error handling for version mismatches in README.md files.
- Display directories with changed files for better visibility.

Improve version bumping process in update script

By checking for diffs after processing each README.md, we can
ensure that only modified files trigger version bump messages.
This change also refines the status check to target README.md files
specifically, aiding in precise error handling.

Clarify update script comment for version bumping

Improve version check and output in scripts

- Enhance visibility of version mismatches by focusing git diff on README.md files.
- Use command substitution to improve clarity in conditional checks.

Apply suggestions from code review

Co-authored-by: Mathias Fredriksson <[email protected]>

simplify

specify shell

Update ci.yaml

Update ci.yaml

Update update-version.sh

Update ci.yaml

Enhance version bump logic output in script

- Improve the clarity of version bump output by specifying current
  and incremented versions.
- Add additional message for unchanged README.md files.
  • Loading branch information
matifali committed Sep 25, 2024
1 parent c2ec4cb commit 70e6092
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 58 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
18 changes: 12 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup
Expand All @@ -27,7 +27,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
fetch-depth: 0 # Needed to get tags
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup
Expand All @@ -37,13 +39,17 @@ jobs:
- name: typos-action
uses: crate-ci/[email protected]
- name: Lint
run: bun lint
- name: Check version
shell: bash
run: |
bun lint
# check for version changes
./update-version.sh
if [[ `git status --porcelain` ]]; then
echo "Version mismatch. Please run ./update-version.sh"
# Check if any changes were made in README.md files
if [[ -n "$(git status --porcelain -- '**/README.md')" ]]; then
echo "Version mismatch detected. Please run ./update-version.sh and commit the updated README.md files."
git diff -- '**/README.md'
exit 1
else
echo "No changes detected."
echo "No version mismatch detected. All versions are up to date."
fi
42 changes: 0 additions & 42 deletions .github/workflows/update-readme.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions cursor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Uses the [Coder Remote VS Code Extension](https://github.com/coder/cursor-coder)
```tf
module "cursor" {
source = "registry.coder.com/modules/cursor/coder"
version = "1.0.18"
version = "1.0.19"
agent_id = coder_agent.example.id
}
```
Expand All @@ -28,7 +28,7 @@ module "cursor" {
```tf
module "cursor" {
source = "registry.coder.com/modules/cursor/coder"
version = "1.0.18"
version = "1.0.19"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
}
Expand Down
2 changes: 1 addition & 1 deletion jupyter-notebook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A module that adds Jupyter Notebook in your Coder template.
```tf
module "jupyter-notebook" {
source = "registry.coder.com/modules/jupyter-notebook/coder"
version = "1.0.8"
version = "1.0.19"
agent_id = coder_agent.example.id
}
```
2 changes: 1 addition & 1 deletion jupyterlab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A module that adds JupyterLab in your Coder template.
```tf
module "jupyterlab" {
source = "registry.coder.com/modules/jupyterlab/coder"
version = "1.0.8"
version = "1.0.19"
agent_id = coder_agent.example.id
}
```
23 changes: 17 additions & 6 deletions update-version.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#!/usr/bin/env bash

# This script updates the version number in the README.md files of all modules
# to the latest tag in the repository. It is intended to be run from the root
# This script increments the version number in the README.md files of all modules
# by 1 patch version. It is intended to be run from the root
# of the repository or by using the `bun update-version` command.

set -euo pipefail

current_tag=$(git describe --tags --abbrev=0)
previous_tag=$(git describe --tags --abbrev=0 $current_tag^)
mapfile -t changed_dirs < <(git diff --name-only "$previous_tag"..."$current_tag" -- ':!**/README.md' ':!**/*.test.ts' | xargs dirname | grep -v '^\.' | sort -u)

LATEST_TAG=$(git describe --abbrev=0 --tags | sed 's/^v//') || exit $?
# Increment the patch version
LATEST_TAG=$(echo "$current_tag" | sed 's/^v//' | awk -F. '{print $1"."$2"."$3+1}') || exit $?

# List directories with changes that are not README.md or test files
mapfile -t changed_dirs < <(git diff --name-only "$current_tag" -- ':!**/README.md' ':!**/*.test.ts' | xargs dirname | grep -v '^\.' | sort -u)

echo "Directories with changes: ${changed_dirs[*]}"

# Iterate over directories and update version in README.md
for dir in "${changed_dirs[@]}"; do
if [[ -f "$dir/README.md" ]]; then
echo "Bumping version in $dir/README.md"
file="$dir/README.md"
tmpfile=$(mktemp /tmp/tempfile.XXXXXX)
awk -v tag="$LATEST_TAG" '{
Expand All @@ -25,5 +29,12 @@ for dir in "${changed_dirs[@]}"; do
print
}
}' "$file" > "$tmpfile" && mv "$tmpfile" "$file"

# Check if the README.md file has changed
if ! git diff --quiet -- "$dir/README.md"; then
echo "Bumping version in $dir/README.md from $current_tag to $LATEST_TAG (incremented)"
else
echo "Version in $dir/README.md is already up to date"
fi
fi
done

0 comments on commit 70e6092

Please sign in to comment.