|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -eu |
| 4 | +set -o pipefail |
| 5 | + |
| 6 | +if [[ $# -lt 1 ]] ; then |
| 7 | + echo "Usage: $(basename $0) <upstream-tag>" |
| 8 | + echo |
| 9 | + echo "Where <upstream_version> is the tag name of the Tailwind CSS release." |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +PAGER="" # we don't want gh to use a pager |
| 14 | +git_cmd=$(command -v git) |
| 15 | +gh_cmd=$(command -v gh) |
| 16 | +sed_cmd=$(command -v sed) |
| 17 | + |
| 18 | +fail() { |
| 19 | + echo "Error: $*" >&2 |
| 20 | + exit 1 |
| 21 | +} |
| 22 | + |
| 23 | +upstream_tag=$1 |
| 24 | +gem_version=$(echo $upstream_tag | $sed_cmd -E 's/^v//' | sed -E 's/-/./') |
| 25 | +gem_tag="v${gem_version}" |
| 26 | + |
| 27 | +github_user=$($git_cmd config github.user || true) |
| 28 | +if [[ -z "$github_user" ]]; then |
| 29 | + fail "github.user is not set in git config" |
| 30 | +fi |
| 31 | + |
| 32 | +# view the release. will fail if the release does not exist |
| 33 | +$gh_cmd release view ${upstream_tag} --repo tailwindlabs/tailwindcss |
| 34 | + |
| 35 | +# get on the right starting branch |
| 36 | +if [[ -n "$($git_cmd status --porcelain --untracked-files=no)" ]]; then |
| 37 | + fail "found uncommitted changes" |
| 38 | +fi |
| 39 | + |
| 40 | +if [[ $upstream_tag =~ ^v4 ]] ; then |
| 41 | + base_branch="v4.x" |
| 42 | + |
| 43 | + changelog_extra=$(cat <<EOF |
| 44 | +
|
| 45 | + Upgrade guide at https://tailwindcss.com/docs/upgrade-guide |
| 46 | +EOF |
| 47 | +) |
| 48 | +elif [[ $upstream_tag =~ ^v3 ]] ; then |
| 49 | + base_branch="main" |
| 50 | + changelog_extra="" |
| 51 | +else |
| 52 | + fail "Whoa! A new major version? Need to update the ${0} script." |
| 53 | +fi |
| 54 | + |
| 55 | +$git_cmd switch $base_branch |
| 56 | + |
| 57 | +if ! $git_cmd rev-parse --abbrev-ref @{push} >/dev/null 2>&1; then |
| 58 | + fail "current branch is not tracking a remote branch" |
| 59 | +fi |
| 60 | + |
| 61 | +# |
| 62 | +# modify the upstream version and gem version |
| 63 | +# |
| 64 | +$sed_cmd -E -i "s/^(\s+)VERSION\s+=.*/\1VERSION = \"${upstream_tag}\"/" lib/tailwindcss/ruby/upstream.rb |
| 65 | +$sed_cmd -E -i "s/^(\s+)VERSION\s+=.*/\1VERSION = \"${gem_version}\"/" lib/tailwindcss/ruby/version.rb |
| 66 | + |
| 67 | +bundle install |
| 68 | + |
| 69 | +# |
| 70 | +# modify the changelog |
| 71 | +# |
| 72 | +replacement_text=$(cat <<EOF |
| 73 | +## ${gem_tag} |
| 74 | +
|
| 75 | +* Update to [Tailwind CSS ${upstream_tag}](https://github.com/tailwindlabs/tailwindcss/releases/tag/${upstream_tag}) @${github_user} |
| 76 | +${changelog_extra} |
| 77 | +EOF |
| 78 | +) |
| 79 | +# substitute newlines with '\n' so sed will do the right things |
| 80 | +replacement_text=$(echo "$replacement_text" | tr '\n' '\t' | sed -E 's/\t/\\n/g') |
| 81 | +$sed_cmd -E -i "0,/^##/{s|^##|${replacement_text}\n\n##|}" CHANGELOG.md |
| 82 | + |
| 83 | +# |
| 84 | +# check if the packages match the checksums |
| 85 | +# |
| 86 | +bundle exec rake clobber download |
| 87 | + |
| 88 | +# |
| 89 | +# commit to a branch |
| 90 | +# |
| 91 | +git switch -c flavorjones-dep-tailwindcss-${upstream_tag} |
| 92 | +git add lib CHANGELOG.md Gemfile* |
| 93 | +git commit -m "dep: update to Tailwind CSS ${upstream_tag} |
| 94 | +
|
| 95 | +https://github.com/tailwindlabs/tailwindcss/releases/tag/${upstream_tag} |
| 96 | +" |
| 97 | + |
| 98 | +echo "Now push the current branch and create a PR." |
| 99 | +exit 0 |
0 commit comments