Skip to content

Commit

Permalink
Merge pull request #13 from restfulhead/main
Browse files Browse the repository at this point in the history
chore: prepare release
  • Loading branch information
restfulhead authored Feb 16, 2024
2 parents 1665dc8 + ae6dd05 commit bce71da
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 99 deletions.
51 changes: 25 additions & 26 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
for path in ${{ steps.get-workspaces.outputs.ws }}; do
cd $path
topdir=$(pwd)
for workspace in ${{ steps.get-workspaces.outputs.ws }}; do
echo "Potentially going to version and release $workspace"
cd $workspace
mkdir .git
PCKG_NAME=`node -pe "require('./package.json').name"`
Expand All @@ -80,38 +82,35 @@ jobs:
if [ "$CUR_VERSION_NO" != "0.0.0" ]; then
FROM_PARAM="--from ${PCKG_NAME}_v${CUR_VERSION_NO}"
fi
VERSION=`npx auto version $FROM_PARAM`
if [ ! -z "$VERSION" ]; then
echo "::notice title=✅ Detected $VERSION version change for $PCKG_NAME::Bumping version"
npx auto changelog --base-branch ${{ steps.get-workspaces.outputs.branch }} $FROM_PARAM
unpushed_commits=$(git log origin/${{ steps.get-workspaces.outputs.branch }}..${{ steps.get-workspaces.outputs.branch }})
if [ -z "$unpushed_commits" ]; then
echo "No changelog was generated for $PCKG_NAME"
else
npm version $VERSION -m "chore: bump release version to %s [skip ci]"
NEW_VERSION_NO=`node -pe "require('./package.json').version"`
git tag -d v$NEW_VERSION_NO
NEW_TAG=${PCKG_NAME}_v$NEW_VERSION_NO
echo "Going to create a new release for $NEW_TAG"
git add -A
git commit -m "chore: release v$NEW_VERSION_NO [skip ci]"
git tag -a $NEW_TAG -m "chore: tag v$NEW_VERSION_NO [skip ci]"
git push "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY" HEAD:${{ steps.get-workspaces.outputs.branch }} --follow-tags
npx auto release --use-version $NEW_TAG $FROM_PARAM --base-branch ${{ steps.get-workspaces.outputs.branch }}
IS_PRIVATE=`node -pe "require('./package.json').private"`
if [ "$IS_PRIVATE" != "true" ]; then
npm publish ./dist
fi
npm version $VERSION -m "chore: bump release version to %s [skip ci]"
NEW_VERSION_NO=`node -pe "require('./package.json').version"`
git tag -d v$NEW_VERSION_NO
NEW_TAG=${PCKG_NAME}_v$NEW_VERSION_NO
echo "Going to create a new release for $NEW_TAG"
git add -A
git commit -m "chore: release v$NEW_VERSION_NO [skip ci]"
git tag -a $NEW_TAG -m "chore: tag v$NEW_VERSION_NO [skip ci]"
git push "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY" HEAD:${{ steps.get-workspaces.outputs.branch }} --follow-tags
npx auto release --use-version $NEW_TAG $FROM_PARAM --base-branch ${{ steps.get-workspaces.outputs.branch }}
IS_PRIVATE=`node -pe "require('./package.json').private"`
rm -rf .git
if [ "$IS_PRIVATE" != "true" ]; then
cd $topdir
echo "publishing $workspace/dist"
npm publish ./$workspace/dist
echo "::notice title=🚀 ${PCKG_NAME} v$NEW_VERSION_NO::Package versioned and published"
fi
else
echo 'Auto versioning failed.'
echo "::notice title=Versioning of $PCKG_NAME skipped::No relevant changes detected."
exit 1
fi
rm -rf .git
cd -
cd $topdir
done
- if: ${{ always() }}
Expand Down
29 changes: 27 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,32 @@
"changelog",
"-d",
"--from",
"@restfulhead/npm-auto-plugin-example-test-package_v0.0.2"
"@restfulhead/npm-auto-plugin-example-test-package_v0.0.3"
],
"internalConsoleOptions": "openOnSessionStart",
"sourceMaps": true,
"outputCapture": "std",
"smartStep": true,
"skipFiles": [
"<node_internals>/**",
"node_modules/**"
],
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
],
"envFile": "${workspaceFolder}/.env"
},
{
"name": "Auto version",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/packages/example-test-package",
"program": "${workspaceFolder}/node_modules/auto/dist/bin/auto",
"args": [
"version",
"--from",
"@restfulhead/npm-auto-plugin-example-test-package_v0.0.3"
],
"internalConsoleOptions": "openOnSessionStart",
"sourceMaps": true,
Expand All @@ -36,7 +61,7 @@
"args": [
"${relativeFile}",
"--config",
"${workspaceFolder}/packages/filter-by-workspace-path/package.json",
"${workspaceFolder}/packages/filter-by-workspace-path/jest.debug.config.js",
"--testTimeout",
"300000",
"--no-cache",
Expand Down
6 changes: 4 additions & 2 deletions config/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ module.exports = {
rules: {
'unused-imports/no-unused-imports': 'error',
'require-await': 'error',
},
settings: {
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': ['error'],
'@typescript-eslint/await-thenable': 'error',
Expand Down Expand Up @@ -90,6 +88,10 @@ module.exports = {
format: ['camelCase'],
leadingUnderscore: 'forbid',
},
{
selector: 'import',
format: ['camelCase', 'PascalCase'],
},
{
selector: 'default',
format: ['camelCase'],
Expand Down
52 changes: 3 additions & 49 deletions packages/filter-by-workspace-path/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (Fri Feb 16 2024)
# v0.1.0 (Fri Feb 16 2024)

#### 🚀 Enhancement

Expand All @@ -14,7 +14,7 @@

---

# (Fri Feb 16 2024)
# v0.0.1 (Fri Feb 16 2024)

#### 🐛 Patch

Expand All @@ -30,7 +30,7 @@

---

# (Wed Feb 14 2024)
# v0.0.1 (Tue Feb 13 2024)

#### 🔩 Internal

Expand All @@ -40,49 +40,3 @@
#### Authors: 1

- Patrick Ruhkopf ([@restfulhead](https://github.com/restfulhead))

---

# (Tue Feb 13 2024)



---

# (Tue Feb 13 2024)

#### 🚀 Enhancement

- chore: fix release [#30](https://github.com/restfulhead/npm-auto-plugins/pull/30) ([@restfulhead](https://github.com/restfulhead))

#### 🔩 Internal

- chore: prepare release [#32](https://github.com/restfulhead/npm-auto-plugins/pull/32) ([@restfulhead](https://github.com/restfulhead))

#### Authors: 1

- Patrick Ruhkopf ([@restfulhead](https://github.com/restfulhead))

---

# (Mon Feb 12 2024)

#### 🚀 Enhancement

- fix: workflow and release [#25](https://github.com/restfulhead/npm-auto-plugins/pull/25) ([@restfulhead](https://github.com/restfulhead))
- fix: cleanup [#23](https://github.com/restfulhead/npm-auto-plugins/pull/23) ([@restfulhead](https://github.com/restfulhead))

#### 🐛 Patch

- fix: test and release workflow [#28](https://github.com/restfulhead/npm-auto-plugins/pull/28) ([@restfulhead](https://github.com/restfulhead))
- fix: hooks [#21](https://github.com/restfulhead/npm-auto-plugins/pull/21) ([@restfulhead](https://github.com/restfulhead))

#### 🔩 Internal

- chore: prepare release [#29](https://github.com/restfulhead/npm-auto-plugins/pull/29) ([@restfulhead](https://github.com/restfulhead))
- chore: prepare release [#27](https://github.com/restfulhead/npm-auto-plugins/pull/27) ([@restfulhead](https://github.com/restfulhead))
- chore: prepare release [#24](https://github.com/restfulhead/npm-auto-plugins/pull/24) ([@restfulhead](https://github.com/restfulhead))

#### Authors: 1

- Patrick Ruhkopf ([@restfulhead](https://github.com/restfulhead))
11 changes: 5 additions & 6 deletions packages/filter-by-workspace-path/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ However, carefully read the following caveats section.

## Caveats

* Note that this plugin also ommits commits that
* Note that this plugin also omits commits that
* do not have a related pull request (e.g. pushed directly to the release branch)
* belong to pull requests that has the `skip-release` label attached
* have `[skip ci]` in their commit message
* By default, `auto version` seems to set the version to `patch` instead of `noVersion` even if all commits were filtered out.
* Therefore, to detect if there were no changes in this case, you have to use the `auto changelog` command instead and then check whether
a changelog was actually generated. :-/
* While the title in the GitHub release notes is correct, the version is missing in the `CHANGELOG.md` file for currently unknown reasons
* This plugin modifies the behavior of `auto version`. By default, it seems to set the version to `patch` instead of `noVersion` even if all
commits were omitted. With this plugin, `noVersion` is returned if there are no relevant commits.
* You can't use the `shipit` command, because for example, the version in each package should only contain the version number
(e.g. `v1.0.0`), but the tag and Github release must include the package name to avoid ambigious release names/tags.
(e.g. `v1.0.0`), but the tag and Github release must include the package name to avoid ambigious release names/tags. Maybe this
customization can be added to the plugin in future. (Contributions welcome!)
* However, you can use individual commands to make this work. To see how to setup a release process that takes all of this into account,
take a look at the [release.yml GitHub action](../../.github/workflows/release.yml) in this repository.
* If you create merge-commits against your release/target branch, then changes to files in your release/target branch become part of the
Expand Down
36 changes: 29 additions & 7 deletions packages/filter-by-workspace-path/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Auto, IExtendedCommit, ILogger, IPlugin } from '@auto-it/core'
import { execSync } from 'child_process'
import * as path from 'path'
import { Auto, IExtendedCommit, ILogger, IPlugin, SEMVER, inFolder } from '@auto-it/core'
import { inc, ReleaseType } from 'semver'

function shouldOmitCommit(currentDir: string, currentWorkspace: string, commit: IExtendedCommit, logger: ILogger): boolean {
if (!commit.pullRequest) {
Expand All @@ -12,7 +12,8 @@ function shouldOmitCommit(currentDir: string, currentWorkspace: string, commit:
const fixedFiles = commit.files.map((file) => path.relative(currentDir, file))
const wsDir = path.join(currentWorkspace, path.sep)

const atLeastOneFileInCurrentDir = fixedFiles.find((file) => file.startsWith(wsDir))
const atLeastOneFileInCurrentDir = fixedFiles.find((file) => inFolder(wsDir, file))

if (!atLeastOneFileInCurrentDir) {
logger.verbose.log(`All files are outside the current workspace directory ('${wsDir}'). Omitting commit '${commit.hash}'.`)
return true
Expand All @@ -31,16 +32,37 @@ export default class FilterByWorkspacePathPlugin implements IPlugin {
/** The name of the plugin */
name = 'filter-by-workspace-path-plugin'

apply(auto: Auto) {
apply(auto: Auto): void {
const currentDir = path.resolve('.')
const npmResult = execSync('npm ls --omit=dev --depth 1 -json', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'] })
const workspaceDeps: any = JSON.parse(npmResult).dependencies
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const currentWorkspace = workspaceDeps[Object.keys(workspaceDeps)[0] as any].resolved.substring(11)

auto.hooks.onCreateLogParse.tap(this.name, (logParse) => {
logParse.hooks.omitCommit.tap(this.name, (commit) => {
return shouldOmitCommit(currentDir, currentWorkspace, commit, auto.logger) === true ? true : undefined
})
logParse.hooks.omitCommit.tap(this.name, (commit) =>
shouldOmitCommit(currentDir, currentWorkspace, commit, auto.logger) ? true : undefined
)
})

auto.hooks.onCreateRelease.tap(this.name, (release) => {
const origGetVersion = release.getSemverBump.bind(release)
release.getSemverBump = async (from: string, to?: string): Promise<SEMVER> => {
const commits = await release.getCommits(from, to)
if (commits.length === 0) {
auto.logger.verbose.log('No commits found. Skipping release.')
return SEMVER.noVersion
}
return origGetVersion(from, to)
}

release.calcNextVersion = async (lastTag: string) => {
const bump = await release.getSemverBump(lastTag)
const matches = lastTag.match(/(\d+\.\d+\.\d+)/)
const lastVersion = matches ? matches[0] : lastTag

return inc(lastVersion, bump as ReleaseType)
}
})
}
}
15 changes: 8 additions & 7 deletions packages/filter-by-workspace-path/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import * as path from 'path'
import Auto, { SEMVER } from '@auto-it/core'
import makeCommitFromMsg from '@auto-it/core/dist/__tests__/make-commit-from-msg'
import LogParse from '@auto-it/core/dist/log-parse'
import { makeChangelogHooks, makeHooks, makeLogParseHooks, makeReleaseHooks } from '@auto-it/core/dist/utils/make-hooks'
import FilterByPathPlugin from '../src'
import * as path from 'path'
import { makeHooks, makeLogParseHooks, makeReleaseHooks } from '@auto-it/core/dist/utils/make-hooks'
import createLog from '@auto-it/core/dist/utils/logger'
import Release from '@auto-it/core/dist/release'
import Changelog from '@auto-it/core/dist/changelog'
import FilterByPathPlugin from '../src'

const setup = () => {
const plugin = new FilterByPathPlugin()
const hooks = makeHooks()
const logger = createLog()
const logParseHooks = makeLogParseHooks()
const releaseHooks = makeReleaseHooks()
const changeLogHooks = makeChangelogHooks()

plugin.apply({ hooks, logger } as Auto)
hooks.onCreateLogParse.call({ hooks: logParseHooks } as LogParse)
hooks.onCreateRelease.call({ hooks: releaseHooks } as Release)
hooks.onCreateChangelog.call({ hooks: changeLogHooks } as Changelog, { bump: SEMVER.major })
hooks.onCreateRelease.call({
hooks: releaseHooks,
getSemverBump: (from: string, to?: string): Promise<SEMVER> => Promise.resolve(SEMVER.patch),
} as Release)

return logParseHooks
}

Expand Down

0 comments on commit bce71da

Please sign in to comment.