qiwi / semantic-release-gh-pages-plugin

github-pages publishing plugin for semantic-release
MIT License
23 stars 7 forks source link

pullTags causes issues when currently checked out on a different branch other than master #82

Closed HeshamMeneisi closed 4 years ago

HeshamMeneisi commented 4 years ago

Problem

I'm using this plugin with my main GitHub page. The main GitHub page requires that the distribution is on master and thus I have to store the codebase on a different branch.

Now while I can choose the target branch, I cannot choose the source branch. Especially when using this in GitHub actions where the current branch is already checked out, the pullTags promise then fails with the following error:

  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: 'From https://github.com/HeshamMeneisi/heshammeneisi.github.io\n' +
    ' * branch            HEAD       -> FETCH_HEAD\n' +
    'fatal: refusing to merge unrelated histories',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false,
  pluginName: '@qiwi/semantic-release-gh-pages-plugin'
}
(node:2838) UnhandledPromiseRejectionWarning: TypeError: (s || "").replace is not a function
    at escapeData (/home/runner/work/_actions/cycjimmy/semantic-release-action/v2/node_modules/@actions/core/lib/command.js:66:10)
    at Command.toString (/home/runner/work/_actions/cycjimmy/semantic-release-action/v2/node_modules/@actions/core/lib/command.js:60:35)
    at issueCommand (/home/runner/work/_actions/cycjimmy/semantic-release-action/v2/node_modules/@actions/core/lib/command.js:23:30)
    at Object.issue (/home/runner/work/_actions/cycjimmy/semantic-release-action/v2/node_modules/@actions/core/lib/command.js:27:5)
    at error (/home/runner/work/_actions/cycjimmy/semantic-release-action/v2/node_modules/@actions/core/lib/core.js:127:15)
    at setFailed (/home/runner/work/_actions/cycjimmy/semantic-release-action/v2/node_modules/@actions/core/lib/core.js:101:5)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:2838) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2838) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero

This makes sense as the master branch containing the distribution and the current branch (codebase - FETCH_HEAD) are completely unrelated.

Proposed Solution

currentBranch option that defaults to master.

So instead of executing git pull --tags {{repo}} we would execute git pull --tags {{repo}} {{currentBranch}}

pullBranch option that defaults to true (to avoid redundant actions when already checked out in GitHub actions without breaking current behaviour)

antongolub commented 4 years ago

@HeshamMeneisi thanks for the feedback, very interesting case. We'll try to fix it in the next sprint.

HeshamMeneisi commented 4 years ago

Thanks for the prompt response! I actually experimented a little with the code after posting that and it seemed quite easy to solve the problem. I will create a PR so you could review the changes.

HeshamMeneisi commented 4 years ago

@antongolub @oljekechoro I introduced these two options in PR #83, please take a look when you have time!

antongolub commented 4 years ago

Fixed in #83, released in 1.16.0