Skip to content

Commit

Permalink
Merge pull request #234 from 18F/add_linting
Browse files Browse the repository at this point in the history
Add linting support
  • Loading branch information
levinmr authored Feb 16, 2024
2 parents a59151a + 0eebbaa commit ba90f16
Show file tree
Hide file tree
Showing 24 changed files with 1,230 additions and 2,386 deletions.
248 changes: 101 additions & 147 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,53 @@
version: 2.1

restore_npm_cache: &restore_npm_cache
restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-

install_npm_packages: &install_npm_packages
run:
name: install dependencies
command: npm install

save_npm_cache: &save_npm_cache
save_cache:
paths:
- ./node_modules
key: v1-dependencies-{{ checksum "package.json" }}

fix_file_suffixes_for_cloud_gov: &fix_file_suffixes_for_cloud_gov
run:
name: Delete Config.js and drop sufffix on Config.js.cloudgov
command: |
rm ./src/config.js
mv ./src/config.js.cloudgov ./src/config.js
rm knexfile.js
mv knexfile.js.cloudgov knexfile.js
install_cf_cli: &install_cf_cli
run:
name: Install CF CLI
command: |
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
jobs:
develop_deploy:
lint_js:
docker:
- image: cimg/node:16.19.1-browsers
- image: cimg/node:20.11.0-browsers
steps:
- checkout
- *restore_npm_cache
- *install_npm_packages
- *save_npm_cache
- run:
name: lint javascript
command: npm run lint
test:
docker:
- image: cimg/node:20.11.0-browsers
environment:
POSTGRES_USER: postgres
NODE_ENV: test
Expand All @@ -11,25 +56,20 @@ jobs:
POSTGRES_DB: analytics-api-test
steps:
- checkout

- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-

- run:
name: install dependencies
command: npm install

- save_cache:
paths:
- ./node_modules
key: v1-dependencies-{{ checksum "package.json" }}

- *restore_npm_cache
- *install_npm_packages
- *save_npm_cache
- run:
name: run tests
command: npm test

name: unit test javascript
command: npm test
development_env_deploy:
docker:
- image: cimg/node:20.11.0-browsers
steps:
- checkout
- *restore_npm_cache
- *install_npm_packages
- *save_npm_cache
- run:
name: Replace Data URL in manifest.yml file when deploying to develop
command: |
Expand All @@ -39,26 +79,12 @@ jobs:
sed -i 's@- analytics-reporter-database@- analytics-reporter-database-develop@g' manifest.yml
mv manifest.yml manifest.yml.src
envsubst < manifest.yml.src > manifest.yml
- run:
name: Run sed on entrypoint.sh when deploying to develop
command: |
sed -i 's@NEW_RELIC_APP_NAME="analytics-reporter-api"@NEW_RELIC_APP_NAME="analytics-reporter-api-develop"@g' entrypoint.sh
- run:
name: Delete Config.js and drop sufffix on Config.js.cloudgov
command: |
rm ./src/config.js
mv ./src/config.js.cloudgov ./src/config.js
rm knexfile.js
mv knexfile.js.cloudgov knexfile.js
- run:
name: Install CF CLI
command: |
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
- *fix_file_suffixes_for_cloud_gov
- *install_cf_cli
- run:
name: deploy
command: |
Expand All @@ -71,37 +97,14 @@ jobs:
cf set-env analytics-reporter-api-develop API_DATA_GOV_SECRET "$API_SECRET_LOWER"
cf restage analytics-reporter-api-develop
cf logout
staging_deploy:
staging_env_deploy:
docker:
- image: cimg/node:16.19.1-browsers
environment:
POSTGRES_USER: postgres
NODE_ENV: test
- image: circleci/postgres:9.5-alpine
environment:
POSTGRES_DB: analytics-api-test
- image: cimg/node:20.11.0-browsers
steps:
- checkout

- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-

- run:
name: install dependencies
command: npm install

- save_cache:
paths:
- ./node_modules
key: v1-dependencies-{{ checksum "package.json" }}

- run:
name: run tests
command: npm test

