Skip to content

Commit 01664b9

Browse files
committed
first commit
0 parents  commit 01664b9

27 files changed

+13178
-0
lines changed

.bitmap

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* THIS IS A BIT-AUTO-GENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */
2+
3+
{
4+
"joshk.exported-with-azure-devops/[email protected]": {
5+
"files": [
6+
{
7+
"name": "Alert.js",
8+
"relativePath": "src/components/Alert.js",
9+
"test": false
10+
}
11+
],
12+
"mainFile": "src/components/Alert.js",
13+
"origin": "AUTHORED",
14+
"exported": true
15+
},
16+
"joshk.test-with-azure-import/[email protected]": {
17+
"files": [
18+
{
19+
"name": "Hello.js",
20+
"relativePath": "Hello.js",
21+
"test": false
22+
}
23+
],
24+
"mainFile": "Hello.js",
25+
"rootDir": "components/hello",
26+
"origin": "IMPORTED",
27+
"originallySharedDir": "src"
28+
},
29+
"version": "14.3.0"
30+
}

.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
/dist
14+
/components/**/dist
15+
/components/**/node_modules
16+
17+
# misc
18+
.DS_Store
19+
.env.local
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*

.npmrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@bit:registry=https://node.bit.dev
2+
//node.bit.dev/:_authToken=$BIT_TOKEN
3+
always-auth=true

README.md

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
```

azure-pipelines.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Node.js with React
2+
# Build a Node.js project that uses React.
3+
# Add steps that analyze code, save build artifacts, deploy, and more:
4+
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
5+
6+
trigger:
7+
- master
8+
9+
pool:
10+
vmImage: 'ubuntu-latest'
11+
12+
steps:
13+
- task: NodeTool@0
14+
inputs:
15+
versionSpec: '10.x'
16+
displayName: 'Install Node.js'
17+
- checkout: self
18+
persistCredentials: true
19+
20+
- script: |
21+
./npm-ci.sh
22+
23+
bit config set analytics_reporting false
24+
bit config set anonymous_reporting false
25+
bit config set user.token $(BIT_TOKEN)
26+
bit config
27+
28+
npm run bit-build
29+
npm run build
30+
31+
bit status
32+
bit tag -a
33+
bit export $(BIT_COLLECTION)
34+
35+
./git-ci.sh
36+
37+
displayName: 'npm install & bit config & npm build & bit export components if needed & git commit back'

components/hello/Hello.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React, { Component } from 'react'
2+
3+
export default class Hello extends Component {
4+
render(){
5+
return <div>Hello {this.props.name}</div>
6+
}
7+
}

components/hello/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* THIS IS A BIT-AUTO-GENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */
2+
3+
module.exports = require('./dist/Hello');

components/hello/package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/hello/package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@bit/joshk.test-with-azure-import.hello",
3+
"version": "0.0.2",
4+
"homepage": "https://bit.dev/joshk/test-with-azure-import/hello",
5+
"main": "dist/Hello.js",
6+
"dependencies": {},
7+
"devDependencies": {},
8+
"peerDependencies": {
9+
"react": "^16.9.0"
10+
},
11+
"license": "SEE LICENSE IN LICENSE",
12+
"bit": {
13+
"env": {
14+
"compiler": "bit.envs/compilers/[email protected]"
15+
}
16+
}
17+
}

git-ci.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
echo "start git commands"
2+
git config --global user.email "[email protected]"
3+
git config --global user.name "Josh Kuttler"
4+
git checkout master
5+
git add .
6+
git commit -m "This is a commit message from azure pipelines [skip ci]"
7+
git push -u origin master

npm-ci.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
echo "run npm install & install bit-bin -g"
2+
npm install
3+
npm install bit-bin -g

0 commit comments

Comments
 (0)