|
| 1 | +# npm install for components during CI (for projects that install components) |
| 2 | +- Create new Pipelines and link your GitHub project. |
| 3 | +- Clone your repo. |
| 4 | +- In the panel click "Edit" to open the yml file, then click on "Variables". |
| 5 | +- Click on "New variable", set Name to "BIT_TOKEN", and set Value need to be your bit token(bit config get user.token), then click on Save. |
| 6 | +- Create another variable and set Name to "BIT_COLLECTION", and the value to your bit collection that you want to export. |
| 7 | +- In your project root directory add an `.npmrc` file and put the following code inside: |
| 8 | +``` |
| 9 | +@bit:registry=https://node.bit.dev |
| 10 | +//node.bit.dev/:_authToken=$BIT_TOKEN |
| 11 | +always-auth=true |
| 12 | +``` |
| 13 | +create also `.env.local` file in your project root directory to be able to install localy from the registry: |
| 14 | +``` |
| 15 | +BIT_TOKEN=<copy the value you get from this: bit config get user.token> |
| 16 | +``` |
| 17 | +- Create an `npm-ci.sh` file in your project root directory with the following commands: |
| 18 | +``` |
| 19 | +npm install |
| 20 | +``` |
| 21 | +this will install all the dependencies from the pacakge.json. |
| 22 | +- Edit the `azure-pipelines.yml` file, with the following commands in script section: |
| 23 | +``` |
| 24 | +- script: | |
| 25 | + ./npm-ci.sh |
| 26 | +``` |
| 27 | +Make sure the file has execution permissions by running `chmod +x ./npm-ci.sh`. |
| 28 | +- Now you can run the pipelines and the build should work. |
| 29 | +Learn more about [variables in Azure DevOps](https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch) |
| 30 | + |
| 31 | +# bit import from private components during CI |
| 32 | +If you project import a component from with `bit import ...`, and your package.json have a dependencies with a locale link to components folder like this, follow the following setups: |
| 33 | +``` |
| 34 | +"@bit/<USER-NAME>.<COLLECTION-NAME>.<COMPONENT-ID>": "file:./components/<COMPONENT-ID>" |
| 35 | +``` |
| 36 | +- Edit the `npm-ci.sh` and add this command: `npm install bit-bin -g`, now the file should look like this: |
| 37 | +``` |
| 38 | +npm install |
| 39 | +npm install bit-bin -g |
| 40 | +``` |
| 41 | +- Add this command in your package.json to import the components and build them: |
| 42 | +``` |
| 43 | +"scripts": { |
| 44 | + ... |
| 45 | + "bit-build": "bit -v && bit import && bit build" |
| 46 | + }, |
| 47 | +``` |
| 48 | +- Edit the `azure-pipelines.yml`file to configure bit on the server and to run the `bit-build` command before building the project: |
| 49 | +``` |
| 50 | +- script: | |
| 51 | + ./npm-ci.sh |
| 52 | + |
| 53 | + bit config set analytics_reporting false |
| 54 | + bit config set anonymous_reporting false |
| 55 | + bit config set user.token $(BIT_TOKEN) |
| 56 | + bit config |
| 57 | + |
| 58 | + npm run bit-build |
| 59 | + npm run build |
| 60 | +
|
| 61 | + displayName: 'npm install & build' |
| 62 | +``` |
| 63 | + |
| 64 | +# bit export to private collection during CI |
| 65 | +- Create a private collection in [bit.dev](bit.dev). |
| 66 | +- Import the compiler you need. |
| 67 | +- Track, Tag and export components to your collection, [Alert component for example](src/components/Alert.js). |
| 68 | +- Modify the `azure-pipelines.yml` file, and add the bit tag and bit export commands after the build: |
| 69 | +``` |
| 70 | +- script: | |
| 71 | + ./npm-ci.sh |
| 72 | + |
| 73 | + bit config set analytics_reporting false |
| 74 | + bit config set anonymous_reporting false |
| 75 | + bit config set user.token $(BIT_TOKEN) |
| 76 | + bit config |
| 77 | + |
| 78 | + npm run bit-build |
| 79 | + npm run build |
| 80 | + |
| 81 | + bit status |
| 82 | + bit tag -a |
| 83 | + bit export $(BIT_COLLECTION) |
| 84 | +
|
| 85 | + displayName: 'npm install & bit config & npm build & bit export components if needed' |
| 86 | +``` |
| 87 | + |
| 88 | +# git commit back after exported new version components during CI |
| 89 | +- First you need to allow azure to do this changes, follow this setups in [azure](https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/git-commands?view=azure-devops&tabs=yaml). |
| 90 | +- Create a `git-ci.sh` file in the root of your project, and add the following commands: |
| 91 | +``` |
| 92 | +git config --global user.email "[email protected]" |
| 93 | +git config --global user.name "Your Name" |
| 94 | +git checkout master |
| 95 | +git add . |
| 96 | +git commit -m "This is a commit message from azure pipelines [skip ci]" |
| 97 | +git push -u origin master |
| 98 | +``` |
| 99 | +Make sure the file has execution permissions by running `chmod +x ./git-ci.sh`. |
| 100 | +- Edit the `azure-pipelines.yml` file and add just one line to run this file: |
| 101 | +``` |
| 102 | +- script: | |
| 103 | + ./npm-ci.sh |
| 104 | + |
| 105 | + bit config set analytics_reporting false |
| 106 | + bit config set anonymous_reporting false |
| 107 | + bit config set user.token $(BIT_TOKEN) |
| 108 | + bit config |
| 109 | + |
| 110 | + npm run bit-build |
| 111 | + npm run build |
| 112 | + |
| 113 | + bit status |
| 114 | + bit tag -a |
| 115 | + bit export $(BIT_COLLECTION) |
| 116 | +
|
| 117 | + ./git-ci.sh |
| 118 | +
|
| 119 | + displayName: 'npm install & bit config & npm build & bit export components if needed & git commit back' |
| 120 | +``` |
| 121 | +- Now you can change your components, and commit the changes, and every thing should work in the CI. |
| 122 | +- After this, the workspace need be update with all the changes the CI do with new version of components, to do this just run the following command to get all the updates: |
| 123 | +``` |
| 124 | +git pull |
| 125 | +bit import |
| 126 | +``` |
0 commit comments