saitho / semantic-release-backmerge

:twisted_rightwards_arrows: semantic-release plugin to back-merge a release into a develop branch
https://saitho.github.io/semantic-release-backmerge/
58 stars 11 forks source link

Backmerge doesn't work in some cases after 1.2.0 upgrade #6

Closed greetclock closed 3 years ago

greetclock commented 4 years ago

Hi! First of all, thank you for the great plugin!

I've been using it for some time. Recently I noticed that it causes a CI pipeline to fail. After some debugging I found that downgrading from 1.2.0 to 1.1.3 fixes the pipelines. Please, may I ask you to help me when it's the most convenient for you? I saw this commit and I think that it was the reason of the changed behaviour. However I can't really suggest off the top of my head why would it cause the error

Here is the error log and the config I use:


"release": {
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    [
      "@semantic-release/npm",
      {
        "pkgRoot": ".",
        "npmPublish": false
      }
    ],
    [
      "@semantic-release/exec",
      // Just checking if .npmrc is present before running everything else
      {
        "publishCmd": "FILE=\".npmrc\"; git ls-files $FILE | grep -q ^ && git checkout -- $FILE || (! (git ls-files $FILE | grep -q ^) && test -f $FILE && rm $FILE)"
      }
    ],
    [
      "@semantic-release/git",
      {
        "assets": [
          "CHANGELOG.md",
          "package.json",
          "package-lock.json"
        ],
        "message": "chore(release): ${nextRelease.version} \n\n${nextRelease.notes}"
      }
    ],
    "@saithodev/semantic-release-backmerge"
  ],
  "branches": [
    {
      "name": "master",
      "channel": "latest"
    },
    {
      "name": "develop",
      "channel": "next",
      "prerelease": "next"
    }
  ],
  "tagFormat": "${version}"
},

