From bd6747f9bc8e0710f0212422ac97aa8047561d15 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 27 Sep 2024 11:24:06 -0700 Subject: [PATCH] chore: move update-version to ci (#301) --- .github/workflows/ci.yaml | 15 ++++++++++ .github/workflows/update-readme.yaml | 42 ---------------------------- cursor/README.md | 4 +-- filebrowser/README.md | 6 ++-- jupyter-notebook/README.md | 2 +- jupyterlab/README.md | 2 +- update-version.sh | 23 +++++++++++---- 7 files changed, 39 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows/update-readme.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2b337d8..4d0c709 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,6 +27,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Needed to get tags - uses: oven-sh/setup-bun@v2 with: bun-version: latest @@ -38,3 +40,16 @@ jobs: uses: crate-ci/typos@v1.17.2 - name: Lint run: bun lint + - name: Check version + shell: bash + run: | + # check for version changes + ./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 version mismatch detected. All versions are up to date." + fi diff --git a/.github/workflows/update-readme.yaml b/.github/workflows/update-readme.yaml deleted file mode 100644 index 0d0e226..0000000 --- a/.github/workflows/update-readme.yaml +++ /dev/null @@ -1,42 +0,0 @@ -name: Update README on Tag - -on: - workflow_dispatch: - push: - tags: - - 'v*' - -jobs: - update-readme: - permissions: - contents: write - pull-requests: write - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Get the latest tag - id: get-latest-tag - run: echo "TAG=$(git describe --tags --abbrev=0 | sed 's/^v//')" >> $GITHUB_OUTPUT - - - name: Run update script - run: ./update-version.sh - - - name: Create Pull Request - id: create-pr - uses: peter-evans/create-pull-request@v5 - with: - commit-message: 'chore: bump version to ${{ env.TAG }} in README.md files' - title: 'chore: bump version to ${{ env.TAG }} in README.md files' - body: 'This is an auto-generated PR to update README.md files of all modules with the new tag ${{ env.TAG }}' - branch: 'update-readme-branch' - base: 'main' - env: - TAG: ${{ steps.get-latest-tag.outputs.TAG }} - - - name: Auto-approve - uses: hmarr/auto-approve-action@v4 - if: github.ref == 'refs/heads/update-readme-branch' diff --git a/cursor/README.md b/cursor/README.md index a62743b..c2997be 100644 --- a/cursor/README.md +++ b/cursor/README.md @@ -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 } ``` @@ -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" } diff --git a/filebrowser/README.md b/filebrowser/README.md index e92560b..8665d82 100644 --- a/filebrowser/README.md +++ b/filebrowser/README.md @@ -14,7 +14,7 @@ A file browser for your workspace. ```tf module "filebrowser" { source = "registry.coder.com/modules/filebrowser/coder" - version = "1.0.18" + version = "1.0.19" agent_id = coder_agent.example.id } ``` @@ -28,7 +28,7 @@ module "filebrowser" { ```tf module "filebrowser" { source = "registry.coder.com/modules/filebrowser/coder" - version = "1.0.18" + version = "1.0.19" agent_id = coder_agent.example.id folder = "/home/coder/project" } @@ -39,7 +39,7 @@ module "filebrowser" { ```tf module "filebrowser" { source = "registry.coder.com/modules/filebrowser/coder" - version = "1.0.18" + version = "1.0.19" agent_id = coder_agent.example.id database_path = ".config/filebrowser.db" } diff --git a/jupyter-notebook/README.md b/jupyter-notebook/README.md index 6338f11..83d36cb 100644 --- a/jupyter-notebook/README.md +++ b/jupyter-notebook/README.md @@ -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 } ``` diff --git a/jupyterlab/README.md b/jupyterlab/README.md index 3d04cf3..ed73b56 100644 --- a/jupyterlab/README.md +++ b/jupyterlab/README.md @@ -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 } ``` diff --git a/update-version.sh b/update-version.sh index 5deb63b..b062736 100755 --- a/update-version.sh +++ b/update-version.sh @@ -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" '{ @@ -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