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

Not detecting existing release #1121

Closed
charliebravodev opened this issue Mar 8, 2019 · 6 comments
Closed

Not detecting existing release #1121

charliebravodev opened this issue Mar 8, 2019 · 6 comments

Comments

@charliebravodev
Copy link

charliebravodev commented Mar 8, 2019

Current behavior

Because of an npm misconfiguration, my pre-release branch failed in the middle of a release. @semantic-release/git tagged the version correctly and created a commit chore(release)... but @semantic-release/npm failed. I then pushed a fix to the pre-release branch and the commit analyser doesn't seem to find an existing release, so it tries to release v1.0.0-alpha.1, but then the git plugin fails because the tag already exists.

Expected behavior

I'm not sure how the commit analyser determines whether there is an existing pre-release, but I would guess that it checks for the existence of a version tag. In this case, it should detect that a pre-release was already performed, and bump the version to v1.0.0-alpha.2.

As you'll see in the logs, I tried pushing a fix, a feature, a breaking change, nothing succeeded.

I would expect any commit to the pre-release branch to trigger a new release.

Environment

  • semantic-release 16.0.0-beta.18
  • CI environment: GitLab
  • Plugins used: see config below
  • semantic-release configuration:
module.exports = {
  branches: [
    '+([1-9])?(.{+([1-9]),x}).x',
    'master',
    'next',
    'next-major',
    {name: 'beta', prerelease: true},
    {name: 'alpha', prerelease: true}
  ],
  plugins: [
    ["@semantic-release/commit-analyzer", {
      "preset": "angular",
    }],
    ["@semantic-release/release-notes-generator", {
      "preset": "angular",
    }],
    ["@semantic-release/changelog", {
      "changelogFile": "CHANGELOG.md",
    }],
    ['@semantic-release/npm'],
    ["@semantic-release/git", {
      "message": "chore(release): ${nextRelease.version} [ci skip]"
    }],
  ],
};
  • CI logs:
[9:57:48 PM] [semantic-release] › ℹ  Start step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: force release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore(release): 1.0.0-alpha.1 [ci skip]
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: force release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore(release): 1.0.0-alpha.1 [ci skip]
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: force release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore(release): 1.0.0-alpha.1 [ci skip]
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: npm publish config

