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..0aca413 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +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 + 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: [20.x] + steps: + - name: Cache node modules + id: cache-npm + uses: actions/cache@v4 + env: + cache-name: cache-node-modules + with: + 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: ${{ 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 + 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..04d08aa --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,19 @@ +{ + "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/npm", + "@semantic-release/git", + "@semantic-release/github" + ] +} 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..9a03658 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,34 @@ "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", + "@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", + "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" + } } }