{"id":19151623,"url":"https://github.com/cypress-io/commit-message-install","last_synced_at":"2025-05-07T05:41:02.923Z","repository":{"id":26043277,"uuid":"107187895","full_name":"cypress-io/commit-message-install","owner":"cypress-io","description":"NPM install a package by name taken from the last commit message","archived":false,"fork":false,"pushed_at":"2024-03-02T14:43:29.000Z","size":396,"stargazers_count":1,"open_issues_count":19,"forks_count":1,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-05-03T20:02:02.449Z","etag":null,"topics":["ci","cli","commit","git","message","npm","utility"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cypress-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-16T22:04:08.000Z","updated_at":"2021-06-15T12:18:44.000Z","dependencies_parsed_at":"2024-06-21T05:45:38.822Z","dependency_job_id":"19a97532-d8e5-4b36-994e-bccf4d050d5d","html_url":"https://github.com/cypress-io/commit-message-install","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cypress-io%2Fcommit-message-install","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cypress-io%2Fcommit-message-install/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cypress-io%2Fcommit-message-install/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cypress-io%2Fcommit-message-install/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cypress-io","download_url":"https://codeload.github.com/cypress-io/commit-message-install/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823656,"owners_count":21809707,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci","cli","commit","git","message","npm","utility"],"created_at":"2024-11-09T08:15:08.887Z","updated_at":"2025-05-07T05:41:02.889Z","avatar_url":"https://github.com/cypress-io.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @cypress/commit-message-install\n\n\u003e NPM install a package by name taken from the last commit message\n\n[![NPM][npm-icon] ][npm-url]\n\n[![Build status][ci-image] ][ci-url]\n[![semantic-release][semantic-image] ][semantic-url]\n[![js-standard-style][standard-image]][standard-url]\n[![renovate-app badge][renovate-badge]][renovate-app]\n\n## Install\n\nRequires [Node](https://nodejs.org/en/) version 6 or above.\n\n```sh\nnpm install --save-dev @cypress/commit-message-install\nyarn add -D @cypress/commit-message-install\n```\n\nor globally\n\n```sh\nnpm i -g @cypress/commit-message-install\nyarn global @cypress/commit-message-install\n```\n\n### Node version\n\nWe are trying to use the same minimum version of Node as Cypress\n\n## Use\n\n### Install NPM package from commit message\n\nImagine you have a CI build that installs NPM dependencies, but you also want to\noverride one or more dependencies and test by creating a commit. Instead of changing\n`package.json` you can make a commit message with embedded JSON block describing\ncustom installation. Then use this CLI tool to install based on the commit message.\n\nExample CI file command\n\n```\n- npm i -g @cypress/commit-message-install\n- commit-message-install\n```\n\nIf commit message is this\n\n```\nthis will install package debug and chalk and while\ninstalling them will set environment variable FOO to \"bar\".\nThe install will happen on all platforms\n\n    ```json\n    {\n        \"platform\": \"*\",\n        \"architecture\": \"x64\",\n        \"packages\": \"debug,chalk\"\n    }\n    ```\n\nHappy installation\n```\n\n**note** `platform` can be `*` or specific one like `darwin` (from Node `os.platform()`) or a list of several platforms like `darwin,linux`. `architecture` is usually 64 bit `x64` as returned by `os.arch()`.\n\n### Specific commit\n\nYou can install using commit message from a specific commit (not the current one)\n\n```shell\n$ $(npm bin)/commit-message-install --sha f81a00\n```\n\n### Alternative command\n\nYou can specify a command to run *if commit message has no JSON block*. For example you can\ninstall default dependency\n\n```bash\n$ $(npm bin)/commit-message-install --else \"npm install foo-bar\"\n```\n\n### Run or skip command based on platform\n\nIf the commit message allows a specific platform, you can run any command, while\nsetting environment variables from the commit message. For example if th\ncommit message embeds the following JSON block\n\n```json\n{\n    \"platform\": \"win32\",\n    \"env\": {\n        \"FOO\": \"bar\"\n    }\n}\n```\n\nand the CI has command `run-if echo Foo is \\\\$FOO`, then on Windows CI it will print\n`Foo is bar` and on other platforms it will skip this step.\n\nIn general, if you use `commit-message-install` on the CI, then you should use `run-if` command as well!\nFor example, here are CircleCI steps that install default dependencies, but then run\nconditional steps\n\n```\nsteps:\n  - checkout\n  - run: npm install\n  - run: $(npm bin)/commit-message-install\n  - run: $(npm bin)/run-if $(npm bin)/cypress version\n  - run: DEBUG=cypress:cli $(npm bin)/run-if $(npm bin)/cypress verify\n```\n\n### Set GitHub commit status\n\nVery useful to notify other projects asynchronously via GitHub commit states.\n\n```text\n$(npm bin)/set-status --label \"context label\" --state success --description \"short message\"\n```\n\nState can be \"error\", \"pending\", \"failure\" or \"success\". `--label` is optional, if not set, then the platform and the package name will be used.\n\n### Has commit message\n\nYou can use script `has-message` to check if the last or a specific commit has JSON commit information block\n\n```text\n$(npm bin)/has-message\n$(npm bin)/has-message --sha f81a00\n```\n\nIf there is a message in the commit's body the script will exit with code 0. Otherwise it will exit with code 1.\n\nSee [commit-message-install-example](https://github.com/bahmutov/commit-message-install-example) repo for an example. Here is CircleCI halting if there is no commit message JSON\n\n```yml\n# install tool locally\n- run: npm install @cypress/commit-message-install\n- run: |\n    if ! $(npm bin)/has-message; then\n        echo Stopping early, no commit message\n        circleci-agent step halt\n    else\n        echo All good, found commit message JSON\n    fi\n```\n\n```yml\n# install tool globally using Yarn\n- run: yarn global @cypress/commit-message-install\n- run: |\n    if ! has-message; then\n        echo Stopping early, no commit message\n        circleci-agent step halt\n    else\n        echo All good, found commit message JSON\n    fi\n```\n\n## API\n\n### getJsonFromGit\n\nExtracts JSON block from the current Git message text\n\n```js\nconst {getJsonFromGit} = require('@cypress/commit-message-install')\ngetJsonFromGit()\n    .then(json =\u003e {\n        // {platform: 'win32', packages: 'foo', branch: 'test-branch'}\n    })\n```\n\nIf there is no valid JSON object in the message, resolves with `undefined`.\n\n### getInstallJson\n\nYou can form good Json object to be included in markdown `json` block in the body of\nthe commit message using provided function\n\n```js\nconst {getInstallJson} = require('@cypress/commit-message-install')\n// package(s), env, platform, branch name (optional)\nconst json = getInstallJson('foo',\n    {foo: 42}, 'linux', 'test-branch', 'b7ccfd8')\n// returns an object\n    // {\n    //   platform: \"linux\",\n    //   env: {foo: 42},\n    //   packages: \"foo\",\n    //   branch: \"test-branch\",\n    //   commit: \"b7ccfd8\"\n    // }\n```\n\nYou can pass individual package name like `debug` or several as a single string\n`debug chalk` or a list `['debug', 'chalk']`\n\nYou can pass for platform either individual `os.platform()` or a \"*\"\" for all, and even\nseveral platforms like `win32,linux` or `linux|darwin`.\n\n### npmInstall\n\nAfter getting JSON from a commit message you can install dependencies\n\n```js\nconst {getInstallJson, npmInstall} = require('@cypress/commit-message-install')\ngetInstallJson()\n  .then(npmInstall)\n```\n\n## Debugging\n\n- Run this tool with `DEBUG=commit-message-install` environment variable set\n- Force reading commit message from a local file with `--file \u003cfilename\u003e` option\n\n### Small print\n\nAuthor: Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt; \u0026copy; 2017\n\n* [@bahmutov](https://twitter.com/bahmutov)\n* [glebbahmutov.com](https://glebbahmutov.com)\n* [blog](https://glebbahmutov.com/blog)\n\nLicense: MIT - do anything with the code, but don't blame me if it does not work.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/cypress-io/commit-message-install/issues) on Github\n\n## MIT License\n\nCopyright (c) 2017 Cypress.io\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n[npm-icon]: https://nodei.co/npm/@cypress/commit-message-install.svg?downloads=true\n[npm-url]: https://npmjs.org/package/@cypress/commit-message-install\n[ci-image]: https://travis-ci.org/cypress-io/commit-message-install.svg?branch=master\n[ci-url]: https://travis-ci.org/cypress-io/commit-message-install\n[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-url]: https://github.com/semantic-release/semantic-release\n[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n[standard-url]: http://standardjs.com/\n[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg\n[renovate-app]: https://renovateapp.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcypress-io%2Fcommit-message-install","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcypress-io%2Fcommit-message-install","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcypress-io%2Fcommit-message-install/lists"}