You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 01-setup-ci/readme.md
+34-27Lines changed: 34 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,8 @@ In our case we're going to set up CI for a Node.js project. Let's start by creat
7
7
* Create `.github/workflows/ci.yml`
8
8
9
9
```bash
10
-
mkdir -p .gitub/workflows
11
-
touch .gitub/workflows/ci.yml
10
+
mkdir -p .github/workflows
11
+
touch .github/workflows/ci.yml
12
12
```
13
13
14
14
```yaml
@@ -25,7 +25,7 @@ jobs:
25
25
runs-on: ubuntu-latest
26
26
27
27
steps:
28
-
- name: inspect
28
+
- name: Inspect machine
29
29
run: |
30
30
ls -al
31
31
whoami
@@ -38,34 +38,34 @@ jobs:
38
38
Let's commit this file to a new branch:
39
39
40
40
```bash
41
-
git checkout -b added-basic-workflow
42
-
git push -u origin added-basic-workflow
41
+
git checkout -b add-basic-workflow
42
+
git push -u origin add-basic-workflow
43
43
git add .
44
-
git commit -m "added ci file"
44
+
git commit -m "added ci workflow file"
45
45
git push
46
46
```
47
47
48
48
Now if we move to GitHub web site, we will find a message to create a new pull request. Let's click on `Compare & pull request`. Now click on `Create pull request`.
49
49
50
50
We can see that a new action starts, and by default is going to check if CI process has succeded before allow us to merge this branch into main branch.
51
51
52
-
> The workflow is triggered by `pull_request` event.
52
+
> The workflow is triggered by `pull_request` event.
53
53
54
54
If we open the action job audit from website and have a look into the steps, we can notice a couple of things:
* There's no contents inside the current directory.
65
+
* Our user is runner
66
+
* Node is already installed
67
67
68
-
Let's solve this by getting the code into workflow context.
68
+
Now, let's get the code into workflow context.
69
69
70
70
* Update `ci.yml`
71
71
@@ -83,7 +83,8 @@ jobs:
83
83
runs-on: ubuntu-latest
84
84
85
85
steps:
86
-
+ - uses: actions/checkout@v3
86
+
+ - name: Checkout # This field is optional
87
+
+ - uses: actions/checkout@v4
87
88
- name: inspect
88
89
run: |
89
90
ls -al
@@ -93,7 +94,7 @@ jobs:
93
94
94
95
```
95
96
96
-
Recall that on job steps we can use and action or run a command, here we're using an action `actions/checkout@v3`, that no needs further configuration.
97
+
Recall that on job steps we can use an action or run a command. Here we're using an action `actions/checkout@v4` that needs no further configuration.
97
98
98
99
```bash
99
100
git add .
@@ -103,7 +104,7 @@ git push
103
104
104
105
Now if we go back to the last action job, we will find out that our code has been download:
105
106
106
-
```
107
+
```bash
107
108
total 44
108
109
drwxr-xr-x 11 runner docker 4096 Oct 9 18:17 .
109
110
drwxr-xr-x 3 runner docker 4096 Oct 9 18:17 ..
@@ -121,14 +122,13 @@ runner
121
122
v16.17.1
122
123
```
123
124
124
-
Really nice, out target is that this workflow implements the CI process.
125
-
125
+
Really nice, but our target is that this workflow implements the CI process.
126
126
127
127
> **Continous Integration (CI)** - The process of automating the build and testing of changes when a commit is pushed to a branch.
128
128
129
-
Lets remove the current job and add new one that builds and test our code:
129
+
Lets remove the current job and add new one that builds and tests our code:
130
130
131
-
````diff
131
+
```diff
132
132
name: CI
133
133
134
134
on:
@@ -142,15 +142,15 @@ jobs:
142
142
- runs-on: ubuntu-latest
143
143
144
144
- steps:
145
-
- - uses: actions/checkout@v3
145
+
- - uses: actions/checkout@v4
146
146
- - name: inspect
147
147
- run: |
148
148
- ls -al
149
149
- whoami
150
150
- pwd
151
151
- node -v
152
152
153
-
````
153
+
```
154
154
155
155
```yaml
156
156
name: CI
@@ -167,11 +167,11 @@ jobs:
167
167
runs-on: ubuntu-latest
168
168
169
169
steps:
170
-
- uses: actions/checkout@v3
170
+
- uses: actions/checkout@v4
171
171
- name: build and test
172
172
working-directory: ./hangman-api
173
173
run: |
174
-
npm ci
174
+
npm ci
175
175
npm run build --if-present
176
176
ls ./dist
177
177
npm test
@@ -180,12 +180,11 @@ jobs:
180
180
181
181
```bash
182
182
git add .
183
-
git commit -m "added build test step"
183
+
git commit -m "added build and test step"
184
184
git push
185
185
```
186
186
187
-
We can check the results in actions. For last, because we're going to add more projects to current solution, seems a good idea that the workflow only starts if the contents of api solution are updated.
188
-
187
+
We can check the results in actions (GitHub website). Since we're going to add more projects to the current solution, it seems a good idea that the workflow only starts if the contents of api project are updated.
189
188
190
189
* Update `ci.yml`
191
190
@@ -205,7 +204,7 @@ jobs:
205
204
runs-on: ubuntu-latest
206
205
207
206
steps:
208
-
- uses: actions/checkout@v3
207
+
- uses: actions/checkout@v4
209
208
- name: build and test
210
209
working-directory: ./hangman-api
211
210
run: |
@@ -218,4 +217,12 @@ jobs:
218
217
219
218
* With `paths` we filter the directories that are able to trigger a new workflow.
220
219
221
-
> Check the [filter pattern cheat sheet](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet) for a better understanding
220
+
> Check the [filter pattern cheat sheet](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet) for a better understanding.
221
+
222
+
```bash
223
+
git add .
224
+
git commit -m "added path filter"
225
+
git push
226
+
```
227
+
228
+
If we check again 'Actions' tab, we will not see a new trigger. Why? Because the latest changes did not modify `hangman-api` folder.
0 commit comments