From 073fcb452454aedcdd38a8f962a268840efcd5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 10 Oct 2024 14:24:41 +0000 Subject: [PATCH 1/3] feat: :construction_worker: Add Conventions Verification Tools and Automation --- .eslintrc.js | 24 ++++++++++++++++++++ .github/workflows/release.yml | 41 ++++++++++++++++++++++++++++++++++ .hooks/commit-msg | 2 ++ .hooks/post-checkout | 18 +++++++++++++++ .hooks/pre-commit | 10 +++++++++ .releaserc.json | 40 +++++++++++++++++++++++++++++++++ .validate-branch-namerc.js | 4 ++++ Makefile | 7 +++++- commitlint.config.js | 12 ++++++++++ git-precommit-checks.config.js | 31 +++++++++++++++++++++++++ package.json | 29 +++++++++++++++++++++--- 11 files changed, 214 insertions(+), 4 deletions(-) create mode 100644 .eslintrc.js create mode 100644 .github/workflows/release.yml create mode 100755 .hooks/commit-msg create mode 100755 .hooks/post-checkout create mode 100755 .hooks/pre-commit create mode 100644 .releaserc.json create mode 100644 .validate-branch-namerc.js create mode 100644 commitlint.config.js create mode 100644 git-precommit-checks.config.js diff --git a/ .eslintrc.js b/ .eslintrc.js new file mode 100644 index 0000000..1063a5a --- /dev/null +++ b/ .eslintrc.js @@ -0,0 +1,24 @@ +module.exports = { + parser: '@typescript-eslint/parser', + parserOptions: { + project: 'tsconfig.json', + tsconfigRootDir: __dirname, + sourceType: 'module', + }, + plugins: ['@typescript-eslint/eslint-plugin'], + extends: [ + 'plugin:@typescript-eslint/recommended', + 'plugin:prettier/recommended', + ], + root: true, + env: { + node: true, + }, + ignorePatterns: ['.eslintrc.js', 'commitlint.config.js'], + rules: { + '@typescript-eslint/interface-name-prefix': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-explicit-any': 'off', + }, +}; \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..30c7b4a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +name: Release +on: + push: + branches: + - main + - staging + - production + + pull_request: + branches: + - main + +permissions: + contents: read # for checkout + +jobs: + release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write # to be able to publish a GitHub release + issues: write # to be able to comment on released issues + pull-requests: write # to be able to comment on released pull requests + id-token: write # to enable use of OIDC for npm provenance + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 'lts/*' + - name: Install dependencies + run: npm clean-install + - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies + run: npm audit signatures + - name: Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: npx semantic-release diff --git a/.hooks/commit-msg b/.hooks/commit-msg new file mode 100755 index 0000000..6356763 --- /dev/null +++ b/.hooks/commit-msg @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +npx --no -- commitlint --edit $1 diff --git a/.hooks/post-checkout b/.hooks/post-checkout new file mode 100755 index 0000000..8b389e4 --- /dev/null +++ b/.hooks/post-checkout @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +printf '\npost-checkout hook\n\n' + +prevHEAD=$1 +newHEAD=$2 +checkoutType=$3 + +[[ $checkoutType == 1 ]] && checkoutType='branch' || + checkoutType='file' ; + +echo 'Checkout type: '$checkoutType +echo ' prev HEAD: '`git name-rev --name-only $prevHEAD` +echo ' new HEAD: '`git name-rev --name-only $newHEAD` + +make clean \ No newline at end of file diff --git a/.hooks/pre-commit b/.hooks/pre-commit new file mode 100755 index 0000000..f9dfcec --- /dev/null +++ b/.hooks/pre-commit @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +if [ -z "${CHECKS_RUN}" ]; then + echo "Pre-commit checks will start as it is a manual commit" + npx --no-install git-precommit-checks + npx lint-staged --concurrent=false + npx validate-branch-name +else + echo "Skipping Pre-commit checks as they already executed" +fi \ No newline at end of file diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..48729f6 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,40 @@ +{ + "branches": [ + "main", + { + "name": "staging", + "prerelease": true + }, + "production" + ], + "repositoryUrl": "https://github.com/steamicc/makecode-steami.git", + "debug": "false", + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@semantic-release/changelog", + { + "changelogFile": "CHANGELOG.md", + "changelogTitle": "# Semantic Versioning Changelog" + } + ], + [ + "@semantic-release/git", + { + "assets": ["package.json", "CHANGELOG.md"], + "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + } + ], + [ + "@semantic-release/github", + { + "assets": [ + { + "path": "release/**" + } + ] + } + ] + ] +} diff --git a/.validate-branch-namerc.js b/.validate-branch-namerc.js new file mode 100644 index 0000000..11a5c0c --- /dev/null +++ b/.validate-branch-namerc.js @@ -0,0 +1,4 @@ +module.exports = { + pattern: "^(main|staging|production)$|^(chores|feature|fix|docs)\/([0-9]){0,3}-([a-z0-9]+-)*[a-z0-9]+$|^release\/v([0-9]+)\.([0-9]+)\.([0-9]+)([a-z0-9-]*)$", + errorMsg: "🤨 La branche que tu essaies de pusher ne respecte pas nos conventions, tu peux la renommer avec `git branch -m `", +} diff --git a/Makefile b/Makefile index 2e9230e..0b64e5c 100644 --- a/Makefile +++ b/Makefile @@ -121,7 +121,12 @@ endef all : setup .PHONY : setup -setup : | _deepclean install-makecode-steami install-pxt install-pxt-common-packages install-pxt-steami install-pxt-steami-backend +setup : | prepare _deepclean install-makecode-steami install-pxt install-pxt-common-packages install-pxt-steami install-pxt-steami-backend + +.PHONY : prepare +prepare : + @echo "Install Git hooks" + git config core.hooksPath .hooks .PHONY : install-makecode-steami install-makecode-steami : node_modules/.package-lock.json package-lock.json diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..ac66bac --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,12 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + parserPreset: { + parserOpts: { + issuePrefixes: ['#'], + }, + }, + rules: { + 'subject-case': [2, 'always', ['lower-case']], + 'scope-enum': [1, 'always', ['wip', 'configs', 'formatting', 'code', 'deployment', 'tests']], + }, +}; \ No newline at end of file diff --git a/git-precommit-checks.config.js b/git-precommit-checks.config.js new file mode 100644 index 0000000..6e24bd1 --- /dev/null +++ b/git-precommit-checks.config.js @@ -0,0 +1,31 @@ +module.exports = { + display: { + notifications: true, + offendingContent: true, + rulesSummary: false, + shortStats: true, + verbose: false, + }, + rules: [ + { + message: 'Aurais-tu oublié de terminer certaines tâches ? Aurais-tu une issue à ouvrir pour traiter cette tache plus tard ?', + nonBlocking: true, + regex: /(?:FIXME|TODO)/, + }, + { + message: 'Tu as des marqueurs de conflits qui traînent dans ton code', + regex: /^[<>|=]{4,}/m, + }, + { + message: + 'Arrêt du commit : tu as renseigné des choses qui ne doivent pas être commitées !', + regex: /do not commit/i, + }, + { + filter: /\.js$/, + message: '🤔 Hum ! N’as-tu pas oublié de retirer du "console.log(…)" ?', + nonBlocking: true, + regex: /^\s*console\.log/, + }, + ], +} \ No newline at end of file diff --git a/package.json b/package.json index 568afc1..4363b8d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,10 @@ "setup": "make setup", "ci": "make ci", "package": "make package", - "staticserve": "make staticserve" + "staticserve": "make staticserve", + "prepare": "make prepare", + "commit:checks": "npx --no-install git-precommit-checks && npx lint-staged && npx validate-branch-name && git-cz", + "prepare-commit": "cross-env CHECKS_RUN=1 npm run commit:checks" }, "repository": { "type": "git", @@ -21,10 +24,30 @@ "url": "https://github.com/steamicc/makecode-steami/issues" }, "dependencies": { - "eslint": "^9.7.0", "pxt": "^0.5.1" }, "devDependencies": { - "nodemon": "^3.1.4" + "@commitlint/cli": "^19.5.0", + "@commitlint/config-conventional": "^19.5.0", + "@commitlint/cz-commitlint": "^19.5.0", + "commitizen": "^4.3.1", + "cross-env": "^7.0.3", + "eslint": "^9.12.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1", + "git-precommit-checks": "^3.1.0", + "nodemon": "^3.1.4", + "prettier": "^3.3.3", + "semantic-release": "^24.1.2", + "validate-branch-name": "^1.3.1" + }, + "lint-staged": { + "*.js, *.json, *.css": "prettier", + "*.ts": "eslint" + }, + "config": { + "commitizen": { + "path": "@commitlint/cz-commitlint" + } } } From 558294829c7ad46e69349be749adbef7164d2e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 10 Oct 2024 14:34:36 +0000 Subject: [PATCH 2/3] fix: :green_heart: call npm setup before install --- .github/workflows/release.yml | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 30c7b4a..fd2a0da 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,22 +17,37 @@ jobs: release: name: Release runs-on: ubuntu-latest + container: + image: letssteam/makecode-toolchain:latest + options: --user 1001 --security-opt no-new-privileges permissions: contents: write # to be able to publish a GitHub release issues: write # to be able to comment on released issues pull-requests: write # to be able to comment on released pull requests id-token: write # to enable use of OIDC for npm provenance + strategy: + matrix: + node-version: [16.x, 18.x, 20.x] steps: - - name: Checkout - uses: actions/checkout@v3 + - name: Cache node modules + id: cache-npm + uses: actions/cache@v4 + env: + cache-name: cache-node-modules with: - fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3 + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 with: - node-version: 'lts/*' - - name: Install dependencies - run: npm clean-install + node-version: ${{ matrix.node-version }} + - uses: actions/checkout@v4 + - run: npm run setup + - run: npm run ci - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies run: npm audit signatures - name: Release From 269e632e601299c69b80d3084463b1cad8a5c28c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 10 Oct 2024 14:58:41 +0000 Subject: [PATCH 3/3] fix: :green_heart: Add missing dependencies for semantic-release --- .github/workflows/release.yml | 2 +- .releaserc.json | 27 +++------------------------ package.json | 4 ++++ 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fd2a0da..0aca413 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,7 +27,7 @@ jobs: id-token: write # to enable use of OIDC for npm provenance strategy: matrix: - node-version: [16.x, 18.x, 20.x] + node-version: [20.x] steps: - name: Cache node modules id: cache-npm diff --git a/.releaserc.json b/.releaserc.json index 48729f6..04d08aa 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -12,29 +12,8 @@ "plugins": [ "@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", - [ - "@semantic-release/changelog", - { - "changelogFile": "CHANGELOG.md", - "changelogTitle": "# Semantic Versioning Changelog" - } - ], - [ - "@semantic-release/git", - { - "assets": ["package.json", "CHANGELOG.md"], - "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" - } - ], - [ - "@semantic-release/github", - { - "assets": [ - { - "path": "release/**" - } - ] - } - ] + "@semantic-release/npm", + "@semantic-release/git", + "@semantic-release/github" ] } diff --git a/package.json b/package.json index 4363b8d..9a03658 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,10 @@ "@commitlint/cli": "^19.5.0", "@commitlint/config-conventional": "^19.5.0", "@commitlint/cz-commitlint": "^19.5.0", + "@semantic-release/changelog": "^6.0.3", + "@semantic-release/commit-analyzer": "^13.0.0", + "@semantic-release/git": "^10.0.1", + "@semantic-release/github": "^11.0.0", "commitizen": "^4.3.1", "cross-env": "^7.0.3", "eslint": "^9.12.0",