-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tools): setup custom versioning and changelog scripts
- Loading branch information
Showing
17 changed files
with
525 additions
and
760 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
name: Publish Releases | ||
|
||
env: | ||
NODE_VERSION: '>=18.5.0' | ||
PNPM_VERSION: 8.6 | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
|
||
concurrency: | ||
group: publishReleases-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
publishReleases: | ||
name: 'Publish releases' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: 'Setup project' | ||
uses: ./.github/actions/setup-project | ||
|
||
- name: Publish pending releases | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
pnpm exec changelogen gh 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
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,9 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
pnpm prettier-check | ||
pnpm type-check | ||
pnpm lint | ||
pnpm publint | ||
pnpm build | ||
pnpm test:ci |
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,10 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Check if there are uncommitted changes | ||
if [ -n "$(git status -s)" ]; then | ||
echo "Error: There are uncommitted changes in the repository." | ||
exit 1 | ||
fi | ||
|
||
node .scripts/set-version.cjs "$(node .scripts/get-semver.cjs ${1:-"patch"})" || exit 1 | ||
node .scripts/match-versions.cjs || exit 1 |
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,28 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const semver = require('semver') | ||
|
||
// Read the root package.json to get the current version | ||
const CWD = process.cwd() | ||
const rootPackagePath = path.resolve(path.join(CWD, 'package.json')) | ||
const rootPackageContent = fs.readFileSync(rootPackagePath, 'utf-8') | ||
const rootPackage = JSON.parse(rootPackageContent) | ||
const currentVersion = rootPackage.version || '0.0.0' | ||
|
||
// Get the desired level from the command line argument (default to "patch") | ||
const desiredLevel = process.argv[2] || 'patch' | ||
|
||
if (desiredLevel === 'current') { | ||
console.log(currentVersion) | ||
process.exit(0) | ||
} | ||
|
||
// Calculate the next version based on the desired level | ||
const nextVersion = semver.inc(currentVersion, desiredLevel) | ||
|
||
if (!nextVersion) { | ||
console.error('Invalid version level specified. Please use "patch", "minor", or "major".') | ||
process.exit(1) | ||
} | ||
|
||
console.log(nextVersion) |
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,52 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const workspaces = ['packages'] | ||
|
||
// Read the root package.json to get the desired version | ||
const CWD = process.cwd() | ||
const rootPackagePath = path.resolve(path.join(CWD, 'package.json')) | ||
const rootPackageContent = fs.readFileSync(rootPackagePath, 'utf-8') | ||
const rootPackage = JSON.parse(rootPackageContent) | ||
const desiredVersion = rootPackage.version | ||
|
||
if (!desiredVersion) { | ||
rootPackage.version = '0.0.1' | ||
fs.writeFileSync(rootPackagePath, JSON.stringify(rootPackage, null, 2) + '\n') | ||
} | ||
|
||
function updateWorkspacePackages(workspaceDir) { | ||
// Get a list of package directories | ||
const packagesDir = path.resolve(path.join(CWD, workspaceDir)) | ||
const packageDirs = fs | ||
.readdirSync(packagesDir, { withFileTypes: true }) | ||
.filter(dirent => dirent.isDirectory()) | ||
.map(dirent => dirent.name) | ||
|
||
// Update versions in each package's package.json | ||
packageDirs.forEach(packageName => { | ||
const packagePath = path.join(packagesDir, packageName, 'package.json') | ||
if (!fs.existsSync(packagePath)) { | ||
console.log(`No package.json found in ${packageName}`) | ||
return | ||
} | ||
|
||
const packageContent = fs.readFileSync(packagePath, 'utf-8') | ||
const packageData = JSON.parse(packageContent) | ||
|
||
if (packageData.version !== desiredVersion) { | ||
packageData.version = desiredVersion | ||
fs.writeFileSync(packagePath, JSON.stringify(packageData, null, 2) + '\n') | ||
console.log(`Updated version in ${packageName}/package.json`) | ||
} else { | ||
console.log(`${packageName}/package.json is already up to date`) | ||
} | ||
}) | ||
} | ||
|
||
function main() { | ||
workspaces.forEach(updateWorkspacePackages) | ||
console.log('Version update process complete.') | ||
} | ||
|
||
main() |
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,26 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const semver = require('semver') | ||
|
||
// Read the root package.json | ||
const CWD = process.cwd() | ||
const rootPackagePath = path.resolve(path.join(CWD, 'package.json')) | ||
const rootPackageContent = fs.readFileSync(rootPackagePath, 'utf-8') | ||
const rootPackage = JSON.parse(rootPackageContent) | ||
|
||
// Get the version from the command line argument | ||
const desiredVersion = process.argv[2] | ||
|
||
// Check if the desired version is a valid semver | ||
if (!semver.valid(desiredVersion)) { | ||
console.error('Invalid version format. Please provide a valid semver version.') | ||
process.exit(1) | ||
} | ||
|
||
// Set the desired version in the package.json | ||
rootPackage.version = desiredVersion | ||
|
||
// Write the updated package.json back to the file | ||
fs.writeFileSync(rootPackagePath, JSON.stringify(rootPackage, null, 2) + '\n') | ||
|
||
console.log(`Version updated to: ${desiredVersion}`) |
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,23 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Check if there are changes in package.json & **/package.json | ||
if git diff --quiet --exit-code -- package.json '**/package.json'; then | ||
echo "Error: None of the package.json files have been changed." | ||
exit 1 | ||
fi | ||
|
||
CURRENT_VERSION=$(node .scripts/get-semver.cjs current) | ||
# FIRST_TAG=$(git tag | sort -V | head -n 1) | ||
|
||
echo "Current Version: ${CURRENT_VERSION}" | ||
|
||
# Prepend content to CHANGELOG.md | ||
existing_CHANGELOG=$(cat CHANGELOG.md) | ||
new_CHANGELOG=$(pnpm exec changelogen -r "${CURRENT_VERSION}") | ||
|
||
echo "${new_CHANGELOG}\n${existing_CHANGELOG}" > CHANGELOG.md | ||
|
||
# Create a new commit and tag with the current version | ||
git add CHANGELOG.md package.json **/package.json pnpm-lock.yaml | ||
git commit -m "chore(release): bump version to v${CURRENT_VERSION}" || exit 1 | ||
git tag -a "v${CURRENT_VERSION}" -m "v${CURRENT_VERSION}" || exit 1 |
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
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
Oops, something went wrong.