-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release @itwin/presentation-rules-editor-react@0.1.0 (#79)
- Loading branch information
Showing
4 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,5 +75,3 @@ stages: | |
parameters: | ||
path: $(tarballName) | ||
artifactName: published-package | ||
dryrun: true | ||
releaseTag: pre-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import { execSync } from "child_process"; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
|
||
const packageJsonFilePath = path.join(process.cwd(), "package.json"); | ||
if (!fs.existsSync(packageJsonFilePath)) { | ||
console.error(`File "${packageJsonFilePath}" does not exist.`); | ||
process.exit(1); | ||
} | ||
|
||
const packageJson = JSON.parse(String(fs.readFileSync(packageJsonFilePath))); | ||
const packageName: string = packageJson.name; | ||
if (!packageName) { | ||
console.error("Could not obtain package name."); | ||
process.exit(1); | ||
} | ||
|
||
const packageVersion: string = packageJson.version; | ||
if (!packageVersion) { | ||
console.error("Could not obtain package version."); | ||
process.exit(1); | ||
} | ||
|
||
const changelogFilePath = path.join(process.cwd(), "CHANGELOG.md"); | ||
if (!fs.existsSync(changelogFilePath)) { | ||
console.error(`File "${changelogFilePath}" does not exist.`); | ||
process.exit(1); | ||
} | ||
|
||
const changelogContent = String(fs.readFileSync(changelogFilePath)); | ||
const unreleasedHeaderStartPosition = changelogContent.indexOf("## [Unreleased]"); | ||
if (unreleasedHeaderStartPosition === -1) { | ||
console.error("Could not find Unreleased section."); | ||
process.exit(1); | ||
} | ||
|
||
const unreleasedHeaderEndPosition = changelogContent.indexOf("\n", unreleasedHeaderStartPosition); | ||
if (unreleasedHeaderEndPosition === -1) { | ||
console.error("Changelog file cannot end with Unreleased section without listed changes."); | ||
process.exit(1); | ||
} | ||
|
||
const unreleasedHeader = changelogContent.substring(unreleasedHeaderStartPosition, unreleasedHeaderEndPosition); | ||
const releaseHeader = unreleasedHeader | ||
.replace("Unreleased", packageVersion) | ||
.replace("HEAD", `v${packageVersion}`) | ||
.concat(` - ${formatDate(new Date())}`); | ||
|
||
const updatedChangelogContent = changelogContent | ||
.slice(0, unreleasedHeaderEndPosition) | ||
.concat("\n\n", releaseHeader, changelogContent.slice(unreleasedHeaderEndPosition)); | ||
|
||
fs.writeFileSync(changelogFilePath, updatedChangelogContent); | ||
|
||
try { | ||
execSync(`git add ${packageJsonFilePath} ${changelogFilePath}`); | ||
execSync(`git commit -e -m \"Release ${packageName}@${packageVersion}\"`); | ||
} catch (error) { | ||
console.error(error instanceof Error ? `${error.name}: ${error.message}` : "Could not commit file changes."); | ||
process.exit(1); | ||
} | ||
|
||
function formatDate(date: Date): string { | ||
return `${date.getUTCFullYear()}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())}`; | ||
|
||
function pad(component: number): string { | ||
return String(component).padStart(2, "0"); | ||
} | ||
} |