- *restore_npm_cache
- *install_npm_packages
- *save_npm_cache
- run:
name: Replace Data URL in manifest.yml file when deploying to staging
command: |
Expand All @@ -111,26 +114,12 @@ jobs:
sed -i 's@- analytics-reporter-database@- analytics-reporter-database-staging@g' manifest.yml
mv manifest.yml manifest.yml.src
envsubst < manifest.yml.src > manifest.yml
- run:
name: Run sed on entrypoint.sh when deploying to staging
command: |
sed -i 's@NEW_RELIC_APP_NAME="analytics-reporter-api"@NEW_RELIC_APP_NAME="analytics-reporter-api-staging"@g' entrypoint.sh
- run:
name: Delete Knexfile.js and drop sufffix on Knexfile.js.cloudgov
command: |
rm knexfile.js
mv knexfile.js.cloudgov knexfile.js
rm ./src/config.js
mv ./src/config.js.cloudgov ./src/config.js
- run:
name: Install CF CLI
command: |
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
- *fix_file_suffixes_for_cloud_gov
- *install_cf_cli
- run:
name: deploy
command: |
Expand All @@ -143,37 +132,14 @@ jobs:
cf set-env analytics-reporter-api-staging API_DATA_GOV_SECRET "$API_SECRET_LOWER"
cf restage analytics-reporter-api-staging
cf logout
main_deploy:
production_env_deploy:
docker:
- image: cimg/node:16.19.1-browsers
environment:
POSTGRES_USER: postgres
NODE_ENV: test
- image: circleci/postgres:9.5-alpine
environment:
POSTGRES_DB: analytics-api-test
- image: cimg/node:20.11.0-browsers
steps:
- checkout

- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-

- run:
name: install dependencies
command: npm install

- save_cache:
paths:
- ./node_modules
key: v1-dependencies-{{ checksum "package.json" }}

- run:
name: run tests
command: npm test

- *restore_npm_cache
- *install_npm_packages
- *save_npm_cache
- run:
name: Replace Data URL in manifest.yml file when deploying to production
command: |
Expand All @@ -183,26 +149,12 @@ jobs:
sed -i 's@- analytics-reporter-database@- analytics-reporter-database-production@g' manifest.yml
mv manifest.yml manifest.yml.src
envsubst < manifest.yml.src > manifest.yml
- run:
name: Run sed on entrypoint.sh when deploying to main
command: |
sed -i 's@NEW_RELIC_APP_NAME="analytics-reporter-api"@NEW_RELIC_APP_NAME="analytics-reporter-api-production"@g' entrypoint.sh
- run:
name: Delete Knexfile.js and drop sufffix on Knexfile.js.cloudgov
command: |
rm knexfile.js
mv knexfile.js.cloudgov knexfile.js
rm ./src/config.js
mv ./src/config.js.cloudgov ./src/config.js
- run:
name: Install CF CLI
command: |
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
- *fix_file_suffixes_for_cloud_gov
- *install_cf_cli
- run:
name: deploy
command: |
Expand All @@ -216,28 +168,30 @@ jobs:
cf restage analytics-reporter-api-production
cf logout
workflows:
develop_workflow:
jobs:
- develop_deploy:
filters:
branches:
only:
ci:
jobs:
- lint
- test:
requires:
- lint
- development_env_deploy:
requires:
- test
filters:
branches:
only:
- develop

staging:
jobs:
- staging_deploy:
filters:
branches:
only:
- stage

main_workflow:
jobs:
- main_deploy:
filters:
branches:
only:
- staging_env_deploy:
requires:
- test
filters:
branches:
only:
- staging
- production_env_deploy:
requires:
- test
filters:
branches:
only:
- master

3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const eslintPluginPrettierRecommended = require("eslint-plugin-prettier/recommended");

module.exports = [eslintPluginPrettierRecommended];
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
if (process.env.NEW_RELIC_APP_NAME) {
console.log("Starting New Relic");
require("newrelic");
console.log("Starting New Relic");
require("newrelic");
}

const app = require('./src/app');
const config = require('./src/config');
const logger = require('./src/logger');
const app = require("./src/app");
const config = require("./src/config");
const logger = require("./src/logger");

app.listen(config.port, () => {
console.log(`Listening on ${config.port}`);
Expand Down
30 changes: 15 additions & 15 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = {
development: {
client: 'postgresql',
client: "postgresql",
connection: {
user: process.env.POSTGRES_USER || 'postgres',
password: process.env.POSTGRES_PASSWORD || '123abc',
database: process.env.POSTGRES_DATABASE || 'analytics-reporter',
}
user: process.env.POSTGRES_USER || "postgres",
password: process.env.POSTGRES_PASSWORD || "123abc",
database: process.env.POSTGRES_DATABASE || "analytics-reporter",
},
},
production: {
client: 'postgresql',
client: "postgresql",
connection: {
host: process.env.POSTGRES_HOST,
user: process.env.POSTGRES_USER,
Expand All @@ -17,20 +17,20 @@ module.exports = {
},
pool: {
min: 2,
max: 10
max: 10,
},
migrations: {
tableName: 'knex_migrations'
}
tableName: "knex_migrations",
},
},
test: {
client: 'postgresql',
client: "postgresql",
connection: {
user: process.env.CIRCLECI ? 'postgres' : undefined,
database: 'analytics-api-test'
user: process.env.CIRCLECI ? "postgres" : undefined,
database: "analytics-api-test",
},
migrations: {
tableName: 'knex_migrations'
}
}
tableName: "knex_migrations",
},
},
};
Loading

0 comments on commit ba90f16

Please sign in to comment.