From 0224ace851ac4fea01eefa82e04fa782fb0146d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Molini=C3=A9?= Date: Fri, 15 Jan 2021 17:56:12 +0100 Subject: [PATCH 1/5] ci: move from travis to github action --- .github/workflows/build.yml | 89 +++++++++++++++++++++++++++++++++++++ .travis.yml | 37 --------------- README.md | 2 +- commitlint.config.js | 6 +-- package.json | 1 - yarn.lock | 11 +---- 6 files changed, 94 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..6b81fd09 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,89 @@ +name: Build, Test and Deploy + +on: + push: + branches: + - master + - beta + pull_request: + +env: + TZ: 'Europe/Paris' + +jobs: + lint: + name: Linting + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - name: Cancel previous running workflows + uses: fkirc/skip-duplicate-actions@master + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/setup-node@v1 + - uses: actions/cache@v2 + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + - name: install dependencies + run: yarn install --frozen-lockfile --non-interactive --production=false + - name: Lint commit message + uses: wagoid/commitlint-github-action@v2 + - name: lint Javascript + run: yarn lint + + test: + name: Test + runs-on: ubuntu-latest + needs: [lint] + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/setup-node@v1 + - name: Cache node_modules + uses: actions/cache@v2 + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + - name: Login on dockerhub + run: echo ${{ secrets.$DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin + - name: Start docker container + run: docker-compose up -d + - name: Send coverage + uses: paambaati/codeclimate-action@v2.7.4 + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + with: + coverageCommand: yarn test:coverage + + deploy: + name: Release package + runs-on: ubuntu-latest + needs: [test] + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta') + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false # GITHUB_TOKEN must not be set for the semantic release + - uses: actions/setup-node@v1 + with: + node-version: 12.13.0 + - uses: actions/cache@v2 + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + - name: Build package + run: yarn build + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v2 + id: semantic + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }} + GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }} + GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }} + GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }} + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index da8dc9be..00000000 --- a/.travis.yml +++ /dev/null @@ -1,37 +0,0 @@ -language: node_js -node_js: lts/* - -services: - - docker - -stages: - - Lint & Tests - - Build & Publish - -jobs: - include: - - stage: Lint & Tests - name: Lint commit messages - script: commitlint-travis - - script: yarn lint - name: Lint JavaScript - - script: echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - name: Login on dockerhub - - script: yarn test:coverage - name: Tests - # NOTICE: Handles code coverage reporting to Code Climate - before_install: - - docker-compose up -d - - curl -L $CC_TEST_REPORTER_URL > ./cc-test-reporter - - chmod +x ./cc-test-reporter - after_script: - - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT - - stage: Build & Publish - if: branch IN ("master", "beta") AND type != pull_request - script: skip - deploy: - provider: script - skip_cleanup: true - on: - all_branches: true - script: yarn && yarn build && npx semantic-release diff --git a/README.md b/README.md index 7187be72..105c6a5d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Forest Admin in Nodejs (Express.js & Mongoose) [![npm package](https://badge.fury.io/js/forest-express-mongoose.svg)](https://badge.fury.io/js/forest-express-mongoose) -[![CI status](https://travis-ci.org/ForestAdmin/forest-express-mongoose.svg?branch=devel)](https://travis-ci.org/ForestAdmin/forest-express-mongoose) +[![CI status](https://github.com/ForestAdmin/forest-express-mongoose/workflows/.github/workflows/build.yml/badge.svg)](https://github.com/ForestAdmin/forest-express-mongoose/actions) [![Test Coverage](https://api.codeclimate.com/v1/badges/4881f8b0b3cb806cd472/test_coverage)](https://codeclimate.com/github/ForestAdmin/forest-express-mongoose/test_coverage) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) diff --git a/commitlint.config.js b/commitlint.config.js index defabc03..3111ea8d 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,5 +1,5 @@ // NOTICE: When a github "squash and merge" is performed, github add the PR link in the commit -// message using the format ` (#)`. Travis provide the target branch of the build, +// message using the format ` (#)`. Github provide the target branch of the build, // so authorizing 4+5 = 9 characters more on master for the max header length should work // until we reach PR #99999. @@ -7,9 +7,9 @@ let maxHeaderLength = 100; const prExtrasChars = 9; -const isCommitOnMaster = process.env.TRAVIS_BRANCH && process.env.TRAVIS_BRANCH === 'master'; +const isPushEvent = process.env.GITHUB_EVENT_NAME === 'push'; -if (isCommitOnMaster) { +if (isPushEvent) { maxHeaderLength += prExtrasChars; } diff --git a/package.json b/package.json index 90821b95..ca102ba7 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "@babel/register": "7.10.1", "@commitlint/cli": "11.0.0", "@commitlint/config-conventional": "11.0.0", - "@commitlint/travis-cli": "11.0.0", "@semantic-release/changelog": "5.0.1", "@semantic-release/git": "9.0.0", "@types/jest": "26.0.13", diff --git a/yarn.lock b/yarn.lock index d201c75f..1e5f28cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1168,7 +1168,7 @@ exec-sh "^0.3.2" minimist "^1.2.0" -"@commitlint/cli@11.0.0", "@commitlint/cli@^11.0.0": +"@commitlint/cli@11.0.0": version "11.0.0" resolved "https://registry.yarnpkg.com/@commitlint/cli/-/cli-11.0.0.tgz#698199bc52afed50aa28169237758fa14a67b5d3" integrity sha512-YWZWg1DuqqO5Zjh7vUOeSX76vm0FFyz4y0cpGMFhrhvUi5unc4IVfCXZ6337R9zxuBtmveiRuuhQqnRRer+13g== @@ -1299,15 +1299,6 @@ dependencies: find-up "^5.0.0" -"@commitlint/travis-cli@11.0.0": - version "11.0.0" - resolved "https://registry.yarnpkg.com/@commitlint/travis-cli/-/travis-cli-11.0.0.tgz#cd0f25274e98daaf68732e53991b74347cde91b4" - integrity sha512-ZohGBnXeXv8hcba13fNz0HaCGy3CA4bz1A0PbyqwAzJA6Q85lBvLf1Wa78+Yxwo+PCZx85Vt8tpSrooHaHf2SA== - dependencies: - "@babel/runtime" "^7.11.2" - "@commitlint/cli" "^11.0.0" - execa "^4.0.0" - "@commitlint/types@^11.0.0": version "11.0.0" resolved "https://registry.yarnpkg.com/@commitlint/types/-/types-11.0.0.tgz#719cf05fcc1abb6533610a2e0f5dd1e61eac14fe" From 034b788a7858af60eeee7b5b4dd329ca07ab8a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Molini=C3=A9?= Date: Mon, 18 Jan 2021 09:14:55 +0100 Subject: [PATCH 2/5] ci: add missing NPM_TOKEN --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6b81fd09..e8826aa9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -86,4 +86,6 @@ jobs: GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }} GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }} GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }} + GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} From 2328f6aeb6e8dc926027ae2c3bb4af7120402fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Molini=C3=A9?= Date: Mon, 18 Jan 2021 09:35:58 +0100 Subject: [PATCH 3/5] chore: remove duplicated environment variable --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e8826aa9..ad45179a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -86,6 +86,5 @@ jobs: GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }} GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }} GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }} - GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} From 451ccc5011825a31a0f374db9298ef6ccb1f0d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Molini=C3=A9?= Date: Mon, 25 Jan 2021 17:54:54 +0100 Subject: [PATCH 4/5] chore: remove duplicate if --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ad45179a..a02e70da 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,7 +37,6 @@ jobs: name: Test runs-on: ubuntu-latest needs: [lint] - if: "!contains(github.event.head_commit.message, '[skip ci]')" steps: - uses: actions/checkout@v2 with: From 1bf60501c6bd741c3d5597a06a2b44d6c59c1d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Molini=C3=A9?= Date: Tue, 26 Jan 2021 16:42:28 +0100 Subject: [PATCH 5/5] ci: fix build syntax error --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a02e70da..1c3503b2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,7 +48,7 @@ jobs: path: '**/node_modules' key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} - name: Login on dockerhub - run: echo ${{ secrets.$DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin + run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin - name: Start docker container run: docker-compose up -d - name: Send coverage