greenkeeperio / greenkeeper-lockfile

:lock: Your lockfile, up to date, all the time
https://greenkeeper.io
183 stars 73 forks source link

AppVeyor CI Integration #80

Closed patkub closed 6 years ago

patkub commented 6 years ago

An attempt at getting greenkeeper-lockfile working in AppVeyor CI. AppVeyor Build that updated lockfile: https://ci.appveyor.com/project/patkub/test-greenkeeper-lockfile-appveyor/build/1.0.20 Greenkeeper PR where lockfile was updated: https://github.com/patkub/test-greenkeeper-lockfile-appveyor/pull/2

Issues:

janl commented 6 years ago

AppVeyor runs Windows, so the existing git commands won't work. How should I go about detecting AppVeyor CI in update-lockfile.js?

Why wouldn’t these commands work on Windows?

patkub commented 6 years ago

@janl

The changes to the commands in update-lockfile.js make it work on Windows, but we need to add a check to choose when to use the existing Linux commands vs the Windows commands.

Failed build log on AppVeyor before changes to update-lockfile.js: https://ci.appveyor.com/project/patkub/test-greenkeeper-lockfile-appveyor/build/1.0.14

The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
child_process.js:511
    throw err;
    ^

This is cause by https://github.com/greenkeeperio/greenkeeper-lockfile/blob/master/lib/update-lockfile.js#L58,L60 because /dev/null does not exist on Windows, and true is not recognized as a command.

Error: Command failed: git commit -m "chore(package): update lockfile
https://npm.im/greenkeeper-lockfile"

This seems to be caused by ${updateMessage}.

Edit: Clarified Linux/Windows detection issue, added build log

patkub commented 6 years ago
chgibb commented 6 years ago

Would it not be possible to run through MSYS on Appveyor? With some minor tweaking, shell scripts written for Travis will work fine on Appveyor under MSYS.

patkub commented 6 years ago

@chgibb Thanks for the suggestion of using MSYS. I tried running just the ci-services implementation through MSYS on Appveyor and the git commit command still fails. https://ci.appveyor.com/project/patkub/test-greenkeeper-lockfile-appveyor/build/1.0.58

I installed greenkeeper-lockfile globally with npm install -g patkub/greenkeeper-lockfile#appveyor-msys. However, running greenkeeper-lockfile through msys looks for update-lockfile.js in the local node_modules directory instead of the global location.

Installing greenkeeper-lockfile locally without modifying package.json gets it to run, but still fails on the git commit -m command.

appveyor.yml: https://github.com/patkub/test-greenkeeper-lockfile-appveyor/blob/master/appveyor.yml

chgibb commented 6 years ago

@patkub Can you send me a link to patkub/greenkeeper-lockfile#appveyor-msys? Wherever the repo for that package is.

patkub commented 6 years ago

@chgibb Yes. I just cherry-picked the add appveyor to ci-services commit from here. https://github.com/patkub/greenkeeper-lockfile/tree/appveyor-msys

chgibb commented 6 years ago

This

  exec('git add npm-shrinkwrap.json 2>/dev/null || true')
  exec('git add package-lock.json 2>/dev/null || true')
  exec('git add yarn.lock 2>/dev/null || true')
  exec('git config user.email "support@greenkeeper.io"')
  exec('git config user.name "greenkeeper[bot]"')

will fail if run through node directly.

Instead of C:\MinGW\msys\1.0\bin\sh greenkeeper-lockfile-update, something like bash node ./node_modules/.bin/greenkeeper-lockfile-update should work. As long as you can get bash to invoke node to invoke greenkeeper-lockfile-update, as opposed to cmd or ps(which is the default Appveyor uses in its config).

patkub commented 6 years ago

@chgibb It looks like even though I get bash to invoke node to invoke greenkeeper-lockfile-update, the commands still fail to run in a bash environment. I tried two approaches:

  1. https://github.com/patkub/test-greenkeeper-lockfile-appveyor/commit/20641a314022e4abc6993790108e26c401a153c7

I used the regular bash command available in Appveyor to run node greenkeeper-lockfile/update.js. The command passes on master, but fails to commit on a greenkeeper branch. master: https://ci.appveyor.com/project/patkub/test-greenkeeper-lockfile-appveyor/build/1.0.97 greenkeeper: https://ci.appveyor.com/project/patkub/test-greenkeeper-lockfile-appveyor/build/1.0.98

  1. https://github.com/patkub/test-greenkeeper-lockfile-appveyor/commit/d3f509e5e88e5bbe21c0c97a6c739f269b768ad5

Using msys bash to invoke node to invoke greenkeeper-lockfile/update.js also passes on master, but fails to commit on a greenkeeper branch. master: https://ci.appveyor.com/project/patkub/test-greenkeeper-lockfile-appveyor/build/1.0.99 greenkeeper: https://ci.appveyor.com/project/patkub/test-greenkeeper-lockfile-appveyor/build/1.0.100

Could this be because exec spawns a new shell, which probably isn't in a bash environment? https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

chgibb commented 6 years ago

@patkub you're probably correct. I was hoping exec would spawn a new instance of the current shell (hence, trying to invoke through bash). You might want to look at invoking git through cp.spawnSync and then just discarding the buffered stdio output to get the same behaviour as exec with the redirect.

patkub commented 6 years ago

@chgibb @janl How about checking if running on windows, and using exec to run windows compatible git commands? I added a check for Windows and git commands to commit the updated lockfile here. This works, but could make the package more complex, and other commands run though exec might also need to be changed to work on Windows.

https://github.com/patkub/greenkeeper-lockfile/commit/378ed906f6fc342dc48139907b7705d53f9f871e Using cp.spawnSync, greenkeeper-lockfile says the Lockfile updated, but no changes are committed. git status after greenkeeper-lockfile-update shows the changes are not staged for commit, and a git diff shows the changes to the lockfile https://ci.appveyor.com/project/patkub/test-greenkeeper-lockfile-appveyor/build/1.0.119

xt0rted commented 6 years ago

AppVeyor supports Linux too now https://www.appveyor.com/docs/getting-started-with-appveyor-for-linux/