Skip to content

Commit

Permalink
ci: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nischalstha9 committed Sep 5, 2024
1 parent cb0ac29 commit 3e0dd9c
Show file tree
Hide file tree
Showing 4 changed files with 511 additions and 3 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,26 @@ on:
workflow_dispatch:

jobs:
backend-test:
uses: hotosm/gh-workflows/.github/workflows/[email protected]
with:
image_name: ghcr.io/${{ github.repository }}/backend
pre_command: docker compose up -d traefik
compose_service: tm-backend
build_target: prod
compose_command: |
pip install flake8
flake8 manage.py backend tests migrations
pip install 'black==23.12.1'
black --check manage.py backend tests migrations
tag_override: ci-${{ github.ref_name }}
coverage: true
secrets: inherit

backend-build:
uses: hotosm/gh-workflows/.github/workflows/[email protected]
needs:
- backend-test
with:
context: .
build_target: prod
Expand All @@ -26,9 +44,24 @@ jobs:
scan_image: false
secrets: inherit

frontend-test:
uses: naxa-developers/tasking-manager/.github/workflows/frontend-test.yml@ci-gh-workflows
secrets: inherit
with:
node-version: 16.x
context: ./frontend
cache-key-file: ./frontend/yarn.lock
package-manager: yarn
test_frontend_build: false
test_frontend_command: |
CI=true yarn test -w 1
CI=true GENERATE_SOURCEMAP=false yarn build
frontend-build:
uses: naxa-developers/tasking-manager/.github/workflows/frontend-build.yml@ci-gh-workflows
secrets: inherit
needs:
- frontend-test
with:
node-version: 16.x
context: ./frontend
Expand Down Expand Up @@ -60,7 +93,7 @@ jobs:
- backend-build
uses: naxa-developers/tasking-manager/.github/workflows/remote_deploy_compose.yml@ci-gh-workflows
with:
docker_compose_file: docker-compose.vm.yml
docker_compose_file: docker-compose.yml
environment: ${{ github.ref_name }}
example_env_file_path: example.env
env_file_path: tasking-manager.env
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/frontend-build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: Node build
name: Node Frontend build

on:
workflow_call:
inputs:
runner-class:
description: "Github Runner class to use"
required: false
type: string
default: "ubuntu-latest"
node-version:
description: "Node version to use."
required: false
Expand Down Expand Up @@ -56,7 +61,7 @@ on:

jobs:
node-build:
runs-on: ubuntu-latest
runs-on: ${{ inputs.runner-class }}

environment:
name: ${{ github.ref_name }}
Expand Down
136 changes: 136 additions & 0 deletions .github/workflows/frontend-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Frontend Test

on:
workflow_call:
inputs:
runner-class:
description: "Github Runner class to use"
required: false
type: string
default: "ubuntu-latest"
node-version:
description: "Node version to use."
required: false
type: string
default: "18.x"
node-version-file:
description: "Node version file to use. node-version overrides this parameter."
required: false
type: string
default: ""
context:
description: "Root directory to start the build from."
required: false
type: string
default: "."
cache:
description: "Use node modules installation caching. Default true."
required: false
type: boolean
default: true
cache-key-file:
description: "Key file for cache."
required: false
type: string
default: "${{ inputs.context }}/package.json"
package-manager:
description: "Package manager to use. Supports [npm, yarn]"
required: false
type: string
default: "npm"
build-script-name:
description: "Build script name in package.json"
required: false
type: string
default: "build"
test_frontend_command:
description: "Testing command to run"
required: true
type: string
test_frontend_build:
description: "Perform a build test"
required: false
type: boolean
default: true

jobs:
node-build:
runs-on: ${{ inputs.runner-class }}

environment:
name: ${{ github.ref_name }}

outputs:
artifact-name: ${{ steps.get_artifact_name.outputs.artifact_name }}

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- id: node_setup
name: Install node
uses: actions/setup-node@v4
#reference: https://github.com/actions/setup-node
with:
node-version: ${{ inputs.node-version }}
node-version-file: ${{ inputs.node-version-file && inputs.node-version-file || '' }}

- name: Cache Node packages
uses: actions/cache@v3
env:
cache_name: node-${{ inputs.node-version || hashFiles(inputs.node-version-file) }}-${{ inputs.package-manager }}-${{ hashFiles(inputs.cache-key-file) }}
with:
key: ${{ runner.os }}-build-${{ env.cache_name }}
path: |
~/.npm
restore-keys: |
${{ runner.os }}-build-${{ env.cache_name }}
- id: node_packages_install
name: Install node pacakges
working-directory: ${{ inputs.context }}
run: |
case "${{ inputs.package-manager }}" in
yarn)
yarn
;;
npm)
npm i
;;
esac
- id: vars_and_secrets
name: Vars and Secrets to Env file
env:
VARS_CONTEXT: ${{ toJson(vars) }}
SECRETS_CONTEXT: ${{ toJson(secrets) }}
shell: bash
run: |
parsed_vars=$(jq -n --argjson VARS_CONTEXT "$VARS_CONTEXT" --argjson SECRETS_CONTEXT "$SECRETS_CONTEXT" "$VARS_CONTEXT+$SECRETS_CONTEXT")
to_envs() { jq -r "to_entries[] | \"\(.key)=\\\"\(.value)\\\"\n\""; }
echo "$parsed_vars" | to_envs > ${{ inputs.context }}/.env
- id: test_frontend
name: Test Frontend
working-directory: ${{ inputs.context }}
run: |
${{ inputs.test_frontend_command }}
- id: build_frontend
name: Build Frontend
if: ${{ inputs.test_frontend_build }}
working-directory: ${{ inputs.context }}
run: |
case "${{ inputs.package-manager }}" in
yarn)
yarn ${{ inputs.build-script-name }}
;;
npm)
npm run ${{ inputs.build-script-name }}
;;
esac
Loading

0 comments on commit 3e0dd9c

Please sign in to comment.