Skip to content

Commit 90df07c

Browse files
committed
Add a script to automate upstream bumps
and update CONTRIBUTING.md
1 parent 2d04044 commit 90df07c

File tree

2 files changed

+111
-6
lines changed

2 files changed

+111
-6
lines changed

CONTRIBUTING.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@ This doc is a brief introduction on modifying and maintaining this gem.
44

55
## Updating to the latest upstream tailwindcss version
66

7-
Update `lib/tailwindcss/ruby/upstream.rb` with the upstream version.
7+
Please don't submit PRs to the maintainer with an upstream bump.
88

9-
Run `bundle exec rake clobber` then `bundle exec rake download` to ensure the tailwindcss binaries can be downloaded, and that you have the correct versions on local disk.
9+
- [ ] run `bin/bump-upstream`
10+
- [ ] push the branch, create a PR
1011

1112
## Cutting a release of tailwindcss-ruby
1213

13-
- bump the version
14+
- if it's just bumping the upstream:
15+
- [ ] follow the steps above
16+
- [ ] when the PR is green, merge the PR
17+
- [ ] create a git tag (after updating local `main`)
18+
- else if the gem is being changed in some other way:
1419
- [ ] update `lib/tailwindcss/ruby/version.rb`
1520
- [ ] update `CHANGELOG.md`
16-
- [ ] commit and create a git tag
21+
- [ ] `git commit`
22+
- [ ] `git tag`
1723
- build the native gems:
18-
- [ ] `bundle exec rake clobber` if needed to clean up possibly-old tailwindcss executables
24+
- [ ] `bundle exec rake clobber` (if needed to clean up old tailwindcss executables)
1925
- [ ] `bundle exec rake package`
20-
- push
26+
- push source and gems:
2127
- [ ] `for g in pkg/*.gem ; do gem push $g ; done`
2228
- [ ] `git push && git push --tags`
2329
- announce

bin/bump-upstream

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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

Comments
 (0)