File: release

package info (click to toggle)
ruby-view-component 2.74.1-1
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm
  • size: 3,156 kB
  • sloc: ruby: 6,731; sh: 163; javascript: 10; makefile: 4
file content (168 lines) | stat: -rwxr-xr-x 3,911 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env bash

fetch() {
  git fetch --all
}

branch_name() {
  git symbolic-ref --short HEAD
}

local_history_is_clean() {
  history=$(git rev-list --count --right-only @{u}...HEAD)
  [ "$history" == "0" ]
}

remote_history_is_clean() {
  history=$(git rev-list --count --left-only @{u}...HEAD)
  [ "$history" == "0" ]
}

tag_exists_on_remote() {
  git rev-parse --quiet --verify refs/tags/v$1.$2.$3 > /dev/null
}

working_tree_is_clean() {
  status=$(git status --porcelain)
  [ "$status" == "" ]
}

create_release_branch() {
  git switch -c release-v$1-$2-$3
}

update_readme() {
  sed -i '' "/## main/ {a\
  \\
\\
## $1.$2.$3
  }" docs/CHANGELOG.md
}

update_ruby_version() {
  # Update version file
  sed -E -i '' \
      -e "s/MAJOR = [0-9]+/MAJOR = $1/g" \
      -e "s/MINOR = [0-9]+/MINOR = $2/g" \
      -e "s/PATCH = [0-9]+/PATCH = $3/g" \
      lib/view_component/version.rb

  # Update deprecation horizon version
  major=$1
  sed -E -i '' \
      -e "s/DEPRECATION_HORIZON = [0-9]+/DEPRECATION_HORIZON = $((major + 1))/g" \
      lib/view_component/deprecation.rb
}

update_gemfiles() {
  # Update Gemfile.lock
  bundle
}

build_docs() {
  bundle exec rake docs:build
}

add_changed_files() {
  git add \
    docs/api.md \
    docs/CHANGELOG.md \
    docs/_data/library.yml \
    Gemfile.lock \
    lib/view_component/version.rb
}

commit() {
  git commit -m "release $1.$2.$3"
}

push() {
  git push origin release-v$1-$2-$3

  echo "####################################################"
  echo "Now, open a PR with this branch and merge it to main"
  echo "Then, run script/publish on main to release the gem"
  echo "Finally, create a GitHub release https://github.com/viewcomponent/view_component/releases/new with the changes from docs/CHANGELOG"
  echo "####################################################"
}

main() {
  version=$(ruby ./lib/view_component/version.rb)
  version=(${version//./ })
  major=${version[0]}
  minor=${version[1]}
  patch=${version[2]}

  echo "==================="
  echo "Prerequisite Checks"
  echo "==================="

  if ! working_tree_is_clean; then
    echo "Error: unclean working tree"
    exit 1
  fi

  if [ "$(branch_name)" != "main" ]; then
    echo "Error: can only make a release on the main branch"
    exit 1
  fi

  fetch

  if ! remote_history_is_clean; then
    echo "Error: changes exist on origin not pulled into this branch. Please pull"
    exit 1
  fi

  if ! local_history_is_clean; then
    echo "Error: changes exist that haven't been pushed to origin. Please pull"
    exit 1
  fi

  echo "Type the number of an option to bump, or pick Manual to enter a version number"
  select bump in Major Minor Patch Manual
  do
    if [ "$bump" == "Major" ]; then
      major=$((major + 1))
      minor=0
      patch=0
    elif [ "$bump" == "Minor" ]; then
      minor=$((minor + 1))
      patch=0
    elif [ "$bump" == "Patch" ]; then
      patch=$((patch + 1))
    else
      read -p "What version? (Currently $major.$minor.$patch): " new_version
      if [ "$new_version" == "$major.$minor.$patch" ]; then
        echo "Error: Can't be the same version"
        exit 1
      fi

      new_version=(${new_version//./ })

      major=${new_version[0]}
      minor=${new_version[1]}
      patch=${new_version[2]}
    fi

    if tag_exists_on_remote $major $minor $patch; then
      echo "Error: tag exists on remote"
      exit 1
    fi

    echo "==============================="
    echo "Creating release for $major.$minor.$patch"
    echo "==============================="

    create_release_branch $major $minor $patch
    update_readme $major $minor $patch
    update_ruby_version $major $minor $patch
    update_gemfiles $major $minor $patch
    echo "version: $major.$minor.$patch" > docs/_data/library.yml
    add_changed_files $major $minor $patch
    commit $major $minor $patch
    push $major $minor $patch
  done
}

main