From 3ec73b96de0857543ee87344ed3d741a04cfdcdb Mon Sep 17 00:00:00 2001 From: Mircea Nistor Date: Thu, 17 Dec 2020 17:54:53 +0100 Subject: [PATCH] chore(ci): refactor automatic release using GH actions (#283) --- .circleci/config.yml | 152 -------------------- .github/workflows/run-tests.yml | 57 ++++++++ .github/workflows/sync-next-with-latest.yml | 17 +++ commitlint.config.js | 2 +- lerna.json | 14 +- package.json | 5 +- 6 files changed, 81 insertions(+), 166 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/run-tests.yml create mode 100644 .github/workflows/sync-next-with-latest.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 912eb077f..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,152 +0,0 @@ -version: 2 -aliases: - - &check-code-format - name: Check code formatting - command: yarn prettier --check - - - &restore-cache - keys: - - v2-dependencies-{{ .Branch }}-{{ checksum "package.json" }} - - v2-dependencies-{{ .Branch }} - - - &save-node-cache - key: v2-dependencies-{{ .Branch }}-{{ checksum "package.json" }} - paths: - - node_modules - - - &install-node-dependencies - name: Install node dependencies - command: yarn install --frozen-lockfile - - - &bootstrap-packages - name: Bootstrap packages - command: yarn bootstrap - - - &build-packages - name: Build packages - command: yarn build - -defaults: &defaults - working_directory: ~/daf - -jobs: - test-packages: - <<: *defaults - docker: - - image: node:10 - resource_class: large - steps: - - checkout - - restore_cache: *restore-cache - - run: *install-node-dependencies - - run: *check-code-format - - run: *bootstrap-packages - - run: *build-packages - - save_cache: *save-node-cache - - run: yarn test:integration - - run: - name: Upload coverage report - command: npx codecov - - publish-packages-npm: - <<: *defaults - docker: - - image: node:10 - resource_class: large - steps: - - checkout - - restore_cache: *restore-cache - - run: *install-node-dependencies - - run: *bootstrap-packages - - run: *build-packages - - run: - name: Authenticate Github - command: | - git remote set-url origin https://uport-project:$GITHUB_TOKEN@github.com/uport-project/daf.git - git config --global user.email $GITHUB_EMAIL - git config --global user.name $GITHUB_USER - - run: - name: Authenticate with NPM - command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/daf/.npmrc - - run: - name: Validate npm authentication - command: npm whoami - - run: - name: Release packages to npm - command: npx lerna publish --yes - - publish-beta-packages-npm: - <<: *defaults - docker: - - image: node:10 - resource_class: large - steps: - - checkout - - restore_cache: *restore-cache - - run: *install-node-dependencies - - run: *bootstrap-packages - - run: *build-packages - - run: - name: Authenticate Github - command: | - git remote set-url origin https://uport-project:$GITHUB_TOKEN@github.com/uport-project/daf.git - git config --global user.email $GITHUB_EMAIL - git config --global user.name $GITHUB_USER - - run: - name: Authenticate with NPM - command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/daf/.npmrc - - run: - name: Validate npm authentication - command: npm whoami - - run: - name: Release packages to npm - command: npx lerna publish --canary premajor --preid beta --pre-dist-tag beta --no-git-reset --yes - - docker: - working_directory: ~/repo - docker: - - image: circleci/node:8.10 - steps: - - checkout - - setup_remote_docker - - run: - name: docker-login - command: echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin - - run: - name: Build docker image - command: | - if [ "${CIRCLE_BRANCH}" == "master" ]; then - docker build -t uport/daf:master . - docker tag uport/daf:master uport/daf:latest - else - docker build -t uport/daf:`echo ${CIRCLE_BRANCH} | sed 's/\//-/g'` . - fi - - run: - name: Push to dockerhub - command: | - if [ "${CIRCLE_BRANCH}" == "master" ]; then - docker push uport/daf:latest - else - docker push uport/daf:`echo ${CIRCLE_BRANCH} | sed 's/\//-/g'` - fi - -workflows: - version: 2 - - verify-test-build: - jobs: - - test-packages - - publish-packages-npm: - filters: - branches: - only: - - master - requires: - - test-packages - - docker: - filters: - branches: - only: - - master - requires: - - publish-packages-npm diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 000000000..2449daf93 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,57 @@ +name: Build, Test and Publish +on: [push, workflow_dispatch] +jobs: + build-test-publish: + env: + NPM_TOKEN: ${{secrets.NPM_TOKEN}} + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + GH_TOKEN: ${{secrets.GH_TOKEN}} + GH_USER: ${{secrets.GH_USER}} + GH_EMAIL: ${{secrets.GH_EMAIL}} + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '12.x' + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + - uses: actions/cache@v2 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - run: yarn install --frozen-lockfile + - run: yarn bootstrap + - run: yarn build + - run: yarn test:integration + - run: yarn lint + - run: npx codecov + + - name: setup git coordinates + run: | + git remote set-url origin https://uport-project:$GH_TOKEN@github.com/uport-project/daf.git + git config user.name $GH_USER + git config user.email $GH_EMAIL + + - name: setup npm registry + run: | + echo "registry=https://registry.npmjs.org/" > .npmrc + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc + npm whoami + + - name: publish @latest when on main + if: github.ref == 'refs/heads/main' + run: yarn publish:latest + + - name: publish @next when on next + if: github.ref == 'refs/heads/next' + run: yarn publish:next diff --git a/.github/workflows/sync-next-with-latest.yml b/.github/workflows/sync-next-with-latest.yml new file mode 100644 index 000000000..cddbfd7d0 --- /dev/null +++ b/.github/workflows/sync-next-with-latest.yml @@ -0,0 +1,17 @@ +name: Sync @next with @latest +on: + workflow_dispatch: + push: + branches: + - 'main' +jobs: + merge-branch: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - uses: everlytic/branch-merge@1.1.0 + with: + github_token: ${{ secrets.GH_TOKEN }} + source_ref: ${{ github.ref }} + target_branch: 'next' + commit_message_template: 'chore(ci): merge main into next' diff --git a/commitlint.config.js b/commitlint.config.js index ad0b9cdd6..481d1e05f 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,6 +1,6 @@ module.exports = { extends: ['@commitlint/config-conventional'], rules: { - 'subject-case': [2, 'always', ['sentence-case']], + // 'subject-case': [2, 'always', ['sentence-case']], }, } diff --git a/lerna.json b/lerna.json index fef28498d..ef39b5baf 100644 --- a/lerna.json +++ b/lerna.json @@ -11,20 +11,12 @@ "command": { "publish": { "allowBranch": [ - "master", - "beta" + "main", + "next" ], "conventionalCommits": true, "gitRemote": "origin", - "message": "chore(release): %s" - }, - "version": { - "allowBranch": [ - "beta" - ], - "conventionalCommits": true, - "gitRemote": "origin", - "message": "chore(beta-release): %s" + "message": "chore(release): %s [skip ci]" } }, "useWorkspaces": true diff --git a/package.json b/package.json index a7957256e..b944e38e8 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "build": "lerna run build && yarn build:schema-api", "bootstrap": "lerna bootstrap", "build:schema-api":"lerna run extract-api && lerna run generate-plugin-schema", + "lint": "echo \"linting not yet enabled\"", "test:integration-build": "yarn test:integration-prepare && yarn test:integration-pretty", "test:integration-prepare": "ts-node --project packages/tsconfig.settings.json ./scripts/prepare-integration-tests.ts", "test:integration-pretty":"prettier --write __tests__/shared/documentationExamples.ts", @@ -15,8 +16,8 @@ "daf": "./packages/daf-cli/bin/daf.js", "prettier": "prettier --write '{packages,__tests__, !build}/**/*.{ts,js,json,md,yml}'", "build-clean": "rimraf ./packages/*/build ./packages/*/node_modules ./packages/*/tsconfig.tsbuildinfo && jest --clearCache", - "publish": "lerna publish", - "publish-beta": "yarn build && npx lerna publish --canary premajor --preid beta --pre-dist-tag beta" + "publish:latest": "lerna publish --conventional-commits --include-merged-tags --create-release github --yes --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}", + "publish:next": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid next --pre-dist-tag next --yes --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}" }, "workspaces": [ "packages/*"