Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add script to update changelogs on release preparation #4315

Merged
12 changes: 3 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,8 @@ There are no changes between 1.0.0 and the previous 0.33.0 version.

* fix(sdk-web): parse url with relative url string [#2972](https://github.com/open-telemetry/opentelemetry-js/pull/2972) @legendecas

### :books: (Refine Doc)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cleanup was done by the script when I ran it locally. It removes all empty sub-sections.


### :house: (Internal)

## 1.2.0

### :boom: Breaking Change

### :rocket: (Enhancement)

### :bug: (Bug Fix)

* fix: sanitize attributes inputs [#2881](https://github.com/open-telemetry/opentelemetry-js/pull/2881) @legendecas
Expand Down Expand Up @@ -2290,7 +2282,9 @@ Released 2020-03-19

Released 2020-03-16

### This is a first official beta release, which provides almost fully complete metrics, tracing, and context propagation functionality but makes no promises around breaking changes
### First official beta release

* provides almost fully complete metrics, tracing, and context propagation functionality but makes **no promises** around breaking changes

### :boom: Breaking Change

Expand Down
14 changes: 0 additions & 14 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ All notable changes to experimental packages in this project will be documented
* fix(instrumentation-fetch): only access navigator if it is defined [#4063](https://github.com/open-telemetry/opentelemetry-js/pull/4063)
* allows for experimental usage of this instrumentation with non-browser runtimes

### :books: (Refine Doc)

### :house: (Internal)

## 0.45.1

### :bug: (Bug Fix)
Expand Down Expand Up @@ -183,8 +179,6 @@ All notable changes to experimental packages in this project will be documented

* doc(instrumentation): add limitiations section to readme [#3786](https://github.com/open-telemetry/opentelemetry-js/pull/3786) @flarna

### :house: (Internal)

## 0.38.0

### :boom: Breaking Change
Expand Down Expand Up @@ -401,10 +395,6 @@ All notable changes to experimental packages in this project will be documented
* fix(histogram): fix maximum when only values < -1 are provided [#3086](https://github.com/open-telemetry/opentelemetry-js/pull/3086) @pichlermarc
* fix(instrumentation-grpc): always set grpc semcov status code attribute with numeric value [#3076](https://github.com/open-telemetry/opentelemetry-js/pull/3076) @blumamir

### :books: (Refine Doc)

### :house: (Internal)

## 0.30.0

### :boom: Breaking Change
Expand Down Expand Up @@ -479,10 +469,6 @@ All notable changes to experimental packages in this project will be documented
* fix(metrics): specification compliant default metric unit [#2983](https://github.com/open-telemetry/opentelemetry-js/pull/2983) @andyfleming
* fix(opentelemetry-instrumentation): use all provided patches for the same file [#2963](https://github.com/open-telemetry/opentelemetry-js/pull/2963) @Ugzuzg

### :books: (Refine Doc)

### :house: (Internal)

## 0.28.0

### :boom: Breaking Change
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@

"comment_prepare_1": "echo scripts in this section automatically prepare releases. Intended for use by maintainers only.",
"comment_prepare_2": "echo experimental preparation scripts only prepare experimental packages",
"prepare_release:experimental:patch": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:remove_stable && npm run _lerna:version_patch && npm run _restore:package-json",
"prepare_release:experimental:minor": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:remove_stable && npm run _lerna:version_minor && npm run _restore:package-json",
"prepare_release:experimental:patch": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:remove_stable && npm run _lerna:version_patch && npm run _restore:package-json && npm run _changelog:prepare_experimental",
"prepare_release:experimental:minor": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:remove_stable && npm run _lerna:version_minor && npm run _restore:package-json && npm run _changelog:prepare_experimental",
"comment_prepare_3": "echo sdk preparation scripts prepare all stable and experimental packages",
"prepare_release:sdk:patch": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:version_patch && npm run _restore:package-json",
"prepare_release:sdk:minor": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:version_minor && npm run _restore:package-json",
"prepare_release:sdk:patch": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:version_patch && npm run _restore:package-json && npm run _changelog:prepare_experimental && npm run _changelog:preapare_stable",
"prepare_release:sdk:minor": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:version_minor && npm run _restore:package-json && npm run _changelog:prepare_experimental && npm run _changelog:preapare_stable",
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved
"release:publish": "lerna publish from-package --no-push --no-private --no-git-tag-version --no-verify-access",

"comment_internal": "echo scripts below this line are for internal use",
Expand All @@ -51,7 +51,9 @@
"_lerna:remove_api": "node -e 'var fs=require(\"fs\");var p=require(\"./package.json\");p.workspaces=p.workspaces.filter(p=>p!==\"api\");fs.writeFileSync(\"package.json\",JSON.stringify(p,null,2))'",
"_lerna:remove_stable": "node -e 'var fs=require(\"fs\");var p=require(\"./package.json\");p.workspaces=p.workspaces.filter(p=>p!==\"packages/*\");fs.writeFileSync(\"package.json\",JSON.stringify(p,null,2))'",
"_lerna:version_patch": "npx lerna version patch --exact --no-git-tag-version --no-push --yes",
"_lerna:version_minor": "npx lerna version minor --exact --no-git-tag-version --no-push --yes"
"_lerna:version_minor": "npx lerna version minor --exact --no-git-tag-version --no-push --yes",
"_changelog:prepare_experimental": "node scripts/update-changelog.js ./experimental/CHANGELOG.md ./experimental/packages/",
"_changelog:preapare_stable": "node scripts/update-changelog.js ./CHANGELOG.md ./packages/"
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved
},
"repository": "open-telemetry/opentelemetry-js",
"keywords": [
Expand Down
60 changes: 60 additions & 0 deletions scripts/update-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const fs = require('fs');
const path = require("path");

const EMPTY_UNRELEASED_SECTION = `## Unreleased

### :boom: Breaking Change

### :rocket: (Enhancement)

### :bug: (Bug Fix)

### :books: (Refine Doc)

### :house: (Internal)

`

function findFirstPackageVersion(basePath){
const packageDirs = fs.readdirSync(basePath);
for(const packageDir of packageDirs){
const packageJsonPath = path.join(basePath, packageDir, 'package.json');
try {
const packageJson = fs.readFileSync(packageJsonPath, 'utf-8');
const version = JSON.parse(packageJson).version;

if(version != null){
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved
return version;
}

console.log('Version in', packageJsonPath, 'was null or undefined, skipping');
} catch (err) {
console.log('Could not get package JSON', packageJsonPath, err);
}
}
throw new Error('Unable to extract version from packages in ' + basePath);
}

function replaceEmptySection(changelog){
// Only match ## at the end in case the last header does not have any entries and the next one is '## version',
// this makes it safe to replace with only '##'
return changelog.replace(RegExp('###.*\n*##', 'gm'), '##');
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved
}

// no special handling for bad args as this is only intended for use via predefined npm scripts.
const changelogPath = path.resolve(process.argv[2]);
const version = findFirstPackageVersion(path.resolve(process.argv[3]));
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved

let changelog = fs.readFileSync(changelogPath, 'utf8').toString();
let previousChangelog = replaceEmptySection(changelog);

// keep replacing until there's nothing to replace anymore
while(changelog !== previousChangelog){
previousChangelog = changelog;
changelog = replaceEmptySection(changelog);
}

// replace unreleased header with new unreleased section and a version header for the former unreleased section
changelog = changelog.replace(RegExp('## Unreleased'), EMPTY_UNRELEASED_SECTION + '## ' + version);

fs.writeFileSync(changelogPath, changelog);