BREAKING CHANGE
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore(release): 1.0.0-alpha.1 [ci skip]
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: npm publish config
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore(release): 1.0.0-alpha.1 [ci skip]
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: npm publish config
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore(release): 1.0.0-alpha.1 [ci skip]
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore: add .npmrc to force semantic-release to publish to private registry
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore(release): 1.0.0-alpha.1 [ci skip]
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore: add .npmrc to force semantic-release to publish to private registry
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: add docker registry to env config
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: ci setup
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: Add initial sources
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: add README
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[9:57:48 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analysis of 19 commits complete: minor release
[9:57:48 PM] [semantic-release] › ✔  Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[9:57:48 PM] [semantic-release] › ℹ  There is no previous release, the next release version is 1.0.0-alpha.1
[9:57:48 PM] [semantic-release] › ℹ  Start step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[9:57:48 PM] [semantic-release] › ✔  Completed step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[9:57:48 PM] [semantic-release] › ℹ  Start step "prepare" of plugin "@semantic-release/changelog"
[9:57:48 PM] [semantic-release] [@semantic-release/changelog] › ℹ  Update /builds/devops/my-project/CHANGELOG.md
[9:57:48 PM] [semantic-release] › ✔  Completed step "prepare" of plugin "@semantic-release/changelog"
[9:57:48 PM] [semantic-release] › ℹ  Start step "prepare" of plugin "@semantic-release/npm"
[9:57:48 PM] [semantic-release] [@semantic-release/npm] › ℹ  Write version 1.0.0-alpha.1 to package.json in /builds/devops/my-project
v1.0.0-alpha.1
[9:57:48 PM] [semantic-release] › ✔  Completed step "prepare" of plugin "@semantic-release/npm"
[9:57:48 PM] [semantic-release] › ℹ  Start step "prepare" of plugin "@semantic-release/git"
[9:57:48 PM] [semantic-release] [@semantic-release/git] › ℹ  Found 1 file(s) to commit
[9:57:49 PM] [semantic-release] [@semantic-release/git] › ℹ  Prepared Git release: v1.0.0-alpha.1@alpha
[9:57:49 PM] [semantic-release] › ✔  Completed step "prepare" of plugin "@semantic-release/git"
[9:57:49 PM] [semantic-release] › ℹ  Start step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[9:57:49 PM] [semantic-release] › ✔  Completed step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[9:57:49 PM] [semantic-release] › ✖  An error occurred while running semantic-release: { Error: Command failed: git tag v1.0.0-alpha.1@alpha 117aeaad55eaf342b06f08580cb3c3777eefa2f6
fatal: tag 'v1.0.0-alpha.1@alpha' already exists
@charliebravodev charliebravodev changed the title Pre-release not detecting existing release Not detecting existing release Mar 12, 2019
@charliebravodev
Copy link
Author

charliebravodev commented Mar 12, 2019

Update: I am having the same issue with normal release branches. Here the history:

  • successfully release v1.0.0
  • make a feature
  • successful release of v1.1.0
  • make a fix on dev, merge dev to master
  • semantic-release tries to release v1.1.0 instead of v1.1.1, so it fails because tag v1.1.0 already exists

Screenshot 2019-03-12 at 15 23 42

Here is the log:

### Bug Fixes

* cannot login due to wrong argument used in docker login ([441a00a](https://my-site.com/devops/my-super-project/commit/441a00a))
* docker login not working ([d935f34](https://my-site.com/devops/my-super-project/commit/d935f34))

### Features

* allow setting image name via DOCKER_IMAGE environment variable ([a11548e](https://my-site.com/devops/my-super-project/commit/a11548e))
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: docker login not working
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore(release): 1.1.0 [skip ci]

# [1.1.0](https://my-site.com/devops/my-super-project/compare/v1.0.0...v1.1.0) (2019-03-12)

### Bug Fixes

* cannot login due to wrong argument used in docker login ([441a00a](https://my-site.com/devops/my-super-project/commit/441a00a))

### Features

* allow setting image name via DOCKER_IMAGE environment variable ([a11548e](https://my-site.com/devops/my-super-project/commit/a11548e))
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore: update package.json
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: Merge branch 'dev'
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: cannot login due to wrong argument used in docker login
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: chore(release): 1.1.0 [skip ci]

# [1.1.0](https://my-site.com/devops/my-super-project/compare/v1.0.0...v1.1.0) (2019-03-12)

### Features

* allow setting image name via DOCKER_IMAGE environment variable ([a11548e](https://my-site.com/devops/my-super-project/commit/a11548e))
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: Merge branch 'dev'
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: allow setting image name via DOCKER_IMAGE environment variable
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[2:19:44 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analysis of 10 commits complete: minor release
[2:19:44 PM] [semantic-release] › ✔  Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[2:19:44 PM] [semantic-release] › ℹ  The next release version is 1.1.0

and the release config:

module.exports = {
  branches: [
    '+([1-9])?(.{+([1-9]),x}).x',
    'master',
    'next',
    'next-major',
    {name: 'beta', prerelease: true},
    {name: 'alpha', prerelease: true}
  ],
  plugins: [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    "@semantic-release/npm",
    "@semantic-release/git",
  ],
};

Could the problem come from the commit analyzer plugin ? I don't have it installed locally, I use nix semantic-release@beta but I checked and @semantic-release/commit-analyzer is in beta in the package.json of semantic-release, so I guess it's not coming from there.

Any idea ?

For information, downgrading to v15 fixes the problem.

@plup
Copy link

plup commented Mar 18, 2019

I have the same issue. In a strange way it seems to work correctly when I test in a local container but fails in Gitlab CI.

In a local docker container:

# npm install -g semantic-release@v16.0.0-beta.18
[skip warnings]
# semantic-release --no-ci  
[11:33:52 AM] [semantic-release] › ℹ  Running semantic-release version 16.0.0-beta.18
[11:33:52 AM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[11:33:59 AM] [semantic-release] › ✔  Run automated release from branch alpha
[11:34:07 AM] [semantic-release] › ✔  Allowed to push to the Git repository
[11:34:07 AM] [semantic-release] › ℹ  Found git tag v0.2.0-alpha.1@alpha associated with version 0.2.0-alpha.1 on branch alpha
[11:34:07 AM] [semantic-release] › ℹ  Found 2 commits since last release
[11:34:07 AM] [semantic-release] › ℹ  Start step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[11:34:07 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: added all plugins for release
[11:34:07 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[11:34:07 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: removed tagged commit from test stage
[11:34:07 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[11:34:07 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analysis of 2 commits complete: patch release
[11:34:07 AM] [semantic-release] › ✔  Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[11:34:07 AM] [semantic-release] › ℹ  The next release version is 0.2.0-alpha.2
[11:34:10 AM] [semantic-release] › ✔  Created tag v0.2.0-alpha.2@alpha
[11:34:10 AM] [semantic-release] › ✔  Published release 0.2.0-alpha.2

In Gitlab CI:

$ npm install -g semantic-release@v16.0.0-beta.18
[skip warning]
$ semantic-release
[11:45:01 AM] [semantic-release] › ℹ  Running semantic-release version 16.0.0-beta.18
[11:45:01 AM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[11:45:08 AM] [semantic-release] › ✔  Run automated release from branch alpha
[11:45:08 AM] [semantic-release] › ✔  Allowed to push to the Git repository
[11:45:08 AM] [semantic-release] › ℹ  Found git tag v0.1.0 associated with version 0.1.0 on branch alpha
[11:45:08 AM] [semantic-release] › ℹ  Found 9 commits since last release
[11:45:08 AM] [semantic-release] › ℹ  Start step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: kept only analyzer plugin
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: Revert "fix: added all plugins for release"

This reverts commit 2fb2943a98445f8bdf7d88cf2ce7a9de1cb06734.
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: trigger alpha release
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: added all plugins for release
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: removed tagged commit from test stage
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: added alpha branch to release stage
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: added gitlab ci
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: added prerelease config
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: this is a patch
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[11:45:08 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analysis of 9 commits complete: minor release
[11:45:08 AM] [semantic-release] › ✔  Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[11:45:08 AM] [semantic-release] › ℹ  The next release version is 0.2.0-alpha.1
[11:45:08 AM] [semantic-release] › ✖  An error occurred while running semantic-release: { Error: Command failed: git tag v0.2.0-alpha.1@alpha 3535c8379991ee88d3743db6778684ec6c460e19
fatal: tag 'v0.2.0-alpha.1@alpha' already exists

@pvdlg
Copy link
Member

pvdlg commented Mar 21, 2019

It's difficult to figure out what's going on with the info provided, but here is a few that might help:

  • The tag format for releases made on branch other than the default one is v{version}@{channel}, so if you made a v1.0.0-alpha.2 release the corresponding tag should be v1.0.0-alpha.2@alpha (if the associated channel is alpha).
  • If you use rebase to merge a release branch into another you will rewrite the commits you merge. That means tags will not follow and semantic-release won't be able to figure out what was merge where.
  • When looking for the last release, semantic-release looks only for tags associated with commits present in the history of the current branch. If the tag is associated with a commit not in the history of the branch semantic-release will ignore it and might try to create the same one again.

I'm not really sure in which state is your repo right now, nor how can I help.
You would have to review your release and tags and make sure everything follow the rule mentioned above.

@pvdlg pvdlg closed this as completed Mar 21, 2019
@pvdlg pvdlg added the support label Mar 21, 2019
@alvaropinot
Copy link
Contributor

In case it helps @charliebravodev, I had a similar issue and I discovered that the released git tag was pointing at an orphan commit, probably due to a rebase.

My solution

Find the git commit that should be the one that the tag vX.X.X is pointing at and force update the tag with (-f stands for force, as the tag already exists)👇

git tag -f <vX.X.X> <SHA_of_the_actual_comit>

In my scenario was v1.2.3 pointing to b843f6 when it should point to 356a7b4 so 👇 did the trick

git tag -f v1.2.3 356a7b4

then force push the tags to the remote repo too running 👇

git push -f --tags . ⚠️ This is risky business 😛

Proposal

Include a precondition check in semantic-release or the check plugin like git branch --contains $COMMIT_ID to check if every tag is still in the release.config branch normally master. Warn the user if its not.

Not that pseudo code 😅

const tags = getTagsCommitIDs()
const DEFAULT_RELEASE_BRANCH = 'master'
const checkContains = (commitId, branch = DEFAULT_RELEASE_BRANCH) => 
   exec(`git branch --contains ${commitId}`)
const isEveryTagContainedInBranch = tags.every(checkContains)

Will this make sense @pvdlg? If so how will you approach it?

@gr2m
Copy link
Member

gr2m commented Aug 5, 2019

@alvaropinot could you create a follow up issue? A comment on a closed issue might easily be overseen, and issue will work better as a reminder.

I very much like your suggestion :)

@alvaropinot
Copy link
Contributor

Thanks @gr2m 😊! I've just created #1257 following your suggestion.

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

5 participants