@scaleway/changesets-renovate 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +4 -0
- package/CHANGELOG.md +11 -0
- package/LICENSE.md +21 -0
- package/README.md +19 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +69 -0
- package/package.json +31 -0
package/.npmignore
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 1.1.0 (2023-03-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### :gear: Features
|
|
10
|
+
|
|
11
|
+
* introduce new @scaleway/changesets-renovate package ([#1216](https://github.com/scaleway/scaleway-lib/issues/1216)) ([db88cd0](https://github.com/scaleway/scaleway-lib/commit/db88cd04970fa234a1fb83b5f6f18f2dbbb3c635))
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Scaleway
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# `@scaleway/changesets-renovate`
|
|
2
|
+
|
|
3
|
+
## Automatically create changesets for Renovate
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
$ pnpm add --global @scaleway/changesets-renovate
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
This package is a very simple CLI:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
changesets-renovate
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
It's inspired by this GitHub Action from Backstage: https://github.com/backstage/backstage/blob/master/.github/workflows/sync_renovate-changesets.yml
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import { simpleGit } from 'simple-git';
|
|
4
|
+
|
|
5
|
+
async function getPackagesNames(files) {
|
|
6
|
+
const promises = files.map(async file => {
|
|
7
|
+
const data = JSON.parse(await fs.readFile(file, 'utf8'));
|
|
8
|
+
return data.name;
|
|
9
|
+
});
|
|
10
|
+
return Promise.all(promises);
|
|
11
|
+
}
|
|
12
|
+
async function createChangeset(fileName, packageBumps, packages) {
|
|
13
|
+
let message = '';
|
|
14
|
+
for (const [pkg, bump] of packageBumps) {
|
|
15
|
+
message += `Updated dependency \`${pkg}\` to \`${bump}\`.\n`;
|
|
16
|
+
}
|
|
17
|
+
const pkgs = packages.map(pkg => `'${pkg}': patch`).join('\n');
|
|
18
|
+
const body = `---\n${pkgs}\n---\n\n${message.trim()}\n`;
|
|
19
|
+
await fs.writeFile(fileName, body);
|
|
20
|
+
}
|
|
21
|
+
async function getBumps(files) {
|
|
22
|
+
const bumps = new Map();
|
|
23
|
+
const promises = files.map(async file => {
|
|
24
|
+
const changes = await simpleGit().show([file]);
|
|
25
|
+
for (const change of changes.split('\n')) {
|
|
26
|
+
if (change.startsWith('+ ')) {
|
|
27
|
+
const match = change.match(/"(.*?)"/g);
|
|
28
|
+
if (match !== null && match !== void 0 && match[0] && match[1]) {
|
|
29
|
+
bumps.set(match[0].replace(/"/g, ''), match[1].replace(/"/g, ''));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
await Promise.all(promises);
|
|
35
|
+
return bumps;
|
|
36
|
+
}
|
|
37
|
+
async function run() {
|
|
38
|
+
const branch = await simpleGit().branch(['--show-current']);
|
|
39
|
+
if (!branch.current.startsWith('renovate/')) {
|
|
40
|
+
console.log('Not a renovate branch, skipping');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const diffOutput = await simpleGit().diffSummary(['--name-only', 'HEAD~1']);
|
|
44
|
+
const diffFiles = diffOutput.files.map(file => file.file);
|
|
45
|
+
if (diffFiles.find(f => f.startsWith('.changeset'))) {
|
|
46
|
+
console.log('Changeset already exists, skipping');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const files = diffFiles.filter(file => file.includes('package.json'));
|
|
50
|
+
if (!files.length) {
|
|
51
|
+
console.log('No package.json changes to published packages, skipping');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const packageNames = await getPackagesNames(files);
|
|
55
|
+
const shortHash = await simpleGit().revparse(['--short', 'HEAD']);
|
|
56
|
+
const fileName = `.changeset/renovate-${shortHash.trim()}.md`;
|
|
57
|
+
const packageBumps = await getBumps(files);
|
|
58
|
+
await createChangeset(fileName, packageBumps, packageNames);
|
|
59
|
+
await simpleGit().add(fileName);
|
|
60
|
+
await simpleGit().commit([], undefined, {
|
|
61
|
+
'-C': 'HEAD',
|
|
62
|
+
'--amend': null,
|
|
63
|
+
'--no-edit': null
|
|
64
|
+
});
|
|
65
|
+
await simpleGit().push(['--force']);
|
|
66
|
+
}
|
|
67
|
+
run().catch(console.error);
|
|
68
|
+
|
|
69
|
+
export { run };
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scaleway/changesets-renovate",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Automatically create changesets for Renovate",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"changesets",
|
|
7
|
+
"renovate",
|
|
8
|
+
"sync"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=14.x"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"changesets-renovate": "dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/scaleway/scaleway-lib",
|
|
24
|
+
"directory": "packages/changesets-renovate"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"simple-git": "^3.17.0"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "27e5bbe5e46fdcbde2b16f871a8abbb9db6652ac"
|
|
31
|
+
}
|