From 8d4376f747016df7002a0bf1ebbc888fc9600dcd Mon Sep 17 00:00:00 2001 From: Jairo <68893868+jairo-bc@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:13:12 +0200 Subject: [PATCH] feat: STRF-10157 Introduce Semantic Release (#302) --- .github/workflows/build.yml | 10 +++++++--- .github/workflows/release.yml | 18 ++++++++++++++---- .husky/commit-msg | 4 ++++ .releaserc | 20 ++++++++++++++++++++ commitlint.config.js | 6 ++++++ package.json | 14 +++++++++++++- 6 files changed, 64 insertions(+), 8 deletions(-) create mode 100755 .husky/commit-msg create mode 100644 .releaserc create mode 100644 commitlint.config.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4338029..b399546 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,8 @@ -name: Build +name: Lint and Test PR on: pull_request: branches: [ master, main ] - push: - branches: [ master, main ] jobs: build: @@ -27,6 +25,12 @@ jobs: - name: Install Dependencies run: npm i + - name: Verify Github PR Title + run: echo "${{ github.event.pull_request.title }}" | npx commitlint + + - name: Verify Git Commit Name + run: git log -1 --pretty=format:"%s" | npx commitlint + - name: Lint the code run: npm run lint diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 286fd6f..1955839 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,10 @@ -name: Paper Library +name: Paper Library Semantic Release + on: - release: - types: [created] + push: + branches: [master, main] + + jobs: build: runs-on: ubuntu-latest @@ -11,6 +14,13 @@ jobs: with: node-version: '14.x' - run: npm i + - name: Check Git Commit name + run: git log -1 --pretty=format:"%s" | npx commitlint # Setup .npmrc file to publish to npm registry - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc - - run: npm publish + - name: Deploy to npm and git + run: npm config list && npm run release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GA_USERNAME: ${{ secrets.PAT_USERNAME }} + GA_TOKEN: ${{ secrets.PAT_TOKEN }} diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..4974c35 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npx commitlint --edit $1 diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..f0277aa --- /dev/null +++ b/.releaserc @@ -0,0 +1,20 @@ +{ + "branches": ["master"], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + "@semantic-release/changelog", + ["@semantic-release/github", { + "assets": [ + {"path": "dist/blackbird-handlebars.js", "label": "helpers.js"} + ] + }], + "@semantic-release/npm", + [ + "semantic-release-github-pullrequest", { + "assets": ["CHANGELOG.md", "package.json"], + "baseRef": "master" + } + ] + ] +} \ No newline at end of file diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..5bcb4bf --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,6 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'subject-case': [0, 'always', 'sentence-case'], + } +}; diff --git a/package.json b/package.json index 6028b09..5de76b5 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "lint": "eslint .", "lint-and-fix": "eslint . --fix", "test": "lab -v -t 95 --ignore i18n,WebAssembly,SharedArrayBuffer,Atomics,BigUint64Array,BigInt64Array,BigInt,URL,URLSearchParams,TextEncoder,TextDecoder,queueMicrotask,FinalizationRegistry,WeakRef,plural,en,number,select spec", - "coverage": "lab -c -r console -o stdout -r html -o coverage.html spec" + "coverage": "lab -c -r console -o stdout -r html -o coverage.html spec", + "release": "semantic-release" }, "repository": { "type": "git", @@ -29,9 +30,20 @@ "messageformat": "~0.2.2" }, "devDependencies": { + "@commitlint/cli": "^17.1.2", + "@commitlint/config-conventional": "^17.1.0", + "@semantic-release/changelog": "^6.0.1", + "@semantic-release/commit-analyzer": "^9.0.2", + "@semantic-release/git": "^10.0.1", + "@semantic-release/github": "^8.0.6", + "@semantic-release/npm": "^9.0.1", + "@semantic-release/release-notes-generator": "^10.0.3", "code": "~4.0.0", "eslint": "^7.8.1", + "husky": "^8.0.1", "lab": "~13.0.1", + "semantic-release": "^19.0.5", + "semantic-release-github-pullrequest": "^1.3.0", "sinon": "~7.5.0" } }