diff --git a/.github/workflows/create_PR_from_feature.yml b/.github/workflows/create_PR_from_feature.yml index 782b9ea..4f1e4ce 100644 --- a/.github/workflows/create_PR_from_feature.yml +++ b/.github/workflows/create_PR_from_feature.yml @@ -50,3 +50,15 @@ jobs: if: always() with: comment_title: "Tests Results" + + lint: + runs-on: ubuntu-latest + needs: pr-to-test + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm run lint diff --git a/.github/workflows/deploy_to_production.yml b/.github/workflows/deploy_to_production.yml new file mode 100644 index 0000000..4414a1e --- /dev/null +++ b/.github/workflows/deploy_to_production.yml @@ -0,0 +1,31 @@ +name: Deploy a produccion + +on: [workflow_dispatch] + +jobs: + merge-and-deploy-to-production: + runs-on: ubuntu-latest + steps: + - name: Merge test -> main + uses: devmasx/merge-branch@master + with: + type: now + from_branch: test + target_branch: main + github_token: ${{ github.token }} + + - uses: actions/checkout@v3 + + - name: Build, Push and Release a Docker container to Heroku. + uses: gonuit/heroku-docker-deploy@v1.3.3 + with: + email: ${{ secrets.HEROKU_EMAIL }} + heroku_api_key: ${{ secrets.HEROKU_API_KEY }} + heroku_app_name: ${{ secrets.HEROKU_APP_NAME_MAIN }} + + - uses: HiromiShikata/gh-actions-move-all-cards-on-projects@v1.0.1 + with: + project_name: Features + from_column_name: Desplegado en Testing + to_column_name: Desplegado en Produccion + github_token: ${{ secrets.GHTOKEN }} diff --git a/.github/workflows/deploy_to_test.yml b/.github/workflows/deploy_to_test.yml index 057a535..8c3147b 100644 --- a/.github/workflows/deploy_to_test.yml +++ b/.github/workflows/deploy_to_test.yml @@ -17,15 +17,6 @@ jobs: steps: - uses: actions/checkout@v3 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - - run: npm ci - - run: npm run build --if-present - name: Build, Push and Release a Docker container to Heroku. uses: gonuit/heroku-docker-deploy@v1.3.3 @@ -39,18 +30,3 @@ jobs: apiKey: ${{ secrets.POSTMAN_API_KEY }} collection: ${{ secrets.POSTMAN_COLLECTION }} environment: ${{ secrets.POSTMAN_ENVIRONMENT }} - - - name: Merge test -> main - uses: devmasx/merge-branch@master - with: - type: now - from_branch: test - target_branch: main - github_token: ${{ github.token }} - - - uses: HiromiShikata/gh-actions-move-all-cards-on-projects@v1.0.1 - with: - project_name: Features - from_column_name: Desplegado en Testing - to_column_name: Desplegado en Produccion - github_token: ${{ secrets.GHTOKEN }} diff --git a/.gitignore b/.gitignore index 6704566..660b871 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,4 @@ dist # TernJS port file .tern-port +junit.xml diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..83af404 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npm run lint:fix diff --git a/package-lock.json b/package-lock.json index 97ad980..c1f9822 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@types/supertest": "^2.0.12", "cors": "^2.8.5", + "dotenv": "^16.0.1", "express": "^4.17.3", "mongoose": "^6.3.1", "reflect-metadata": "^0.1.13", @@ -24,6 +25,7 @@ "@types/node": "^17.0.25", "@typescript-eslint/eslint-plugin": "^5.21.0", "@typescript-eslint/parser": "^5.21.0", + "husky": "^8.0.1", "jest": "^28.1.0", "jest-junit": "^13.2.0", "nodemon": "^2.0.16", @@ -3681,6 +3683,21 @@ "node": ">=10.17.0" } }, + "node_modules/husky": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.1.tgz", + "integrity": "sha512-xs7/chUH/CKdOCs7Zy0Aev9e/dKOMZf3K1Az1nar3tzlv0jfqnYtu235bstsWTmXOR0EfINrPa97yy4Lz6RiKw==", + "dev": true, + "bin": { + "husky": "lib/bin.js" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -10046,6 +10063,12 @@ "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", "dev": true }, + "husky": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.1.tgz", + "integrity": "sha512-xs7/chUH/CKdOCs7Zy0Aev9e/dKOMZf3K1Az1nar3tzlv0jfqnYtu235bstsWTmXOR0EfINrPa97yy4Lz6RiKw==", + "dev": true + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", diff --git a/package.json b/package.json index d461174..b58d41c 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "start": "node dist/index.js", "lint": "eslint --ext ts,tsx .", "lint:fix": "eslint --ext ts,tsx . --fix", - "test": "jest --reporters='default' --reporters='jest-junit'" + "test": "jest --reporters='default' --reporters='jest-junit'", + "prepare": "husky install" }, "repository": { "type": "git", @@ -39,6 +40,7 @@ "@types/node": "^17.0.25", "@typescript-eslint/eslint-plugin": "^5.21.0", "@typescript-eslint/parser": "^5.21.0", + "husky": "^8.0.1", "jest": "^28.1.0", "jest-junit": "^13.2.0", "nodemon": "^2.0.16", diff --git a/src/index.ts b/src/index.ts index c65cd92..01b8cb3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,7 @@ const port = process.env.PORT || 4000; app.get('/', (_req, res) => { res.send('Hello World!!!!!!!!!!'); + }); db.connectDB(); diff --git a/tests/UserController.test.ts b/tests/UserController.test.ts index 548c089..2c8db5b 100644 --- a/tests/UserController.test.ts +++ b/tests/UserController.test.ts @@ -5,5 +5,6 @@ describe('test add function', () => { it('should start with four users', async () => { const response = await request(app).get('/users'); expect(response.body.users).toHaveLength(4); + }); }); \ No newline at end of file