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

CalVer "Zero-padded month" format does not work #754

Closed
SimoneCusimano opened this issue Apr 10, 2021 · 1 comment
Closed

CalVer "Zero-padded month" format does not work #754

SimoneCusimano opened this issue Apr 10, 2021 · 1 comment

Comments

@SimoneCusimano
Copy link

Hello,
I would like to use release-it with the plugin that adds Calendar Versioning support (@csmith/release-it-calver-plugin).

When using the YY.0M.MICRO format, I get the following error: ERROR Cannot read property 'prerelease' of null

I checked and the issue derives from the implementation of parseVersion function implemented here "./lib/util.js" and invoked here in "./lib/tasks.js".

Let's consider the statement in parseVersion const version = semver.valid(raw) ? raw: semver.coerce(raw); (row 76).
A version like 21.04.1 does not pass the validation above because 04 (Zero-padded month) is not a valid SemVer format. Then, execution continues with a "version" equals "null" and row 78 generates the mentioned error.

Here are the logs with the configuration and the environment I am using:

$ DEBUG=release-it:* release-it --ci
2021-04-10T15:56:09.872Z release-it:config {
  cosmiconfig: {
    config: { verbose: 2, npm: [Object], plugins: [Object] },
    filepath: 'C\\SOURCE_CODE_PATH\\.release-it.json'
  }
}
2021-04-10T15:56:10.054Z release-it:config {
  system: { 'release-it': '14.6.0', node: 'v12.14.1', os: 'Windows 10' }
}
2021-04-10T15:56:10.055Z release-it:config {
  _: [],
  ci: true,
  increment: undefined,
  verbose: 2,
  npm: {
    publish: false,
    publishPath: '.',
    publishArgs: [],
    tag: null,
    otp: null,
    ignoreVersion: false,
    skipChecks: false,
    timeout: 10
  },
  plugins: { '@csmith/release-it-calver-plugin': { format: 'YY.0M.MICRO' } },
  hooks: {},
  git: {
    changelog: 'git log --pretty=format:"* %s (%h)" ${from}...${to}',
    requireCleanWorkingDir: true,
    requireBranch: false,
    requireUpstream: true,
    requireCommits: false,
    addUntrackedFiles: false,
    commit: true,
    commitMessage: 'Release ${version}',
    commitArgs: [],
    tag: true,
    tagName: null,
    tagAnnotation: 'Release ${version}',
    tagArgs: [],
    push: true,
    pushArgs: [ '--follow-tags' ],
    pushRepo: ''
  },
  github: {
    release: false,
    releaseName: 'Release ${version}',
    releaseNotes: null,
    preRelease: false,
    draft: false,
    tokenRef: 'GITHUB_TOKEN',
    assets: null,
    host: null,
    timeout: 0,
    proxy: null,
    skipChecks: false
  },
  gitlab: {
    release: false,
    releaseName: 'Release ${version}',
    releaseNotes: null,
    tokenRef: 'GITLAB_TOKEN',
    tokenHeader: 'Private-Token',
    assets: null,
    origin: null,
    skipChecks: false
  },
  isUpdate: false,
  version: {
    increment: undefined,
    isPreRelease: false,
    preReleaseId: undefined
  }
}
2021-04-10T15:56:10.244Z release-it:config { 'release-it-calver-plugin': { format: 'YY.0M.MICRO' } }
2021-04-10T15:56:10.245Z release-it:plugins {
  namespace: 'release-it-calver-plugin',
  options: { format: 'YY.0M.MICRO' }
}
2021-04-10T15:56:10.253Z release-it:plugins {
  namespace: 'version',
  options: {
    increment: undefined,
    isPreRelease: false,
    preReleaseId: undefined
  }
}
2021-04-10T15:56:10.255Z release-it:plugins {
  namespace: 'git',
  options: {
    changelog: 'git log --pretty=format:"* %s (%h)" ${from}...${to}',
    requireCleanWorkingDir: true,
    requireBranch: false,
    requireUpstream: true,
    requireCommits: false,
    addUntrackedFiles: false,
    commit: true,
    commitMessage: 'Release ${version}',
    commitArgs: [],
    tag: true,
    tagName: null,
    tagAnnotation: 'Release ${version}',
    tagArgs: [],
    push: true,
    pushArgs: [ '--follow-tags' ],
    pushRepo: '',
    isUpdate: false
  }
}
$ git diff --quiet HEAD
2021-04-10T15:56:10.331Z release-it:shell {
  command: 'git diff --quiet HEAD',
  options: { write: false },
  code: 0,
  stdout: '',
  stderr: ''
}
$ git rev-parse --abbrev-ref HEAD
2021-04-10T15:56:10.344Z release-it:metrics {
  url: 'http://www.google-analytics.com/collect',
  statusCode: 200,
  statusMessage: 'OK',
  payload: 'v=1&tid=UA-108828841-1&cid=21070b3f-32ab-4e7a-bedd-a85f2fa503b0&cd1=14.6.0&cd2=v12.14.1&cd3=Windows+10&cd4=1&cd5=0&cd6=0&cd7=0&cd8=null&cd9=undefined&cd11=0&cd12=1&cd13=0&cd14=0&cd15=undefined&cd16=0&t=event&ec=session&ea=start'
}
experimental/calver
experimental/calver
2021-04-10T15:56:10.384Z release-it:shell {
  command: 'git rev-parse --abbrev-ref HEAD',
  options: { write: false },
  code: 0,
  stdout: 'experimental/calver',
  stderr: ''
}
$ git config --get branch.experimental/calver.remote
origin
origin
2021-04-10T15:56:10.441Z release-it:shell {
  command: 'git config --get branch.experimental/calver.remote',
  options: { write: false },
  code: 0,
  stdout: 'origin',
  stderr: ''
}
$ git remote get-url origin
https://BITBUCKET_REPOSITORY_URL.git
https://BITBUCKET_REPOSITORY_URL.git
2021-04-10T15:56:10.491Z release-it:shell {
  command: 'git remote get-url origin',
  options: { write: false },
  code: 0,
  stdout: 'https://BITBUCKET_REPOSITORY_URL.git',
  stderr: ''
}
$ git fetch
2021-04-10T15:56:11.841Z release-it:shell { command: 'git fetch', options: {}, code: 0, stdout: '', stderr: '' }
$ git describe --tags --match=* --abbrev=0
21.04.1
21.04.1
2021-04-10T15:56:11.909Z release-it:shell {
  command: 'git describe --tags --match=* --abbrev=0',
  options: { write: false },
  code: 0,
  stdout: '21.04.1',
  stderr: ''
}
2021-04-10T15:56:11.909Z release-it:config { latestTag: '21.04.1' }
$ git symbolic-ref HEAD
refs/heads/experimental/calver
refs/heads/experimental/calver
2021-04-10T15:56:11.962Z release-it:shell {
  command: 'git symbolic-ref HEAD',
  options: { write: false },
  code: 0,
  stdout: 'refs/heads/experimental/calver',
  stderr: ''
}
$ git for-each-ref --format="%(upstream:short)" refs/heads/experimental/calver
origin/experimental/calver
origin/experimental/calver
2021-04-10T15:56:12.017Z release-it:shell {
  command: 'git for-each-ref --format="%(upstream:short)" refs/heads/experimental/calver',
  options: { write: false },
  code: 0,
  stdout: 'origin/experimental/calver',
  stderr: ''
}
2021-04-10T15:56:12.018Z release-it:config {
  repo: {
    host: 'BITBUCKET_HOST',
    owner: 'OWNER_NAME',
    project: 'PROJECT_NAME',
    protocol: 'http',
    remote: 'https://BITBUCKET_REPOSITORY_URL.git',
    repository: 'REPOSITORY_NAME'
  }
}
$ git log --pretty=format:"* %s (%h)" 21.04.1...HEAD
* WIP 4 (5f9ec96)* WIP 4 (5f9ec96)

