Skip to content

Commit 729e78e

Browse files
authored
Merge pull request #4 from Lemoncode/bootcamp-update-2023
Bootcamp update 2023
2 parents 62ea0c0 + 898defe commit 729e78e

22 files changed

Lines changed: 680 additions & 221 deletions

File tree

.github/workflows/cd-docker.yml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,28 @@ jobs:
1212
# runs-on: ubuntu-latest
1313

1414
# steps:
15-
# - uses: actions/checkout@v3
16-
# - uses: actions/setup-node@v3
17-
# with:
18-
# node-version: 16
19-
# cache: 'npm'
20-
# cache-dependency-path: hangman-api/package-lock.json
21-
# - name: build
22-
# working-directory: ./hangman-api
23-
# run: |
24-
# npm ci
25-
# npm run build --if-present
26-
# - uses: actions/upload-artifact@v3
27-
# with:
28-
# name: build-code
29-
# path: hangman-api/dist/
30-
15+
# - uses: actions/checkout@v4
16+
# - uses: actions/setup-node@v4
17+
# with:
18+
# node-version: 16
19+
# cache: 'npm'
20+
# cache-dependency-path: hangman-api/package-lock.json
21+
# - name: build
22+
# working-directory: ./hangman-api
23+
# run: |
24+
# npm ci
25+
# npm run build --if-present
26+
# - uses: actions/upload-artifact@v3
27+
# with:
28+
# name: build-code
29+
# path: hangman-api/dist/
3130

3231
delivery:
33-
3432
runs-on: ubuntu-latest
3533
needs: build
3634

3735
steps:
38-
- uses: actions/checkout@v3
36+
- uses: actions/checkout@v4
3937
- uses: actions/download-artifact@v3
4038
with:
4139
name: build-code
@@ -49,6 +47,6 @@ jobs:
4947
run: |
5048
echo $DOCKER_PASSWORD | docker login --username $DOCKER_USER --password-stdin
5149
image=$DOCKER_USER/$DOCKER_REPOSITORY:$(date +%s)
52-
docker build . --file Dockerfile.workflow --tag $image
50+
docker build -t $image -f Dockerfile.workflow .
5351
docker push $image
54-
52+

.github/workflows/ci.yml

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
name: CI
1+
name: CI
22

33
on:
44
# push:
55
# branches: [ main ]
66
# paths: [ 'hangman-api/**' ]
77
workflow_dispatch:
8-
8+
99
pull_request:
10-
branches: [ main ]
11-
paths: [ 'hangman-api/**' ]
10+
branches: [main]
11+
paths: ["hangman-api/**"]
1212

1313
jobs:
1414
build:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v3
19-
- uses: actions/setup-node@v3
20-
with:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-node@v4
20+
with:
2121
node-version: 16
22-
cache: 'npm'
22+
cache: "npm"
2323
cache-dependency-path: hangman-api/package-lock.json
2424
- name: build
2525
working-directory: ./hangman-api
@@ -31,9 +31,9 @@ jobs:
3131
runs-on: ubuntu-latest
3232
needs: build
3333

34-
steps:
35-
- uses: actions/checkout@v3
36-
- uses: actions/setup-node@v3
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-node@v4
3737
with:
3838
node-version: 16
3939
- name: test
@@ -50,8 +50,8 @@ jobs:
5050
postgres:
5151
image: postgres:14-alpine
5252
env:
53-
POSTGRES_USER: postgres
54-
POSTGRES_PASSWORD: postgres
53+
POSTGRES_USER: postgres
54+
POSTGRES_PASSWORD: postgres
5555
POSTGRES_DB: hangman_db
5656
# Set health checks to wait until postgres has started
5757
options: >-
@@ -63,12 +63,12 @@ jobs:
6363
- 5432:5432
6464

6565
steps:
66-
- uses: actions/checkout@v3
67-
- uses: actions/setup-node@v3
66+
- uses: actions/checkout@v4
67+
- uses: actions/setup-node@v4
6868
with:
6969
node-version: 16
7070
# - name: Create database relationships
71-
- name: Running integration tests
71+
- name: Running integration tests
7272
working-directory: ./hangman-api
7373
env:
7474
DATABASE_PORT: 5432
@@ -82,5 +82,3 @@ jobs:
8282
npm ci
8383
npx knex migrate:latest --env development
8484
npm run test:integration
85-
86-
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: Reusable Node Build
1+
name: Reusable Node Build
22

3-
on:
3+
on:
44
workflow_call:
55
inputs:
6-
node-version:
6+
node-version:
77
required: true
88
type: number
99
working-directory:
@@ -15,18 +15,18 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v3
19-
- uses: actions/setup-node@v3
20-
with:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-node@v4
20+
with:
2121
node-version: ${{ inputs.node-version }}
22-
cache: 'npm'
22+
cache: "npm"
2323
cache-dependency-path: ${{ inputs.working-directory }}/package-lock.json
24-
- name: build
24+
- name: build
2525
working-directory: ${{ inputs.working-directory }}
2626
run: |
2727
npm ci
2828
npm run build --if-present
29-
- uses: actions/upload-artifact@v3
29+
- uses: actions/upload-artifact@v3
3030
with:
3131
name: build-code
3232
path: ${{ inputs.working-directory }}/dist/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Workflow to test the custom action
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
get_commodity_price:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Get commodity price step
12+
id: commodity_price
13+
uses: jtrillo/get-commodity-price@v1.0.1
14+
with:
15+
commodity: silver
16+
# Use the output from 'commodity_price' step
17+
- name: Get the output price
18+
run: echo "Price per ounce is ${{ steps.commodity_price.outputs.price }} USD"

