Skip to content

Commit ec729f4

Browse files
authored
Add release-plz (open-feature#63)
Signed-off-by: Todd Baert <[email protected]>
1 parent 8ec3eb4 commit ec729f4

File tree

9 files changed

+181
-17
lines changed

9 files changed

+181
-17
lines changed

Diff for: .github/workflows/lint-pr.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: 'Lint PR'
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
jobs:
11+
main:
12+
name: Validate PR title
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: amannn/action-semantic-pull-request@v4
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Diff for: .github/workflows/release-please.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
name: Run Release Please
6+
jobs:
7+
release-please:
8+
runs-on: ubuntu-latest
9+
10+
# Release-please creates a PR that tracks all changes
11+
steps:
12+
- uses: google-github-actions/release-please-action@v3
13+
id: release
14+
with:
15+
command: manifest
16+
token: ${{secrets.GITHUB_TOKEN}}
17+
default-branch: main
18+
19+
# The logic below handles the npm publication:
20+
- name: Checkout Repository
21+
if: ${{ steps.release.outputs.releases_created }}
22+
uses: actions/checkout@v2
23+
- name: Setup Node
24+
uses: actions/setup-node@v3
25+
if: ${{ steps.release.outputs.releases_created }}
26+
with:
27+
node-version: 16
28+
registry-url: 'https://registry.npmjs.org'
29+
- name: Build Packages
30+
if: ${{ steps.release.outputs.releases_created }}
31+
run: |
32+
npm install
33+
npm run build
34+
35+
# Release Please has already incremented versions and published tags, so we just
36+
# need to publish all unpublished versions to NPM here
37+
# Our scripts only publish versions that do not already exist.
38+
- name: Publish to NPM
39+
if: ${{ steps.release.outputs.releases_created }}
40+
env:
41+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
42+
run: npm run publish

Diff for: .release-please-manifest.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"libs/hooks/open-telemetry": "1.0.6-alpha"
3+
}

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ The project includes:
1010
- [Providers](./libs/providers)
1111
- [Hooks](./libs/hooks)
1212

13+
## Releases
14+
15+
This repo uses _Release Please_ to release packages. Release Please sets up a running PR that tracks all changes for the library components, and maintains the versions according to [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/), generated when [PRs are merged](https://github.com/amannn/action-semantic-pull-request). When Release Please's running PR is merged, any changed artifacts are published.
16+
1317
## License
1418

1519
Apache 2.0 - See [LICENSE](./license) for more information.

Diff for: libs/hooks/open-telemetry/package.json

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
{
22
"name": "@openfeature/open-telemetry-hook",
3-
"version": "0.0.1",
4-
"type": "commonjs"
5-
}
3+
"version": "1.0.6-alpha",
4+
"type": "commonjs",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/open-feature/node-sdk-contrib.git",
8+
"directory": "libs/hooks/open-telemetry"
9+
},
10+
"publishConfig": {
11+
"access": "public"
12+
},
13+
"scripts": {
14+
"publish-if-not-exists": "cp $NPM_CONFIG_USERCONFIG .npmrc && if [[ $(npm show $npm_package_name@$npm_package_version version) = $(npm run current-version -s) ]]; then echo 'already published, skipping'; else npm publish --access public; fi",
15+
"current-version": "echo $npm_package_version"
16+
},
17+
"license": "Apache-2.0"
18+
}

Diff for: libs/hooks/open-telemetry/project.json