$ GITLAB_TOKEN=$SEMANTIC_RELEASE_TOKEN npx semantic-release
[12:12:30 PM] [semantic-release] › ℹ  Running semantic-release version 17.1.2
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/changelog"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/npm"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/exec"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/git"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@saithodev/semantic-release-backmerge"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/exec"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "verifyRelease" from "@semantic-release/exec"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "generateNotes" from "@semantic-release/release-notes-generator"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "generateNotes" from "@semantic-release/exec"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/changelog"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/npm"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/exec"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/git"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/npm"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/exec"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "addChannel" from "@semantic-release/npm"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "addChannel" from "@semantic-release/exec"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "success" from "@semantic-release/exec"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "success" from "@saithodev/semantic-release-backmerge"
[12:12:30 PM] [semantic-release] › ✔  Loaded plugin "fail" from "@semantic-release/exec"
[12:12:31 PM] [semantic-release] › ✔  Run automated release from branch develop on repository https://gitlab-ci-token:[secure]@gitlab.com/myproject.git
[12:12:32 PM] [semantic-release] › ✔  Allowed to push to the Git repository
[12:12:32 PM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/changelog"
[12:12:32 PM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/changelog"
[12:12:32 PM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/npm"
[12:12:32 PM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/npm"
[12:12:32 PM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/exec"
[12:12:32 PM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/exec"
[12:12:32 PM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/git"
[12:12:32 PM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/git"
[12:12:32 PM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@saithodev/semantic-release-backmerge"
[12:12:32 PM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@saithodev/semantic-release-backmerge"
[12:12:32 PM] [semantic-release] › ℹ  Found git tag 1.0.0-next.3 associated with version 1.0.0-next.3 on branch develop
[12:12:32 PM] [semantic-release] › ℹ  Found 1 commits since last release
[12:12:32 PM] [semantic-release] › ℹ  Start step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[12:12:32 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: fix: update @saithodev/semantic-release-backmerge to 1.2.0
[12:12:32 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is patch
[12:12:32 PM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analysis of 1 commits complete: patch release
[12:12:32 PM] [semantic-release] › ✔  Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[12:12:32 PM] [semantic-release] › ℹ  Start step "analyzeCommits" of plugin "@semantic-release/exec"
[12:12:32 PM] [semantic-release] › ✔  Completed step "analyzeCommits" of plugin "@semantic-release/exec"
[12:12:32 PM] [semantic-release] › ℹ  The next release version is 1.0.0-next.4
[12:12:32 PM] [semantic-release] › ℹ  Start step "verifyRelease" of plugin "@semantic-release/exec"
[12:12:32 PM] [semantic-release] › ✔  Completed step "verifyRelease" of plugin "@semantic-release/exec"
[12:12:32 PM] [semantic-release] › ℹ  Start step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[12:12:32 PM] [semantic-release] › ✔  Completed step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[12:12:32 PM] [semantic-release] › ℹ  Start step "generateNotes" of plugin "@semantic-release/exec"
[12:12:32 PM] [semantic-release] › ✔  Completed step "generateNotes" of plugin "@semantic-release/exec"
[12:12:32 PM] [semantic-release] › ℹ  Start step "prepare" of plugin "@semantic-release/changelog"
[12:12:32 PM] [semantic-release] [@semantic-release/changelog] › ℹ  Update /builds/myproject/CHANGELOG.md
[12:12:32 PM] [semantic-release] › ✔  Completed step "prepare" of plugin "@semantic-release/changelog"
[12:12:32 PM] [semantic-release] › ℹ  Start step "prepare" of plugin "@semantic-release/npm"
[12:12:32 PM] [semantic-release] [@semantic-release/npm] › ℹ  Write version 1.0.0-next.4 to package.json in /builds/myproject
v1.0.0-next.4
[12:12:32 PM] [semantic-release] › ✔  Completed step "prepare" of plugin "@semantic-release/npm"
[12:12:32 PM] [semantic-release] › ℹ  Start step "prepare" of plugin "@semantic-release/exec"
[12:12:32 PM] [semantic-release] › ✔  Completed step "prepare" of plugin "@semantic-release/exec"
[12:12:32 PM] [semantic-release] › ℹ  Start step "prepare" of plugin "@semantic-release/git"
[12:12:33 PM] [semantic-release] [@semantic-release/git] › ℹ  Found 3 file(s) to commit
[12:12:33 PM] [semantic-release] [@semantic-release/git] › ℹ  Prepared Git release: 1.0.0-next.4
[12:12:33 PM] [semantic-release] › ✔  Completed step "prepare" of plugin "@semantic-release/git"
[12:12:33 PM] [semantic-release] › ℹ  Start step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[12:12:33 PM] [semantic-release] › ✔  Completed step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[12:12:33 PM] [semantic-release] › ℹ  Start step "generateNotes" of plugin "@semantic-release/exec"
[12:12:33 PM] [semantic-release] › ✔  Completed step "generateNotes" of plugin "@semantic-release/exec"
[12:12:34 PM] [semantic-release] › ✔  Created tag 1.0.0-next.4
[12:12:34 PM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/npm"
[12:12:34 PM] [semantic-release] [@semantic-release/npm] › ℹ  Skip publishing to npm registry as npmPublish is false
[12:12:34 PM] [semantic-release] › ✔  Completed step "publish" of plugin "@semantic-release/npm"
[12:12:34 PM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/exec"
[12:12:34 PM] [semantic-release] [@semantic-release/exec] › ℹ  Call script FILE=".npmrc"; git ls-files $FILE | grep -q ^ && git checkout -- $FILE || (! (git ls-files $FILE | grep -q ^) && test -f $FILE && rm $FILE)
[12:12:34 PM] [semantic-release] › ✔  Completed step "publish" of plugin "@semantic-release/exec"
[12:12:34 PM] [semantic-release] › ℹ  Start step "success" of plugin "@semantic-release/exec"
[12:12:34 PM] [semantic-release] › ✔  Completed step "success" of plugin "@semantic-release/exec"
[12:12:34 PM] [semantic-release] › ℹ  Start step "success" of plugin "@saithodev/semantic-release-backmerge"
[12:12:34 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Release succeeded. Performing back-merge into branch "develop".
[12:12:35 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Loading plugins
[12:12:35 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Executing "done" step of plugins
[12:12:35 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Found 0 staged files for back-merge commit
[12:12:35 PM] [semantic-release] › ✖  Failed step "success" of plugin "@saithodev/semantic-release-backmerge"
[12:12:35 PM] [semantic-release] › ✖  An error occurred while running semantic-release: Error: Command failed with exit code 1: git push https://gitlab-ci-token:[secure]@gitlab.com/myproject.git HEAD:develop
To https://gitlab.com/myproject.git
 ! [rejected]        HEAD -> develop (non-fast-forward)
error: failed to push some refs to 'https://gitlab-ci-token:[secure]@gitlab.com/myproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    at makeError (/builds/myproject/node_modules/@saithodev/semantic-release-backmerge/node_modules/execa/lib/error.js:59:11)
    at handlePromise (/builds/myproject/node_modules/@saithodev/semantic-release-backmerge/node_modules/execa/index.js:114:26)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  shortMessage: 'Command failed with exit code 1: git push https://gitlab-ci-token:[secure]@gitlab.com/myproject.git HEAD:develop',
  command: 'git push https://gitlab-ci-token:[secure]@gitlab.com/myproject.git HEAD:develop',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: 'To https://gitlab.com/myproject.git\n' +
    ' ! [rejected]        HEAD -> develop (non-fast-forward)\n' +
    "error: failed to push some refs to 'https://gitlab-ci-token:[secure]@gitlab.com/myproject.git'\n" +
    'hint: Updates were rejected because the tip of your current branch is behind\n' +
    'hint: its remote counterpart. Integrate the remote changes (e.g.\n' +
    "hint: 'git pull ...') before pushing again.\n" +
    "hint: See the 'Note about fast-forwards' in 'git push --help' for details.",
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false,
  pluginName: '@saithodev/semantic-release-backmerge'
}
AggregateError: 
    Error: Command failed with exit code 1: git push https://gitlab-ci-token:[secure]@gitlab.com/myproject.git HEAD:develop
    To https://gitlab.com/myproject.git
     ! [rejected]        HEAD -> develop (non-fast-forward)
    error: failed to push some refs to 'https://gitlab-ci-token:[secure]@gitlab.com/myproject.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
        at makeError (/builds/myproject/node_modules/@saithodev/semantic-release-backmerge/node_modules/execa/lib/error.js:59:11)
        at handlePromise (/builds/myproject/node_modules/@saithodev/semantic-release-backmerge/node_modules/execa/index.js:114:26)
    at /builds/myproject/node_modules/semantic-release/lib/plugins/pipeline.js:54:11
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Object.pluginsConf.<computed> [as success] (/builds/myproject/node_modules/semantic-release/lib/plugins/index.js:80:11)
    at async run (/builds/myproject/node_modules/semantic-release/index.js:201:3)
    at async module.exports (/builds/myproject/node_modules/semantic-release/index.js:260:22)
    at async module.exports (/builds/myproject/node_modules/semantic-release/cli.js:55:5)
ERROR: Job failed: exit code 1
saitho commented 4 years ago

As I understand your configuration you're performing a regular backmerge from master to develop. Can't see how the change you mentioned would affect that, as the behaviour should be the same as before.

Maybe someone pushed to develop branch while semantic-release was running? That would explain the error message that the branch is behind develop. Please let me know if that's the case. :)

greetclock commented 4 years ago

@saitho thank you for your response!

Yes, as you correctly notice, this is a regular backmerge from master to develop. However the error appears in develop branch. When I rollback to 1.1.3 then I get this message and the CI job completes successfully:


[10:01:25 AM] [semantic-release] [@saithodev/semantic-release-backmerge] › ✖  Branch for back-merge is the same as the branch which includes the release. Aborting back-merge workflow.

Maybe someone pushed to develop branch while semantic-release was running?

Regarding your suggestion about concurrent push from someone else, I get the error consistently in 1.2.0 and it works as expected in 1.1.3; I've tried it multiple times in different repositories. At the same time, the push does happen indeed, it is initiated by semantic-release itself. What I think, I'm getting something like this:

  1. A commit with fix: prefix is pushed to develop.
  2. semantic-release detects it and prepares the new version in the next channel (the channel that I use for releases in develop).
  3. semantic-release makes a commit that updates version in package.json and also adds changes to changelog.md
  4. semantic-release pushes the new commit
  5. The backmerge plugin is run.

The reason why I think that the commit I mentioned affects the pipeline is that in 1.1.3 there was this warning/error message and the plugin exited immediately. After the commit, the plugin reaches the push step in any case. Of course, without your expertise in building the plugin I can only guess why the changed behaviour (1.1.3 vs 1.2.0) might appear. What do you think about it?

For now, as a temporary solution, I'm rolling back to 1.1.3 in my repos.

saitho commented 4 years ago

Thanks for your detailed reply.

I myself don't use develop branches anymore, so I don't use this plugin. I'll try create a test setup and take a look at it.

saitho commented 3 years ago

Hi @cherurg,

I finally was able to take some time to investigate that. I've created a test repository here: https://github.com/saitho/backmerge-test

v1.0.0 was released from master and backmerged into develop:

[3:58:49 PM] [semantic-release] › ✔  Created tag 1.0.0
[3:58:49 PM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/npm"
[3:58:49 PM] [semantic-release] [@semantic-release/npm] › ℹ  Skip publishing to npm registry as npmPublish is false
[3:58:49 PM] [semantic-release] › ✔  Completed step "publish" of plugin "@semantic-release/npm"
[3:58:49 PM] [semantic-release] › ℹ  Start step "success" of plugin "@saithodev/semantic-release-backmerge"
[3:58:49 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Release succeeded. Performing back-merge into branch "develop".
[3:58:50 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Loading plugins
[3:58:50 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Executing "done" step of plugins
[3:58:50 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Found 0 staged files for back-merge commit
[3:58:54 PM] [semantic-release] › ✔  Completed step "success" of plugin "@saithodev/semantic-release-backmerge"
[3:58:54 PM] [semantic-release] › ✔  Published release 1.0.0 on latest channel

v1.1.0-next.1 was released from develop and also succeeded:

[4:01:48 PM] [semantic-release] › ✔  Created tag 1.1.0-next.1
[4:01:48 PM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/npm"
[4:01:48 PM] [semantic-release] [@semantic-release/npm] › ℹ  Skip publishing to npm registry as npmPublish is false
[4:01:48 PM] [semantic-release] › ✔  Completed step "publish" of plugin "@semantic-release/npm"
[4:01:48 PM] [semantic-release] › ℹ  Start step "success" of plugin "@saithodev/semantic-release-backmerge"
[4:01:48 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Release succeeded. Performing back-merge into branch "develop".
[4:01:49 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Loading plugins
[4:01:49 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Executing "done" step of plugins
[4:01:49 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Found 0 staged files for back-merge commit
[4:01:49 PM] [semantic-release] › ✔  Completed step "success" of plugin "@saithodev/semantic-release-backmerge"
[4:01:49 PM] [semantic-release] › ✔  Published release 1.1.0-next.1 on next channel

So both cases worked for me. I've tried that with Github Actions and DroneCI as Continuous Deployment tool.

I'll restore the old behaviour (aborting when source == target) and add a option to disable that behaviour. That should do the trick.

saitho commented 3 years ago

@cherurg Can you try v1.2.1? ;)

ccrowley96 commented 3 years ago

Thanks for your detailed reply.

I myself don't use develop branches anymore, so I don't use this plugin. I'll try create a test setup and take a look at it.

I'm considering using this plugin. What are you using instead of a develop branch? Back merging seems to be the only way to keep the pre-release version up to date with semantic-release.

saitho commented 3 years ago

@ccrowley96 I don't have prereleases on my projects. I'm developing features in separate branches and merge them to master when they're ready, immedialy creating a release.

greetclock commented 3 years ago

@saitho it works for me now, thanks! I've sent you a tip via Brave, as you seem to be a registered creator there

saitho commented 3 years ago

@saitho it works for me now, thanks! I've sent you a tip via Brave, as you seem to be a registered creator there

Great it works! Oh, yes I am on Brave. Thanks a lot! :)