Skip to content

Commit

Permalink
Adds prep-release script
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jul 22, 2024
1 parent 2189adb commit 710ad69
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 3 deletions.
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,46 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Added

- Initial release

[unreleased]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.7.2...HEAD
[4.7.2]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.7.1...v4.7.2
[4.7.1]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.7.0...v4.7.1
[4.7.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.6.0...v4.7.0
[4.6.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.5.0...v4.6.0
[4.5.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.4.0...v4.5.0
[4.4.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.3.0...v4.4.0
[4.3.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.2.0...v4.3.0
[4.2.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.1.0...v4.2.0
[4.1.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.0.0...v4.1.0
[4.0.4]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.0.3...v4.0.4
[4.0.3]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.0.2...v4.0.3
[4.0.2]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.0.1...v4.0.2
[4.0.1]: https://github.com/eamodio/vscode-amethyst-theme/compare/v4.0.0...v4.0.1
[4.0.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v3.0.0...v4.0.0
[3.0.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.0.5...v3.0.0
[2.6.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.5.0...v2.6.0
[2.5.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.4.0...v2.5.0
[2.4.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.3.0...v2.4.0
[2.3.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.2.0...v2.3.0
[2.2.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.1.0...v2.2.0
[2.1.1]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.1.0...v2.1.1
[2.1.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.0.0...v2.1.0
[2.0.8]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.0.7...v2.0.8
[2.0.7]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.0.6...v2.0.7
[2.0.6]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.0.5...v2.0.6
[2.0.5]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.0.4...v2.0.5
[2.0.4]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.0.3...v2.0.4
[2.0.3]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.0.2...v2.0.3
[2.0.2]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.0.1...v2.0.2
[2.0.1]: https://github.com/eamodio/vscode-amethyst-theme/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v1.0.0...v2.0.0
[1.1.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v0.3.1...v1.0.0
[0.5.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v0.3.1...v0.4.0
[0.3.1]: https://github.com/eamodio/vscode-amethyst-theme/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v0.2.1...v0.3.0
[0.2.1]: https://github.com/eamodio/vscode-amethyst-theme/compare/v0.1.0...v0.2.1
[0.1.0]: https://github.com/eamodio/vscode-amethyst-theme/compare/v0.0.2...v0.1.0
[0.0.2]: https://github.com/eamodio/vscode-amethyst-theme/compare/v0.0.1...v0.0.2
[0.0.1]: https://github.com/eamodio/vscode-amethyst-theme/releases/tag/v0.0.1
26 changes: 23 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ git clone https://github.com/eamodio/vscode-amethyst-theme.git
Prerequisites

- [Git](https://git-scm.com/)
- [NodeJS](https://nodejs.org/), `>= 10.11.0`
- [yarn](https://yarnpkg.com/), `>= 1.17.3`
- [NodeJS](https://nodejs.org/), `>= 20`
- [yarn](https://yarnpkg.com/), `>= 1.22.22`

### Dependencies

From a terminal, where you have cloned the repository, execute the following command to install the required dependencies:

```
yarn --frozen-lockfile
yarn
```

### Formatting
Expand Down Expand Up @@ -61,3 +61,23 @@ yarn run pack
## Submitting a Pull Request

Please follow all the instructions in the [PR template](.github/PULL_REQUEST_TEMPLATE.md).

## Publishing

### Stable Releases

Use the [prep-release](scripts/prep-release.js) script to prepare a new release. The script updates the [package.json](package.json) and [CHANGELOG.md](CHANGELOG.md) appropriately, commits the changes as `Bumps to v{major}.{minor}.{patch}`, and creates a `v{major}.{minor}.{patch}` tag which when pushed will trigger the CI to publish a release.

1. Ensure you are on the `main` branch and have a clean working tree
2. Ensure the [CHANGELOG.md](CHANGELOG.md) has been updated with the release notes
3. Run `yarn run prep-release` and enter the desired `{major}.{minor}.{patch}` version when prompted
4. Review the `Bumps to v{major}.{minor}.{patch}` commit
5. Run `git push --follow-tags` to push the commit and tag

Pushing the `v{major}.{minor}.{patch}` tag will trigger the [Publish Stable workflow](.github/workflows/cd-stable.yml) to automatically package the extension, create a [GitHub release](https://github.com/eamodio/vscode-amethyst-theme/releases/latest), and deploy it to the [VS Marketplace](https://marketplace.visualstudio.com/items?itemName=amodio.amethyst-theme).

If the action fails and retries are unsuccessful, the VSIX can be built locally with `yarn package` and uploaded manually to the marketplace. A GitHub release can also be [created manually](https://github.com/eamodio/vscode-amethyst-theme/releases/new) using `v{major}.{minor}.{patch}` as the title and the notes from the [CHANGELOG.md](CHANGELOG.md) with the VSIX attached.

### Pre-releases

The [Publish Pre-release workflow](.github/workflows/cd-pre.yml) is automatically run every AM unless no new changes have been committed to `main`. This workflow can also be manually triggered by running the `Publish Pre-release` workflow from the Actions tab, no more than once per hour (because of the versioning scheme).
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"package": "vsce package --yarn",
"package-pre": "yarn run patch-pre && yarn run package --pre-release",
"patch-pre": "node ./scripts/applyPreReleasePatch.js",
"prep-release": "node ./scripts/prep-release.js",
"pretty": "prettier --config .prettierrc --loglevel warn --write .",
"pub": "vsce publish --yarn",
"pub-pre": "vsce publish --yarn --pre-release",
Expand Down
78 changes: 78 additions & 0 deletions scripts/prep-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const { exec } = require('child_process');
const fs = require('fs');
const readline = require('readline');
const path = require('path');

const versionRegex = /^\d{1,4}\.\d{1,4}\.\d{1,4}$/;

const changelogPath = path.join(__dirname, '..', 'CHANGELOG.md');
console.log(changelogPath);
let data = fs.readFileSync(changelogPath, 'utf8');

// Find the current version number
const match = /\[unreleased\]: https:\/\/github\.com\/eamodio\/vscode-amethyst-theme\/compare\/v(.+)\.\.\.HEAD/.exec(
data,
);
const currentVersion = match?.[1];
if (currentVersion == null || versionRegex.test(currentVersion) === false) {
console.error('Unable to find current version number.');
return;
}

// Create readline interface for getting input from user
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

// Ask for new version number
rl.question(`Enter the new version number (format x.x.x, current is ${currentVersion}): `, function (version) {
// Validate the version input
if (!versionRegex.test(version)) {
console.error(
'Invalid version number. Please use the format x.y.z where x, y, and z are positive numbers no greater than 4 digits.',
);
rl.close();
return;
}

// Get today's date
const today = new Date();
const yyyy = today.getFullYear();
const mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
const dd = String(today.getDate()).padStart(2, '0');

const newVersionHeader = `## [Unreleased]\n\n## [${version}] - ${yyyy}-${mm}-${dd}`;
const newVersionLink = `[${version}]: https://github.com/eamodio/vscode-amethyst-theme/compare/v${currentVersion}...v${version}`;

// Add the new version header below the ## [Unreleased] header
data = data.replace('## [Unreleased]', newVersionHeader);

const unreleasedLink = match[0].replace(/\/compare\/v(.+?)\.\.\.HEAD/, `/compare/v${version}...HEAD`);

// Update the [unreleased]: line
data = data.replace(match[0], `${unreleasedLink}\n${newVersionLink}`);

// Writing the updated version data to CHANGELOG
fs.writeFileSync(changelogPath, data);

// Stage CHANGELOG
exec('git add CHANGELOG.md', err => {
if (err) {
console.error(`Unable to stage CHANGELOG.md: ${err}`);
return;
}

// Call 'yarn version' to commit and create the tag
exec(`yarn version --new-version ${version}`, err => {
if (err) {
console.error(`'yarn version' failed: ${err}`);
return;
}

console.log(`${version} is ready for release.`);
});
});

rl.close();
});

0 comments on commit 710ad69

Please sign in to comment.