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

Suffering "would clobber existing tag" when reusing repository cache #8

Open
mikaello opened this issue Jan 23, 2024 · 3 comments
Open

Comments

@mikaello
Copy link

I am using this plugin in a GitLab CI/CD pipeline and recently got this error:

[11:49:44 AM] [semantic-release] › ✘  An error occurred while running semantic-release: Error: Command failed with exit code 1: git fetch --tags --update-head-ok [https://gitlab-ci-token:[secure]@gitlab.acme.com/my-group/my-project.git](https://gitlab-ci-token:%5Bsecure%[email protected]/my-group/my-project.git) +refs/heads/main:refs/heads/main
From https://gitlab.acme.com/my-group/my-project
 ! [rejected]        v1         -> v1  (would clobber existing tag)

This is because the default Git strategy was to use git fetch to get the repository, it then reused previous artifacts which caused this error to happen.

If the fetch function in semantic-release had fetched the tags with --force this would not have been a problem. Another solution is to make sure that the CI/CD pipeline always clones a fresh repository. In GitLab this is done by adding this to the job making the release:

  variables:
    GIT_STRATEGY: clone

This may not be an issue for GitHub actions users, but in case others come across the same error this may at least be the root cause.

@doteric
Copy link
Owner

doteric commented Jan 24, 2024

Hey @mikaello ,
Thank you for the issue report, I haven't came across this issue and we use the fetch strategy on GitLab.
Could you please tell me if this error happens before or after a new "major version" is created? It happens in the next job run or when exactly? 🤔
A situation I'm thinking of this could happen is if the tag was created locally, but not pushed successfully in the first run and the second run when you retry produces the error. Is that the case by any chance?

@mikaello
Copy link
Author

Click to see full job log of failing pipeline
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/my-group/my-project/.git/
Checking out f8e3387e as detached HEAD (ref is main)...
Removing my-project.env
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:11
Using docker image sha256:2ac41ffd89980691aae0ed43d998for node:latest with digest node@sha256:2beb7b17b78455a3ae0b86f053829...
$ npm install --no-save semantic-release @semantic-release/changelog @semantic-release/git @semantic-release/gitlab semantic-release-major-tag semantic-release-replace-plugin conventional-changelog-conventionalcommits
npm WARN deprecated [email protected]: Renamed to read-package-up
added 377 packages in 8s
24 packages are looking for funding
  run `npm fund` for details
$ [[ -f $SEMANTIC_RELEASE_CONFIG ]] || echo "$SEMANTIC_RELEASE_DEFAULT_CONFIG" > $SEMANTIC_RELEASE_CONFIG

$ npx --package @semantic-release/gitlab semantic-release
[11:49:43 AM] [semantic-release] › ℹ  Running semantic-release version 23.0.0
(node:38) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
[11:49:43 AM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/gitlab"
[11:49:43 AM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[11:49:43 AM] [semantic-release] › ✔  Loaded plugin "generateNotes" from "@semantic-release/release-notes-generator"
[11:49:43 AM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/gitlab"
[11:49:43 AM] [semantic-release] › ✔  Loaded plugin "success" from "@semantic-release/gitlab"
[11:49:43 AM] [semantic-release] › ✔  Loaded plugin "success" from "semantic-release-major-tag"
[11:49:43 AM] [semantic-release] › ✔  Loaded plugin "fail" from "@semantic-release/gitlab"
[11:49:44 AM] [semantic-release] › ✘  An error occurred while running semantic-release: Error: Command failed with exit code 1: git fetch --tags --update-head-ok https://gitlab-ci-token:[secure]@gitlab.acme.com/my-group/my-project.git +refs/heads/main:refs/heads/main
From https://gitlab.acme.com/my-group/my-project
 ! [rejected]        v1         -> v1  (would clobber existing tag)
    at makeError (file:///builds/my-group/my-project/node_modules/semantic-release/node_modules/execa/lib/error.js:60:11)
    at handlePromise (file:///builds/my-group/my-project/node_modules/semantic-release/node_modules/execa/index.js:124:26)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async fetch (file:///builds/my-group/my-project/node_modules/semantic-release/lib/git.js:123:5)
    at async file:///builds/my-group/my-project/node_modules/semantic-release/lib/branches/index.js:21:5
    at async pEachSeries (file:///builds/my-group/my-project/node_modules/p-each-series/index.js:6:23)
    at async default (file:///builds/my-group/my-project/node_modules/semantic-release/lib/branches/index.js:20:3)
    at async run (file:///builds/my-group/my-project/node_modules/semantic-release/index.js:68:22)
    at async Module.default (file:///builds/my-group/my-project/node_modules/semantic-release/index.js:278:22)
    at async default (file:///builds/my-group/my-project/node_modules/semantic-release/cli.js:55:5) {
  shortMessage: 'Command failed with exit code 1: git fetch --tags --update-head-ok https://gitlab-ci-token:[secure]@gitlab.acme.com/my-group/my-project.git +refs/heads/main:refs/heads/main',
  command: 'git fetch --tags --update-head-ok https://gitlab-ci-token:[secure]@gitlab.acme.com/my-group/my-project.git +refs/heads/main:refs/heads/main',
  escapedCommand: 'git fetch --tags --update-head-ok "https://gitlab-ci-token:[secure]@gitlab.acme.com/my-group/my-project.git" "+refs/heads/main:refs/heads/main"',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: 'From https://gitlab.acme.com/my-group/my-project\n' +
    ' ! [rejected]        v1         -> v1  (would clobber existing tag)',
  cwd: '/builds/my-group/my-project',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}
Error: Command failed with exit code 1: git fetch --tags --update-head-ok https://gitlab-ci-token:[secure]@gitlab.acme.com/my-group/my-project.git +refs/heads/main:refs/heads/main
From https://gitlab.acme.com/my-group/my-project
 ! [rejected]        v1         -> v1  (would clobber existing tag)
    at makeError (file:///builds/my-group/my-project/node_modules/semantic-release/node_modules/execa/lib/error.js:60:11)
    at handlePromise (file:///builds/my-group/my-project/node_modules/semantic-release/node_modules/execa/index.js:124:26)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async fetch (file:///builds/my-group/my-project/node_modules/semantic-release/lib/git.js:123:5)
    at async file:///builds/my-group/my-project/node_modules/semantic-release/lib/branches/index.js:21:5
    at async pEachSeries (file:///builds/my-group/my-project/node_modules/p-each-series/index.js:6:23)
    at async default (file:///builds/my-group/my-project/node_modules/semantic-release/lib/branches/index.js:20:3)
    at async run (file:///builds/my-group/my-project/node_modules/semantic-release/index.js:68:22)
    at async Module.default (file:///builds/my-group/my-project/node_modules/semantic-release/index.js:278:22)
    at async default (file:///builds/my-group/my-project/node_modules/semantic-release/cli.js:55:5) {
  shortMessage: 'Command failed with exit code 1: git fetch --tags --update-head-ok https://gitlab-ci-token:[secure]@gitlab.acme.com/my-group/my-project.git +refs/heads/main:refs/heads/main',
  command: 'git fetch --tags --update-head-ok https://gitlab-ci-token:[secure]@gitlab.acme.com/my-group/my-project.git +refs/heads/main:refs/heads/main',
  escapedCommand: 'git fetch --tags --update-head-ok "https://gitlab-ci-token:[secure]@gitlab.acme.com/my-group/my-project.git" "+refs/heads/main:refs/heads/main"',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: 'From https://gitlab.acme.com/my-group/my-project\n' +
    ' ! [rejected]        v1         -> v1  (would clobber existing tag)',
  cwd: '/builds/my-group/my-project',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

We have been using this plugin for a couple of weeks without experiencing this problem, so it may be something special with this repository, but on the other hand it was this plugin that created the v1 and v1.0 plugins, this is the log from a couple of pipelines before the failing pipeline that creates the versions (in between the failing pipeline and this pipeline it was a couple of docs: pipelines with no version changes):

$ npx --package @semantic-release/gitlab semantic-release
[1:02:28 PM] [semantic-release] › ℹ  Running semantic-release version 23.0.0
(node:38) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
[1:02:28 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/gitlab"
[1:02:28 PM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[1:02:28 PM] [semantic-release] › ✔  Loaded plugin "generateNotes" from "@semantic-release/release-notes-generator"
[1:02:28 PM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/gitlab"
[1:02:28 PM] [semantic-release] › ✔  Loaded plugin "success" from "@semantic-release/gitlab"
[1:02:28 PM] [semantic-release] › ✔  Loaded plugin "success" from "semantic-release-major-tag"
[1:02:28 PM] [semantic-release] › ✔  Loaded plugin "fail" from "@semantic-release/gitlab"
[1:02:29 PM] [semantic-release] › ✔  Run automated release from branch main on repository https://gitlab-ci-token:[secure]@gitlab.acme.com/my-group/my-project.git
[1:02:29 PM] [semantic-release] › ✔  Allowed to push to the Git repository
[1:02:29 PM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/gitlab"
[1:02:29 PM] [semantic-release] [@semantic-release/gitlab] › ℹ  Verify GitLab authentication (https://gitlab.acme.com/api/v4)
[1:02:29 PM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/gitlab"
[1:02:29 PM] [semantic-release] › ℹ  No git tag version found on branch main
[1:02:29 PM] [semantic-release] › ℹ  No previous release found, retrieving all commits
[1:02:29 PM] [semantic-release] › ℹ  Found 47 commits since last release
[1:02:29 PM] [semantic-release] › ℹ  Start step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: ci: include semantic relase pipeline
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: docs: add prod env name change to v1 migration
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: prod overlay path in example/test and migration guide
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: docs: fix project path after move to pipelines
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: docs: describe example project
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: templating
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: docs: add example of image replace with wildcard
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: docs: use italic for K8S resources
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: docs: create v0 -> v1.0.0 migration guide
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: refactor!: rename overlay vars to include paths
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is major
[1:02:29 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analysis of 47 commits complete: major release
[1:02:29 PM] [semantic-release] › ✔  Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[1:02:29 PM] [semantic-release] › ℹ  There is no previous release, the next release version is 1.0.0
[1:02:29 PM] [semantic-release] › ℹ  Start step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[1:02:29 PM] [semantic-release] › ✔  Completed step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[1:02:30 PM] [semantic-release] › ✔  Created tag v1.0.0
[1:02:30 PM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/gitlab"
[1:02:31 PM] [semantic-release] [@semantic-release/gitlab] › ℹ  Published GitLab release: v1.0.0
[1:02:31 PM] [semantic-release] › ✔  Completed step "publish" of plugin "@semantic-release/gitlab"
[1:02:31 PM] [semantic-release] › ℹ  Start step "success" of plugin "@semantic-release/gitlab"
[1:02:[34](https://gitlab.acme.com/my-group/my-project/-/jobs/10200181#L34) PM] [semantic-release] › ✔  Completed step "success" of plugin "@semantic-release/gitlab"
[1:02:34 PM] [semantic-release] › ℹ  Start step "success" of plugin "semantic-release-major-tag"
[1:02:34 PM] [semantic-release] [semantic-release-major-tag] › ℹ  Pushing version tag 'v1' to git.
[1:02:34 PM] [semantic-release] [semantic-release-major-tag] › ℹ  Pushing version tag 'v1.0' to git.
To https://gitlabacme.com/my-group/my-project.git
 * [new tag]         v1 -> v1
 * [new tag]         v1.0 -> v1.0
[1:02:[35](https://gitlabacme.com/my-group/my-project/-/jobs/10200181#L35) PM] [semantic-release] › ✔  Completed step "success" of plugin "semantic-release-major-tag"
[1:02:35 PM] [semantic-release] › ✔  Published release 1.0.0 on default channel

So to answer your questions:

Could you please tell me if this error happens before or after a new "major version" is created?

After

A situation I'm thinking of this could happen is if the tag was created locally, but not pushed successfully in the first run and the second run when you retry produces the error. Is that the case by any chance?

This tag was not created locally, but by this plugin.

@doteric
Copy link
Owner

doteric commented Jan 26, 2024

Thanks for the reply @mikaello

This tag was not created locally, but by this plugin.

Sorry I put it wrong. I meant locally on the runner/pipeline/job and then there was some error when actually pushing the tag and when retrying this error occurred, could this have been the case? If yes I would appreciate the logs from the job before the would clobber existing tag fail.
If this is the problem I could possibly add some checking if the tag was pushed correctly and if not then remove the tag locally (job/runner), but beforehand I would also like to know the reason the previous push might have failed (if it even did fial). Thoughts?

So the potential scenario you might have faced in steps:

  1. First job with semantic-release-major-tag starts and creates tag, but fails to push the tag for some reason;
  2. Second job with semantic-release-major-tag is triggered and the machine already has a local version of this tag. It tries to fetch tags, but realises it has a newer one locally and fails.

HOWEVER, it's not a guarantee that this could have been the problem. If the fetch was using --prune (or --force like you mentioned, but prune should be more ideal I think) then there wouldn't be a problem with this, but that's outside of this plugin.

Does this error happen often or very rarely btw?

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