Skip to content

Commit 5ebf428

Browse files
authored
update release-please to be able to update ruby versions correctly (#203)
* chore: pin nodejs to compatible version * feat: add ruby version updater
1 parent dc0cbaf commit 5ebf428

File tree

7 files changed

+132
-1
lines changed

7 files changed

+132
-1
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 18.20.2

__snapshots__/ruby-readme.ts.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
exports['Ruby README.md updateContent updates ruby version in README.md - 0.6.0-alpha.1 1'] = `
2+
## Install
3+
4+
\`\`\`ruby
5+
gem "sink", "~> 0.6.0.pre.alpha.1"
6+
\`\`\`
7+
8+
\`\`\`ruby
9+
gem "sink", "~> 0.6.0.pre.alpha.1"
10+
\`\`\`
11+
12+
\`\`\`ruby
13+
gem "sink", "~> 0.6.0.pre.alpha.1"
14+
\`\`\`
15+
16+
`
17+
18+
exports['Ruby README.md updateContent updates ruby version in README.md - 0.6.0-beta.2 1'] = `
19+
## Install
20+
21+
\`\`\`ruby
22+
gem "sink", "~> 0.6.0.pre.beta.2"
23+
\`\`\`
24+
25+
\`\`\`ruby
26+
gem "sink", "~> 0.6.0.pre.beta.2"
27+
\`\`\`
28+
29+
\`\`\`ruby
30+
gem "sink", "~> 0.6.0.pre.beta.2"
31+
\`\`\`
32+
33+
`
34+
35+
exports['Ruby README.md updateContent updates ruby version in README.md - 2.1.0 1'] = `
36+
## Install
37+
38+
\`\`\`ruby
39+
gem "sink", "~> 2.1.0"
40+
\`\`\`
41+
42+
\`\`\`ruby
43+
gem "sink", "~> 2.1.0"
44+
\`\`\`
45+
46+
\`\`\`ruby
47+
gem "sink", "~> 2.1.0"
48+
\`\`\`
49+
50+
`

src/manifest.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,20 @@ type ExtraTomlFile = {
8181
jsonpath: string;
8282
glob?: boolean;
8383
};
84+
type ExtraRubyReadMeFile = {
85+
type: 'ruby-readme';
86+
path: string;
87+
jsonpath: string;
88+
glob?: boolean;
89+
};
8490
export type ExtraFile =
8591
| string
8692
| ExtraJsonFile
8793
| ExtraYamlFile
8894
| ExtraXmlFile
8995
| ExtraPomFile
90-
| ExtraTomlFile;
96+
| ExtraTomlFile
97+
| ExtraRubyReadMeFile;
9198
/**
9299
* These are configurations provided to each strategy per-path.
93100
*/

src/strategies/base.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {Generic} from '../updaters/generic';
4242
import {GenericJson} from '../updaters/generic-json';
4343
import {GenericXml} from '../updaters/generic-xml';
4444
import {PomXml} from '../updaters/java/pom-xml';
45+
import {RubyReadMeUpdater} from '../updaters/ruby/readme';
4546
import {GenericYaml} from '../updaters/generic-yaml';
4647
import {GenericToml} from '../updaters/generic-toml';
4748
import {FileNotFoundError} from '../errors';
@@ -553,6 +554,13 @@ If you instead want to use the version number \`${newVersion}\` generated from c
553554
updater: new PomXml(version),
554555
});
555556
break;
557+
case 'ruby-readme':
558+
extraFileUpdates.push({
559+
path: this.addPath(path),
560+
createIfMissing: false,
561+
updater: new RubyReadMeUpdater({version}),
562+
});
563+
break;
556564
default:
557565
throw new Error(
558566
`unsupported extraFile type: ${

src/updaters/ruby/readme.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {DefaultUpdater} from '../default';
2+
import {RUBY_VERSION_REGEX, stringifyRubyVersion} from './common';
3+
4+
const RUBY_VERSION_LINE_REGEX = new RegExp(
5+
`(^gem "[^"]+"\\s*,\\s*"[^\\d]+)(${RUBY_VERSION_REGEX.source})(.)\\s*$`,
6+
'gm'
7+
);
8+
9+
/**
10+
* Updates a versions.rb file which is expected to have a version string.
11+
*/
12+
export class RubyReadMeUpdater extends DefaultUpdater {
13+
/**
14+
* Given initial file contents, return updated contents.
15+
* @param {string} content The initial content
16+
* @returns {string} The updated content
17+
*/
18+
updateContent(content: string): string {
19+
return content.replace(
20+
RUBY_VERSION_LINE_REGEX,
21+
`$1${stringifyRubyVersion(this.version)}"`
22+
);
23+
}
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Install
2+
3+
```ruby
4+
gem "sink", "~> 0.2.0.pre.alpha"
5+
```
6+
7+
```ruby
8+
gem "sink", "~> 0.2.0.pre.beta"
9+
```
10+
11+
```ruby
12+
gem "sink", "~> 0.2.0"
13+
```

test/updaters/ruby-readme.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {readFileSync} from 'fs';
2+
import {describe, it} from 'mocha';
3+
import {resolve} from 'path';
4+
import {RubyReadMeUpdater} from '../../src/updaters/ruby/readme';
5+
import {Version} from '../../src/version';
6+
import snapshot = require('snap-shot-it');
7+
8+
const fixturesPath = './test/updaters/fixtures';
9+
10+
describe('Ruby README.md', () => {
11+
describe('updateContent', () => {
12+
const versions = ['2.1.0', '0.6.0-alpha.1', '0.6.0-beta.2'];
13+
14+
for (const ver of versions) {
15+
it(`updates ruby version in README.md - ${ver}`, async () => {
16+
const oldContent = readFileSync(
17+
resolve(fixturesPath, './README-ruby-version.md'),
18+
'utf8'
19+
).replace(/\r\n/g, '\n');
20+
const version = new RubyReadMeUpdater({
21+
version: Version.parse(ver),
22+
});
23+
const newContent = version.updateContent(oldContent);
24+
snapshot(newContent);
25+
});
26+
}
27+
});
28+
});

0 commit comments

Comments
 (0)