Skip to content

Updated unit test to test get-by-id route #78

Updated unit test to test get-by-id route

Updated unit test to test get-by-id route #78

Workflow file for this run

# Continuous Integration (CI) Workflow
name: ci
# This workflow will run whenever we push commits to the `main` branch, or
# whenever there's a pull request to the `main` branch. See:
# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#on
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
lint:
# Give your job a name that will show up in the GitHub Actions web UI
name: ESLint
# We'll run this on a Linux (Ubuntu) VM, since we'll deploy on Linux too.
runs-on: ubuntu-latest
# We run these steps one after the other, and if any fail, we stop the process
steps:
# https://github.com/actions/checkout
- name: Check out code
uses: actions/checkout@v3
# https://github.com/actions/setup-node
- name: Setup node
uses: actions/setup-node@v3
with:
# Use node LTS version 18 - https://github.com/actions/setup-node#supported-version-syntax
node-version: '18'
# Cache npm dependencies so they don't have to be downloaded next time - https://github.com/actions/setup-node#caching-packages-dependencies
cache: 'npm'
- name: Install node dependencies
# Use `ci` vs. `install`, see https://docs.npmjs.com/cli/v8/commands/npm-ci
run: npm ci
- name: Run ESLint
run: npm run lint
# Lint our Dockerfile using Hadolint
dockerfile-lint:
name: Dockerfile Lint
runs-on: ubuntu-latest
steps:
# https://github.com/marketplace/actions/hadolint-action
- uses: actions/checkout@v3
- uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: Dockerfile
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install node dependencies and run Tests
# There are two ways we could do this:
#
# 1. Call `npm ci` followed by `npm test` like so (NOTE: the use of | and -):
# run: |
# - npm install
# - npm test
#
# 2. Use `install-ci-test` to do it in a single command, see https://docs.npmjs.com/cli/v8/commands/npm-install-ci-test
# run: npm install-ci-test
run: npm install-ci-test
docker-hub:
name: Build and Push to Docker Hub
# Don't bother running this job unless the other three all pass
needs: [lint, dockerfile-lint, unit-tests, integration-tests]
runs-on: ubuntu-latest
steps:
# Set up buildx for optimal Docker Builds, see:
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Login to Docker Hub using GitHub secrets, see:
# https://github.com/docker/login-action
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Build and Push an Image to Docker Hub
- name: Build and push
env:
# Define an Environment Variable with our Docker Hub Repo
# Replace `username` with your Docker Hub username and `fragments
# with whatever you've named your Docker Hub repo
DOCKERHUB_REPO: avelynhc/fragments
# Define an Environment Variable with the current git commit's
# sha: sha-87f664e01bb5f242faa411e9e7fb9e75a58ae767
# Use the `github` context to get this, see:
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
SHA_TAG: sha-${{ github.sha }}
uses: docker/build-push-action@v4
with:
push: true
# Use 3 tags :sha-sha-7d821bd14e0d6c381dc57a5369ae1a3a9220664f, :main, and :latest
tags: ${{ env.DOCKERHUB_REPO }}:${{ env.SHA_TAG }}, ${{ env.DOCKERHUB_REPO }}:main, ${{ env.DOCKERHUB_REPO }}:latest
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install node dependencies
# NOTE: we need to install dev dependencies too vs. production only for hurl
run: npm install
- name: Build Containers
run: docker compose up -d
- name: Setup Local AWS Resources
# NOTE: this file needs to be made executable *before* you check into git:
# $ chmod +x ./scripts/local-aws-setup.sh
run: ./scripts/local-aws-setup.sh
- name: Run Hurl Tests
run: npm run test:integration