Skip to content

Commit

Permalink
Bootcamp update 2023
Browse files Browse the repository at this point in the history
  • Loading branch information
JTrillo committed Dec 11, 2023
1 parent 62ea0c0 commit f362f02
Show file tree
Hide file tree
Showing 22 changed files with 680 additions and 221 deletions.
38 changes: 18 additions & 20 deletions .github/workflows/cd-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,28 @@ jobs:
# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-node@v3
# with:
# node-version: 16
# cache: 'npm'
# cache-dependency-path: hangman-api/package-lock.json
# - name: build
# working-directory: ./hangman-api
# run: |
# npm ci
# npm run build --if-present
# - uses: actions/upload-artifact@v3
# with:
# name: build-code
# path: hangman-api/dist/

# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: 16
# cache: 'npm'
# cache-dependency-path: hangman-api/package-lock.json
# - name: build
# working-directory: ./hangman-api
# run: |
# npm ci
# npm run build --if-present
# - uses: actions/upload-artifact@v3
# with:
# name: build-code
# path: hangman-api/dist/

delivery:

runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: build-code
Expand All @@ -49,6 +47,6 @@ jobs:
run: |
echo $DOCKER_PASSWORD | docker login --username $DOCKER_USER --password-stdin
image=$DOCKER_USER/$DOCKER_REPOSITORY:$(date +%s)
docker build . --file Dockerfile.workflow --tag $image
docker build -t $image -f Dockerfile.workflow .
docker push $image
34 changes: 16 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
name: CI
name: CI

on:
# push:
# branches: [ main ]
# paths: [ 'hangman-api/**' ]
workflow_dispatch:

pull_request:
branches: [ main ]
paths: [ 'hangman-api/**' ]
branches: [main]
paths: ["hangman-api/**"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
cache: 'npm'
cache: "npm"
cache-dependency-path: hangman-api/package-lock.json
- name: build
working-directory: ./hangman-api
Expand All @@ -31,9 +31,9 @@ jobs:
runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
- name: test
Expand All @@ -50,8 +50,8 @@ jobs:
postgres:
image: postgres:14-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: hangman_db
# Set health checks to wait until postgres has started
options: >-
Expand All @@ -63,12 +63,12 @@ jobs:
- 5432:5432

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
# - name: Create database relationships
- name: Running integration tests
- name: Running integration tests
working-directory: ./hangman-api
env:
DATABASE_PORT: 5432
Expand All @@ -82,5 +82,3 @@ jobs:
npm ci
npx knex migrate:latest --env development
npm run test:integration
18 changes: 9 additions & 9 deletions .github/workflows/reusable-node-build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Reusable Node Build
name: Reusable Node Build

on:
on:
workflow_call:
inputs:
node-version:
node-version:
required: true
type: number
working-directory:
Expand All @@ -15,18 +15,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: 'npm'
cache: "npm"
cache-dependency-path: ${{ inputs.working-directory }}/package-lock.json
- name: build
- name: build
working-directory: ${{ inputs.working-directory }}
run: |
npm ci
npm run build --if-present
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v3
with:
name: build-code
path: ${{ inputs.working-directory }}/dist/
18 changes: 18 additions & 0 deletions .github/workflows/test-custom-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Workflow to test the custom action

on:
workflow_dispatch:

jobs:
get_commodity_price:
runs-on: ubuntu-latest

steps:
- name: Get commodity price step
id: commodity_price
uses: jtrillo/get-commodity-price@v1.0.1
with:
commodity: silver
# Use the output from 'commodity_price' step
- name: Get the output price
run: echo "Price per ounce is ${{ steps.commodity_price.outputs.price }} USD"
2 changes: 1 addition & 1 deletion .start-code/hangman-api/src/dals/games/game.dal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ beforeEach(async () => {

describe('game.dal', () => {
describe('getGames', () => {
test('resturns the games related to a player', async () => {
test('returns the games related to a player', async () => {
// Arrange
const playersDAL = playerDALFactory(db);
const wordsDAL = wordDALFactory(db);
Expand Down
61 changes: 34 additions & 27 deletions 01-setup-ci/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ In our case we're going to set up CI for a Node.js project. Let's start by creat
* Create `.github/workflows/ci.yml`

```bash
mkdir -p .gitub/workflows
touch .gitub/workflows/ci.yml
mkdir -p .github/workflows
touch .github/workflows/ci.yml
```

```yaml
Expand All @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: inspect
- name: Inspect machine
run: |
ls -al
whoami
Expand All @@ -38,34 +38,34 @@ jobs:
Let's commit this file to a new branch:
```bash
git checkout -b added-basic-workflow
git push -u origin added-basic-workflow
git checkout -b add-basic-workflow
git push -u origin add-basic-workflow
git add .
git commit -m "added ci file"
git commit -m "added ci workflow file"
git push
```

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

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.

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

```
```bash
drwxr-xr-x 2 runner docker 4096 Oct 9 18:03 .
drwxr-xr-x 3 runner docker 4096 Oct 9 18:03 ..
runner
/home/runner/work/github-actions-playground/github-actions-playground
v16.17.1
```

* Node is already installed
* Our user is runner
* There's no contents inside the current directory.
* Our user is runner
* Node is already installed

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

* Update `ci.yml`

Expand All @@ -83,7 +83,8 @@ jobs:
runs-on: ubuntu-latest

steps:
+ - uses: actions/checkout@v3
+ - name: Checkout # This field is optional
+ - uses: actions/checkout@v4
- name: inspect
run: |
ls -al
Expand All @@ -93,7 +94,7 @@ jobs:

```

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

```bash
git add .
Expand All @@ -103,7 +104,7 @@ git push

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

```
```bash
total 44
drwxr-xr-x 11 runner docker 4096 Oct 9 18:17 .
drwxr-xr-x 3 runner docker 4096 Oct 9 18:17 ..
Expand All @@ -121,14 +122,13 @@ runner
v16.17.1
```

Really nice, out target is that this workflow implements the CI process.

Really nice, but our target is that this workflow implements the CI process.

> **Continous Integration (CI)** - The process of automating the build and testing of changes when a commit is pushed to a branch.
Lets remove the current job and add new one that builds and test our code:
Lets remove the current job and add new one that builds and tests our code:

````diff
```diff
name: CI

on:
Expand All @@ -142,15 +142,15 @@ jobs:
- runs-on: ubuntu-latest

- steps:
- - uses: actions/checkout@v3
- - uses: actions/checkout@v4
- - name: inspect
- run: |
- ls -al
- whoami
- pwd
- node -v

````
```

```yaml
name: CI
Expand All @@ -167,11 +167,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: build and test
working-directory: ./hangman-api
run: |
npm ci
npm ci
npm run build --if-present
ls ./dist
npm test
Expand All @@ -180,12 +180,11 @@ jobs:

```bash
git add .
git commit -m "added build test step"
git commit -m "added build and test step"
git push
```

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.

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.

* Update `ci.yml`

Expand All @@ -205,7 +204,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: build and test
working-directory: ./hangman-api
run: |
Expand All @@ -218,4 +217,12 @@ jobs:

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

> 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
> 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.
```bash
git add .
git commit -m "added path filter"
git push
```

If we check again 'Actions' tab, we will not see a new trigger. Why? Because the latest changes did not modify `hangman-api` folder.
Loading

0 comments on commit f362f02

Please sign in to comment.