cloudflare/kumo
Publicmirrored from https://github.com/cloudflare/kumoAvailable
ci/versioning/version-beta.sh
34lines · modecode
| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | # Note: Ensure "jq" is installed - sudo apt-get update && sudo apt-get install -y jq |
| 5 | # Note: Ensure Git is configured - git config --global user.email "you@example.com" && git config --global user.name "Your Name" |
| 6 | # Note: Use CI vars where possible: `commitHash=${GITHUB_SHA:0:7:-$(git rev-parse --short HEAD)}` |
| 7 | # - This line first tries to use the GITHUB_SHA environment variable (GitHub Actions) and falls back to the Git command if it's not set. |
| 8 | |
| 9 | # Run changeset version to version all packages |
| 10 | pnpm run version |
| 11 | |
| 12 | # Ensure changes are staged for the commit hash to reflect all changes including version bumps |
| 13 | git add . |
| 14 | |
| 15 | # Get the current short Git commit hash |
| 16 | # GitHub Actions provides GITHUB_SHA (full), so we truncate it |
| 17 | commitHash=${GITHUB_SHA:+${GITHUB_SHA:0:7}} |
| 18 | commitHash=${commitHash:-$(git rev-parse --short HEAD)} |
| 19 | |
| 20 | # Find all modified package.json files and append "-beta" and the commit hash to their version |
| 21 | git diff --cached --name-only | grep 'package.json$' | while read -r file ; do |
| 22 | echo "Updating $file with \"-beta\" and commit hash $commitHash" |
| 23 | |
| 24 | # Use jq to safely read and modify the JSON data, appending "-beta" and the commit hash to the version |
| 25 | jq --arg hash "$commitHash" ' |
| 26 | if .version then |
| 27 | .version += ("-beta." + $hash) |
| 28 | else |
| 29 | . |
| 30 | end' "$file" > temp.json && mv temp.json "$file" |
| 31 | |
| 32 | # Stage the modified package.json for commit |
| 33 | git add "$file" |
| 34 | done |
| 35 | |