.start-code/hangman-api/src/dals/games/game.dal.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ beforeEach(async () => {
2323

2424
describe('game.dal', () => {
2525
describe('getGames', () => {
26-
test('resturns the games related to a player', async () => {
26+
test('returns the games related to a player', async () => {
2727
// Arrange
2828
const playersDAL = playerDALFactory(db);
2929
const wordsDAL = wordDALFactory(db);

01-setup-ci/readme.md

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff 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
77
* Create `.github/workflows/ci.yml`
88

99
```bash
10-
mkdir -p .gitub/workflows
11-
touch .gitub/workflows/ci.yml
10+
mkdir -p .github/workflows
11+
touch .github/workflows/ci.yml
1212
```
1313

1414
```yaml
@@ -25,7 +25,7 @@ jobs:
2525
runs-on: ubuntu-latest
2626

2727
steps:
28-
- name: inspect
28+
- name: Inspect machine
2929
run: |
3030
ls -al
3131
whoami
@@ -38,34 +38,34 @@ jobs:
3838
Let's commit this file to a new branch:
3939
4040
```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
4343
git add .
44-
git commit -m "added ci file"
44+
git commit -m "added ci workflow file"
4545
git push
4646
```
4747

4848
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`.
4949

5050
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.
5151

52-
> The workflow is triggered by `pull_request` event.
52+
> The workflow is triggered by `pull_request` event.
5353
5454
If we open the action job audit from website and have a look into the steps, we can notice a couple of things:
5555

56-
```
56+
```bash
5757
drwxr-xr-x 2 runner docker 4096 Oct 9 18:03 .
5858
drwxr-xr-x 3 runner docker 4096 Oct 9 18:03 ..
5959
runner
6060
/home/runner/work/github-actions-playground/github-actions-playground
6161
v16.17.1
6262
```
6363

64-
* Node is already installed
65-
* Our user is runner
6664
* There's no contents inside the current directory.
65+
* Our user is runner
66+
* Node is already installed
6767

68-
Let's solve this by getting the code into workflow context.
68+
Now, let's get the code into workflow context.
6969

7070
* Update `ci.yml`
7171

@@ -83,7 +83,8 @@ jobs:
8383
runs-on: ubuntu-latest
8484

8585
steps:
86-
+ - uses: actions/checkout@v3
86+
+ - name: Checkout # This field is optional
87+
+ - uses: actions/checkout@v4
8788
- name: inspect
8889
run: |
8990
ls -al
@@ -93,7 +94,7 @@ jobs:
9394

9495
```
9596

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.
9798

9899
```bash
99100
git add .
@@ -103,7 +104,7 @@ git push
103104

104105
Now if we go back to the last action job, we will find out that our code has been download:
105106

106-
```
107+
```bash
107108
total 44
108109
drwxr-xr-x 11 runner docker 4096 Oct 9 18:17 .
109110
drwxr-xr-x 3 runner docker 4096 Oct 9 18:17 ..
@@ -121,14 +122,13 @@ runner
121122
v16.17.1
122123
```
123124

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.
126126

127127
> **Continous Integration (CI)** - The process of automating the build and testing of changes when a commit is pushed to a branch.
128128
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:
130130

131-
````diff
131+
```diff
132132
name: CI
133133

134134
on:
@@ -142,15 +142,15 @@ jobs:
142142
- runs-on: ubuntu-latest
143143

144144
- steps:
145-
- - uses: actions/checkout@v3
145+
- - uses: actions/checkout@v4
146146
- - name: inspect
147147
- run: |
148148
- ls -al
149149
- whoami
150150
- pwd
151151
- node -v
152152

153-
````
153+
```
154154

155155
```yaml
156156
name: CI
@@ -167,11 +167,11 @@ jobs:
167167
runs-on: ubuntu-latest
168168

169169
steps:
170-
- uses: actions/checkout@v3
170+
- uses: actions/checkout@v4
171171
- name: build and test
172172
working-directory: ./hangman-api
173173
run: |
174-
npm ci
174+
npm ci
175175
npm run build --if-present
176176
ls ./dist
177177
npm test
@@ -180,12 +180,11 @@ jobs:
180180

181181
```bash
182182
git add .
183-
git commit -m "added build test step"
183+
git commit -m "added build and test step"
184184
git push
185185
```
186186

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.
189188

190189
* Update `ci.yml`
191190

@@ -205,7 +204,7 @@ jobs:
205204
runs-on: ubuntu-latest
206205

207206
steps:
208-
- uses: actions/checkout@v3
207+
- uses: actions/checkout@v4
209208
- name: build and test
210209
working-directory: ./hangman-api
211210
run: |
@@ -218,4 +217,12 @@ jobs:
218217

219218
* With `paths` we filter the directories that are able to trigger a new workflow.
220219

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

Comments
 (0)