Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
ci(github-action): add workflow build
Browse files Browse the repository at this point in the history
  ## what
  - add workflow `build`
  - jobs
    - install: install npm packages and store to cache
    - lint: lint NextJS project
    - build: build NextJS project
    - semantic-release: run semantic-release

  ## how

  ## why
  - this will be used to CI/CD the repo
  - this will ensure the code is not breaking

  ## where
  - ./.github/workflows/build.yaml

  ## usage
  • Loading branch information
Clumsy-Coder committed Nov 5, 2023
1 parent 107fdd4 commit e3e5561
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
name: NextJS build and release
# description: lint, test, build and release NextJS
on: push

env:
FORCE_COLOR: true # display terminal colors
# APP_NAME: app_name
# GHCR_IMAGE: ghcr.io/<user>/<repo name>
CONTAINER_REGISTRY: ghcr.io
IMAGE_NAME: clumsy-coder/uva-uhunt

####################################################################################################

jobs:
# install npm packages and store them as cache.
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: latest

- name: Cache node modules
id: cache-primes
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-

# skip npm ci if `package.json` didn't change
# https://github.com/actions/cache#outputs
# https://github.com/actions/cache#restoring-and-saving-cache-using-a-single-action
- name: Install npm dependencies
if: steps.cache-primes.outputs.cache-hit != 'true'
run: npm ci --include=dev

################################################################################################
# lint source code using ESlint and Typescript
lint:
needs: install
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: latest

- name: Cache node modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-

- name: Lint project
run: npm run lint

################################################################################################
# build NextJS
build:
needs: install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: latest

- name: Cache node modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-

- name: build NextJS
run: npm run build

################################################################################################

semantic-release:
# prerequisite of a job that uses matrix
# https://github.com/orgs/community/discussions/42010#discussioncomment-4439644
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development'
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-node@v3
with:
node-version: latest

- name: Cache node modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-

- run: npm install --production=false

- name: semantic-release
run: npx semantic-release --ci
env:
GITHUB_TOKEN: ${{ secrets.DEPENDABOT_TOKEN }}

####################################################################################################

0 comments on commit e3e5561

Please sign in to comment.