+28-10
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@
55
"targets": {
66
"package": {
77
"executor": "@nrwl/web:rollup",
8-
"outputs": ["{options.outputPath}"],
8+
"outputs": [
9+
"{options.outputPath}"
10+
],
911
"options": {
1012
"project": "libs/hooks/open-telemetry/package.json",
1113
"outputPath": "dist/libs/hooks/open-telemetry",
1214
"entryFile": "libs/hooks/open-telemetry/src/index.ts",
1315
"tsConfig": "libs/hooks/open-telemetry/tsconfig.lib.json",
1416
"compiler": "babel",
1517
"umdName": "OpenTelemetry",
16-
"external": ["typescript"],
17-
"format": ["cjs", "esm"],
18+
"external": [
19+
"typescript"
20+
],
21+
"format": [
22+
"cjs",
23+
"esm"
24+
],
1825
"assets": [
1926
{
2027
"glob": "LICENSE",
@@ -31,18 +38,23 @@
3138
},
3239
"build": {
3340
"executor": "@nrwl/js:tsc",
34-
"outputs": ["{options.outputPath}"],
41+
"outputs": [
42+
"{options.outputPath}"
43+
],
3544
"options": {
3645
"outputPath": "dist/libs/hooks/open-telemetry",
3746
"main": "libs/hooks/open-telemetry/src/index.ts",
3847
"tsConfig": "libs/hooks/open-telemetry/tsconfig.lib.json",
39-
"assets": ["libs/hooks/open-telemetry/*.md"]
48+
"assets": [
49+
"libs/hooks/open-telemetry/*.md"
50+
]
4051
}
4152
},
4253
"publish": {
4354
"executor": "@nrwl/workspace:run-commands",
4455
"options": {
45-
"command": "node tools/scripts/publish.mjs hooks-open-telemetry {args.ver} {args.tag}"
56+
"command": "npm run publish-if-not-exists",
57+
"cwd": "dist/libs/hooks/open-telemetry"
4658
},
4759
"dependsOn": [
4860
{
@@ -53,19 +65,25 @@
5365
},
5466
"lint": {
5567
"executor": "@nrwl/linter:eslint",
56-
"outputs": ["{options.outputFile}"],
68+
"outputs": [
69+
"{options.outputFile}"
70+
],
5771
"options": {
58-
"lintFilePatterns": ["libs/hooks/open-telemetry/**/*.ts"]
72+
"lintFilePatterns": [
73+
"libs/hooks/open-telemetry/**/*.ts"
74+
]
5975
}
6076
},
6177
"test": {
6278
"executor": "@nrwl/jest:jest",
63-
"outputs": ["coverage/libs/hooks/open-telemetry"],
79+
"outputs": [
80+
"coverage/libs/hooks/open-telemetry"
81+
],
6482
"options": {
6583
"jestConfig": "libs/hooks/open-telemetry/jest.config.ts",
6684
"passWithNoTests": true
6785
}
6886
}
6987
},
7088
"tags": []
71-
}
89+
}

Diff for: package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"name": "node-sdk-contrib",
33
"version": "0.0.0",
4-
"license": "MIT",
4+
"license": "Apache-2.0",
55
"scripts": {
66
"generate-hook": "nx workspace-generator open-feature hook",
77
"generate-provider": "nx workspace-generator open-feature provider",
8-
"test": "nx run-many --all --target=test"
8+
"test": "nx run-many --all --target=test",
9+
"build": "npx nx run-many --all --target=build",
10+
"publish": "npx nx run-many --all --target=publish"
911
},
1012
"private": true,
1113
"dependencies": {
@@ -37,4 +39,4 @@
3739
"ts-node": "~10.8.0",
3840
"typescript": "~4.7.2"
3941
}
40-
}
42+
}

Diff for: release-please-config.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"bootstrap-sha": "8ec3eb4db55b7c2d6c2d7edc7c7f3c147b47fd35",
3+
"packages": {
4+
"libs/hooks/open-telemetry": {
5+
"releaseType": "node",
6+
"prerelease": true,
7+
"bumpMinorPreMajor": false,
8+
"bumpPatchForMinorPreMajor": false,
9+
"changelogPath": "CHANGELOG.md",
10+
"versioning": "default"
11+
}
12+
}
13+
}

Diff for: tools/generators/open-feature/index.ts

+53-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ export default async function (tree: Tree, schema: SchemaOptions) {
7777

7878
updateProject(tree, projectRoot, name);
7979
updateTsConfig(tree, projectRoot);
80+
updatePackage(tree, projectRoot);
81+
updateReleasePleaseConfig(tree, projectRoot);
82+
updateReleasePleaseManifest(tree, projectRoot);
8083
await formatFiles(tree);
8184

8285
return () => {
@@ -143,17 +146,66 @@ function updateProject(tree: Tree, projectRoot: string, umdName: string) {
143146
},
144147
};
145148

146-
json.targets.publish.dependsOn[0].target = 'package';
149+
// add publishing
150+
json.targets['publish'] = {
151+
executor: '@nrwl/workspace:run-commands',
152+
options: {
153+
command: 'npm run publish-if-not-exists',
154+
cwd: `dist/${projectRoot}`,
155+
},
156+
dependsOn: [
157+
{
158+
projects: 'self',
159+
target: 'package',
160+
},
161+
],
162+
};
147163
delete json.targets.build;
148164

149165
return json;
150166
});
151167
}
152168

169+
function updatePackage(tree: Tree, projectRoot: string) {
170+
updateJson(tree, joinPathFragments(projectRoot, 'package.json'), (json) => {
171+
json.scripts = {
172+
'publish-if-not-exists':
173+
"cp $NPM_CONFIG_USERCONFIG .npmrc && if [[ $(npm show $npm_package_name@$npm_package_version version) = $(npm run current-version -s) ]]; then echo 'already published, skipping'; else npm publish --access public; fi",
174+
'current-version': 'echo $npm_package_version',
175+
};
176+
177+
return json;
178+
});
179+
}
180+
153181
function updateTsConfig(tree: Tree, projectRoot: string) {
154182
updateJson(tree, joinPathFragments(projectRoot, 'tsconfig.json'), (json) => {
155183
json.compilerOptions.module = 'ES6';
156184

157185
return json;
158186
});
159187
}
188+
189+
function updateReleasePleaseConfig(tree: Tree, projectRoot: string) {
190+
updateJson(tree, 'release-please-config.json', (json) => {
191+
json.packages[projectRoot] = {
192+
releaseType: 'node',
193+
prerelease: true,
194+
bumpMinorPreMajor: true,
195+
bumpPatchForMinorPreMajor: false,
196+
changelogPath: 'CHANGELOG.md',
197+
versioning: 'default',
198+
};
199+
200+
return json;
201+
});
202+
}
203+
204+
// this starts everything at 0.1.0
205+
function updateReleasePleaseManifest(tree: Tree, projectRoot: string) {
206+
updateJson(tree, '.release-please-manifest.json', (json) => {
207+
json[projectRoot] = '0.1.0';
208+
209+
return json;
210+
});
211+
}

0 commit comments

Comments
 (0)