Skip to content

Commit fa23d75

Browse files
committed
Release workflow
1 parent 25f9213 commit fa23d75

File tree

6 files changed

+152
-28
lines changed

6 files changed

+152
-28
lines changed

.github/workflows/release.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Publish RubyGem
2+
3+
on:
4+
workflow_dispatch: # Trigger the workflow manually
5+
inputs:
6+
otp_code:
7+
description: 'Enter the RubyGems OTP code'
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
release:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
- name: Set up Ruby
24+
uses: ruby/setup-ruby@v1
25+
with:
26+
ruby-version: '3.3.4'
27+
28+
- name: Extract Gem Version
29+
id: extract_version
30+
run: |
31+
VERSION=$(./.github/workflows/scripts/version.sh)
32+
echo "Version: $VERSION"
33+
echo "gem_version=$VERSION" >> $GITHUB_ENV
34+
35+
- name: Install dependencies
36+
run: bundle install
37+
38+
- name: Extract Changelog
39+
run: ./.github/workflows/scripts/changelog.sh
40+
41+
- name: Build the gem
42+
run: gem build *.gemspec
43+
44+
- name: Tag the release version
45+
run: ./.github/workflows/scripts/tag.sh
46+
47+
- name: Publish to RubyGems
48+
env:
49+
GEM_HOST_API_KEY: ${{ secrets.JS_ROUTES_RUBYGEMS_KEY }}
50+
run: |
51+
gem push *.gem --otp ${{ github.event.inputs.otp_code }}
52+
53+
- name: Create GitHub Release
54+
uses: softprops/action-gh-release@v2
55+
with:
56+
name: "v${{ env.gem_version }}"
57+
tag_name: "v${{ env.gem_version }}"
58+
body_path: ./release_changelog.md
59+
draft: false
60+
prerelease: false
61+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
CHANGELOG="CHANGELOG.md"
6+
OUTPUT="./release_changelog.md"
7+
SCRIPT_DIR=$(dirname "$(realpath "$0")")
8+
VERSION=$($SCRIPT_DIR/version.sh)
9+
10+
if [ -z "$VERSION" ]; then
11+
echo "VERSION is not specified"
12+
exit 1
13+
fi
14+
15+
if [ ! -f "$CHANGELOG" ]; then
16+
echo "CHANGELOG.md file not found!"
17+
exit 1
18+
fi
19+
20+
if ! grep -q "^## \[$VERSION\]" $CHANGELOG; then
21+
echo "No changelog found for version $VERSION in $CHANGELOG"
22+
exit 1
23+
fi
24+
25+
echo "## Changes" > $OUTPUT
26+
echo "" >> $OUTPUT
27+
ruby -e "puts File.read('$CHANGELOG').split('## [$VERSION]')[1]&.split('## ')&.first&.strip" >> $OUTPUT
28+
echo "Release notes:"
29+
echo ----------------------------------------
30+
cat $OUTPUT
31+
echo ----------------------------------------
32+

.github/workflows/scripts/tag.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
set -e
4+
SCRIPT_DIR=$(dirname "$(realpath "$0")")
5+
VERSION=$($SCRIPT_DIR/version.sh)
6+
7+
git tag "v$VERSION" || echo "Tag already exists."
8+
git push origin "v$VERSION"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
VERSION_FILE="./lib/js_routes/version.rb"
6+
if [ ! -f "$VERSION_FILE" ]; then
7+
echo "Version file not found!"
8+
exit 1
9+
fi
10+
11+
VERSION=$(ruby -r $VERSION_FILE -e "puts JsRoutes::VERSION")
12+
13+
if [ -z "$VERSION" ]; then
14+
echo "Could not extract version from $VERSION_FILE"
15+
exit 1
16+
fi
17+
18+
echo "$VERSION"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ gemfiles/*.lock
7171
node_modules
7272
sorbet/rbi
7373

74+
/release_changelog.md

CHANGELOG.md

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
## v2.3.3
3+
## [2.3.4]
4+
5+
* Migrate to yarn 4
6+
7+
## [2.3.3]
48

59
* Rework default banner to use `routes.rb` digest instead of timestamp to ensure
610
consistent routes.js version accross environments.
@@ -17,7 +21,7 @@ The new default banner:
1721
*/
1822
```
1923

20-
## v2.3.2
24+
## [2.3.2]
2125

2226
* Add `banner` option that allow to control JSDoc on top of generated file. [#324](https://github.com/bogdan/repo/issues/324).
2327

@@ -34,131 +38,131 @@ JsRoutes.setup do |c|
3438
end
3539
```
3640

37-
## v2.3.1
41+
## [2.3.1]
3842