* WIP 4 (72e5100)
* WIP 3 (93ef4eb)* WIP 4 (72e5100)
* WIP 3 (93ef4eb)

* WIP 2 (c95b0af)* WIP 2 (c95b0af)

* WIP (8a7ae97)* WIP (8a7ae97)

* Set VERSION (5b60124)* Set VERSION (5b60124)
2021-04-10T15:56:12.079Z release-it:shell {
  command: 'git log --pretty=format:"* %s (%h)" 21.04.1...HEAD',
  options: { write: false },
  code: 0,
  stdout: '* WIP 4 (5f9ec96)\n' +
    '* WIP 4 (72e5100)\n' +
    '* WIP 3 (93ef4eb)\n' +
    '* WIP 2 (c95b0af)\n' +
    '* WIP (8a7ae97)\n' +
    '* Set VERSION (5b60124)',
  stderr: ''
}
2021-04-10T15:56:12.081Z release-it:config {
  name: 'PROJECT_NAME',
  latestVersion: '21.04.1',
  version: '21.04.2',
  changelog: '* WIP 4 (5f9ec96)\n' +
    '* WIP 4 (72e5100)\n' +
    '* WIP 3 (93ef4eb)\n' +
    '* WIP 2 (c95b0af)\n' +
    '* WIP (8a7ae97)\n' +
    '* Set VERSION (5b60124)'
}
🚀 Let's release PROJECT_NAME (21.04.1...21.04.2)
Changelog:
* WIP 4 (5f9ec96)
* WIP 4 (72e5100)
* WIP 3 (93ef4eb)
* WIP 2 (c95b0af)
* WIP (8a7ae97)
* Set VERSION (5b60124)
2021-04-10T15:56:12.143Z release-it:metrics {
  url: 'http://www.google-analytics.com/collect',
  statusCode: 200,
  statusMessage: 'OK',
  payload: 't=exception&exd=TypeError%3A+Cannot+read+property+%27prerelease%27+of+null'
}
ERROR Cannot read property 'prerelease' of null
@webpro webpro closed this as completed in 50216ad Apr 11, 2021
@webpro
Copy link
Collaborator

webpro commented Apr 11, 2021

When not using semver, release-it should be more forgiving indeed.

Just released v14.6.1 that resolves this.

Also, by the way, looking at the code of the CalVer plugin: https://github.com/casmith/release-it-calver-plugin/blob/5f2277067f1276224d3c7dc567ed2524a1a6b1d7/calver-plugin.js#L15

Maybe it's interesting to look into using the increment (semver default: patch) argument as level (now hard-coded micro), as this could be easily grabbed from the release-it context in the plugin. Then you could do:

release-it [calendar|major|minor|micro]

/cc @casmith (plugin author)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants