Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor improvements to DX: jest running on src files; tweaks to GH actions #364

Merged
merged 2 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .github/workflows/docker.yml

This file was deleted.

123 changes: 112 additions & 11 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,133 @@ on:
push:
branches:
- develop

pull_request:

release:
types: [published]

jobs:
build:
runs-on: 'ubuntu-latest'
# deploy to staging by commiting to api-server-deployment repo
deploy-staging:
runs-on: ubuntu-latest
if: github.ref_name == 'develop'
needs: docker
steps:
- name: 'Checkout Project'
uses: 'actions/checkout@v4'
with:
fetch-depth: 1
repository: 'api-server-deployment'
token: ${{ secrets.GH_DEPLOYMENT_REPO_TOKEN }}
- uses: imranismail/setup-kustomize@v2
- run: |
kustomize edit set image vnguyen/openbeta-graph-api:sha-${GITHUB_SHA}
- name: Check if there are changes
id: changes
uses: UnicornGlobal/[email protected]
- name: Push if tag has changes
if: steps.changes.outputs.changed == 1
run: |
cd api-server-deployment/stage
git config user.name github-actions
git config user.email [email protected]
git commit -am "Update deployment. Code=${GITHUB_SHA}"
git push

# deploy to prod by commiting to api-server-deployment repo
deploy-prod:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
needs: docker
steps:
- name: Setup Node.js environment
uses: actions/setup-node@v3
- name: 'Checkout Project'
uses: 'actions/checkout@v4'
with:
node-version: '16.15'
fetch-depth: 1
repository: 'api-server-deployment'
token: ${{ secrets.GH_DEPLOYMENT_REPO_TOKEN }}
- uses: imranismail/setup-kustomize@v2
- run: |
kustomize edit set image vnguyen/openbeta-graph-api:${GITHUB_REF}
- name: Check if there are changes
id: changes
uses: UnicornGlobal/[email protected]
- name: Push if tag has changes
if: steps.changes.outputs.changed == 1
run: |
git config user.name github-actions
git config user.email [email protected]
git commit -am "Update deployment. Code=${GITHUB_REF}"
git push

# build docker image and push to registry
docker:
runs-on: ubuntu-latest
needs: test
steps:
- name: 'Checkout Project'
uses: 'actions/checkout@v3'
with:
fetch-depth: 1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
vnguyen/openbeta-graph-api
tags: |
type=ref,event=branch
type=semver,pattern={{raw}}
type=ref,event=pr
type=sha,format=long

- name: Build docker image
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ steps.meta.outputs.tags }}

# setup basic machine to run all kinds of tests: lint, unit, integration, types
test:
runs-on: 'ubuntu-latest'
steps:
- name: 'Checkout Project'
uses: 'actions/checkout@v3'
with:
fetch-depth: 1

- name: Install Dependencies and lint code
run: yarn install && yarn lint
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '16.15'
cache: 'yarn'

- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 5
mongodb-replica-set: rs0

- name: Install dependencies
run: yarn install --immutable

- name: Lint code
run: yarn lint

- name: Wait for the database to start
run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- localhost:27017 -- echo "Database is up"
env:
Expand All @@ -44,8 +145,8 @@ jobs:
run: |
docker container restart mongodb

- name: Build and run tests
run: yarn test
env:
NODE_OPTIONS: --experimental-vm-modules
- name: Run tests
run: yarn test --ci

- name: Build sources
run: yarn build-release --noEmit
15 changes: 13 additions & 2 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
module.exports = {
preset: 'ts-jest',
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1'
},
extensionsToTreatAsEsm: ['.ts'],
transform: {
'^.+\\.(mt|t|cj|j)s$': [
'ts-jest',
{
useESM: true
}
]
},
testEnvironment: 'node',
testMatch: [
'<rootDir>/build/**/__tests__/*.js'
'<rootDir>/**/__tests__/*.ts'
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"scripts": {
"lint": "yarn ts-standard",
"fix": "yarn ts-standard --fix",
"test": "yarn build && cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --runInBand",
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --runInBand",
"build": "tsc -p tsconfig.json",
"build-release": "tsc -p tsconfig.release.json",
"clean": "tsc -b --clean && rm -rf build/*",
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"module": "ESNext",
"esModuleInterop": true,
"moduleResolution": "Node",
"rootDir": "./src",
"outDir": "build",
"sourceMap": true,
"strictNullChecks": true,
Expand All @@ -21,4 +20,4 @@
"include": [
"src/**/*.ts",
]
}
}
Loading