3943
* Add timestamp on when routes.js was generated into banner.
4044
* Fix application specified directly without proc. [#323](https://github.com/railsware/js-routes/issues/323)
4145
* Support `optional_definition_params` option. See [Related Docs](./Readme.md#optional-definition-params).
4246

43-
## v2.3.0
47+
## [2.3.0]
4448

4549
* Drop support of Rails 4.x
4650
* Fix support of shakapacker [#321](https://github.com/railsware/js-routes/issues/321).
4751
* Fix support for Rails 8 [#319](https://github.com/railsware/js-routes/issues/319)
4852
* Deprecated `rake js:routes:typescript`.
4953
`rake js:routes` now automatically detects if types support can be used on not.
5054

51-
## v2.2.10
55+
## [2.2.10]
5256

5357
* Remove sorbet files from repo
5458
* Clearly define files included in gem
5559
* Fix Middleware and Middleware generator bugs [#316](https://github.com/railsware/js-routes/issues/316)
5660
* Remove empty object linter warning on DTS module
5761
* Generators: Add `.ts` extension when searching for main JS file of the project
5862

59-
## v2.2.9
63+
## [2.2.9]
6064

6165
* Fix middleware error for non-modern setup.
6266
* Added [Sorbet](https://sorbet.org/) method signatures.
6367
* Always use DTS module type when calling JsRoutes.definitions or .definitions!.
6468
[#313](https://github.com/railsware/js-routes/issues/313)
6569

66-
## v2.2.8
70+
## [2.2.8]
6771

6872
* Leave emoji symbols intact when encoding URI fragment [#312](https://github.com/railsware/js-routes/issues/312)
6973
* Use webpacker config variable instead of hardcode [#309](https://github.com/railsware/js-routes/issues/309)
7074
* Use `File.exist?` to be compatible with all versions of ruby [#310](https://github.com/railsware/js-routes/issues/310)
7175

72-
## v2.2.7
76+
## [2.2.7]
7377

7478
* Fix ESM Tree Shaking [#306](https://github.com/railsware/js-routes/issues/306)
7579

76-
## v2.2.6
80+
## [2.2.6]
7781

7882
* Prefer to extend `javascript:build` instead of `assets:precompile`. [#305](https://github.com/railsware/js-routes/issues/305)
7983
* Add stimulus framework application.js location to generators
8084

81-
## v2.2.5
85+
## [2.2.5]
8286

8387
* Upgraded eslint and prettier versions [#304](https://github.com/railsware/js-routes/issues/304)
8488
* Fix middleware generator [#300](https://github.com/railsware/js-routes/issues/300)
8589
* Support `params` special parameter
8690

87-
## v2.2.4
91+
## [2.2.4]
8892

8993
* Fix rails engine loading if sprockets is not in Gemfile. Fixes [#294](https://github.com/railsware/js-routes/issues/294)
9094

91-
## v2.2.3
95+
## [2.2.3]
9296

9397
* Fixed NIL module type namespace defintion [#297](https://github.com/railsware/js-routes/issues/297).
9498
* The patch may cause a problem with nested `namespace` option.
9599
* Ex. Value like `MyProject.Routes` requires to define `window.MyProject` before importing the routes file
96100

97-
## v2.2.2
101+
## [2.2.2]
98102

99103
* Fix custom file path [#295](https://github.com/railsware/js-routes/issues/295)
100104

101-
## v2.2.1
105+
## [2.2.1]
102106

103107
* Improve generator to update route files on `assets:precompile` and add them to `.gitignore by default` [#288](https://github.com/railsware/js-routes/issues/288#issuecomment-1012182815)
104108

105-
## v2.2.0
109+
## [2.2.0]
106110

107111
* Use Rack Middleware to automatically update routes file in development [#288](https://github.com/railsware/js-routes/issues/288)
108112
* This setup is now a default recommended due to lack of any downside comparing to [ERB Loader](./Readme.md#webpacker) and [Manual Setup](./Readme.md#advanced-setup)
109113

110-
## v2.1.3
114+
## [2.1.3]
111115

112116
* Fix `default_url_options` bug. [#290](https://github.com/railsware/js-routes/issues/290)
113117

114-
## v2.1.2
118+
## [2.1.2]
115119

116120
* Improve browser window object detection. [#287](https://github.com/railsware/js-routes/issues/287)
117121

118-
## v2.1.1
122+
## [2.1.1]
119123

120124
* Added webpacker generator `./bin/rails generate js_routes:webpacker`
121125
* Reorganized Readme to describe different setups with their pros and cons more clearly
122126

123-
## v2.1.0
127+
## [2.1.0]
124128

125129
* Support typescript defintions file aka `routes.d.ts`. See [Readme.md](./Readme.md#definitions) for more information.
126130

127-
## v2.0.8
131+
## [2.0.8]
128132

129133
* Forbid usage of `namespace` option if `module_type` is not `nil`. [#281](https://github.com/railsware/js-routes/issues/281).
130134

131-
## v2.0.7
135+
## [2.0.7]
132136

133137
* Remove source map annotation from JS file. Fixes [#277](https://github.com/railsware/js-routes/issues/277)
134138
* Generated file is not minified, so it is better to use app side bundler/compressor for source maps
135139

136140

137-
## v2.0.6
141+
## [2.0.6]
138142

139143
* Disable `namespace` option default for all envs [#278](https://github.com/railsware/js-routes/issues/278)
140144

141-
## v2.0.5
145+
## [2.0.5]
142146

143147
* Fixed backward compatibility issue [#276](https://github.com/railsware/js-routes/issues/276)
144148

145-
## v2.0.4
149+
## [2.0.4]
146150

147151
* Fixed backward compatibility issue [#275](https://github.com/railsware/js-routes/issues/275)
148152

149-
## v2.0.3
153+
## [2.0.3]
150154

151155
* Fixed backward compatibility issue [#275](https://github.com/railsware/js-routes/issues/275)
152156

153-
## v2.0.2
157+
## [2.0.2]
154158

155159
* Fixed backward compatibility issue [#274](https://github.com/railsware/js-routes/issues/274)
156160

157-
## v2.0.1
161+
## [2.0.1]
158162

159163
* Fixed backward compatibility issue [#272](https://github.com/railsware/js-routes/issues/272)
160164

161-
## v2.0.0
165+
## [2.0.0]
162166

163167
Version 2.0 has some breaking changes.
164168
See [UPGRADE TO 2.0](./VERSION_2_UPGRADE.md) for guidance.

0 commit comments

Comments
 (0)