From 4a0e65cd99c08162ea12041c2c029042d3c2bf43 Mon Sep 17 00:00:00 2001 From: H01001000 Date: Sun, 4 Dec 2022 17:31:04 +0800 Subject: [PATCH] ci: add release to gh per commit --- .github/workflows/release.yml | 51 +++++++++++++++++++++++ .npmignore | 9 ++++ package.json | 3 +- packages/bot/package.json | 6 ++- packages/client/package.json | 6 ++- packages/discordeno/package.json | 6 ++- packages/embeds/package.json | 6 ++- packages/gateway/package.json | 6 ++- packages/logger/package.json | 6 ++- packages/plugins/cache/package.json | 6 ++- packages/plugins/fileloader/package.json | 4 ++ packages/plugins/permissions/package.json | 4 ++ packages/plugins/utils/package.json | 6 ++- packages/plugins/validations/package.json | 4 ++ packages/rest/package.json | 8 +++- packages/types/package.json | 6 ++- packages/utils/package.json | 8 +++- scripts/bumpVersionByCommit.js | 28 +++++++++++++ 18 files changed, 159 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .npmignore create mode 100644 scripts/bumpVersionByCommit.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..30f7dfe3e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,51 @@ +name: Release + +on: + push: + branches: + - main + - node-migration + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + matrix: + package: ["bot", "gateway", "rest", "types", "utils"] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + registry-url: "https://npm.pkg.github.com" + scope: '@discordeno' + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn config get cacheFolder)" + - uses: actions/cache@v3 + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - run: yarn install --immutable + - name: Turbo Cache + id: turbo-cache + uses: actions/cache@v3 + with: + path: .turbo + key: ${{ runner.os }}-turbo-release-build-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-turbo-release-build- + - name: build Package + run: yarn release-build --cache-dir=".turbo" + - name: Bump Package Version + run: node /scripts/bumpVersionByCommit.js ${{ matrix.package }} + - run: npm publish + working-directory: packages/${{ matrix.package }} + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.npmignore b/.npmignore new file mode 100644 index 000000000..54f77c75c --- /dev/null +++ b/.npmignore @@ -0,0 +1,9 @@ +# ignore everything +* + +# except package.json and build +!package.json +!dist + +# but not tsc cache +dist/tsconfig.tsbuildinfo \ No newline at end of file diff --git a/package.json b/package.json index fff60b9a3..577191b18 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "discordeno-monorepo", "version": "18.0.0-alpha.1", "private": true, + "type": "module", "workspaces": [ "packages/*", "packages/plugins/cache", @@ -42,4 +43,4 @@ ] }, "packageManager": "yarn@3.3.0" -} +} \ No newline at end of file diff --git a/packages/bot/package.json b/packages/bot/package.json index 528f2d1c5..5717d3198 100644 --- a/packages/bot/package.json +++ b/packages/bot/package.json @@ -5,6 +5,10 @@ "types": "./dist/index.d.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", @@ -36,4 +40,4 @@ "tsconfig": "*", "typescript": "^4.9.3" } -} +} \ No newline at end of file diff --git a/packages/client/package.json b/packages/client/package.json index dfa4d0d21..de0fb11f9 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -5,6 +5,10 @@ "types": "./dist/index.d.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", @@ -36,4 +40,4 @@ "tsconfig": "*", "typescript": "^4.9.3" } -} +} \ No newline at end of file diff --git a/packages/discordeno/package.json b/packages/discordeno/package.json index 54468cf32..4ae4edf29 100644 --- a/packages/discordeno/package.json +++ b/packages/discordeno/package.json @@ -5,6 +5,10 @@ "types": "./dist/index.d.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", @@ -36,4 +40,4 @@ "tsconfig": "*", "typescript": "^4.9.3" } -} +} \ No newline at end of file diff --git a/packages/embeds/package.json b/packages/embeds/package.json index a6fe3838d..69bdfdbe0 100644 --- a/packages/embeds/package.json +++ b/packages/embeds/package.json @@ -5,6 +5,10 @@ "types": "./src/index.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "lint": "eslint \"**/*.ts*\"" }, @@ -21,4 +25,4 @@ "tsconfig": "*", "typescript": "^4.9.3" } -} +} \ No newline at end of file diff --git a/packages/gateway/package.json b/packages/gateway/package.json index f4bca22c2..c37d40275 100644 --- a/packages/gateway/package.json +++ b/packages/gateway/package.json @@ -6,6 +6,10 @@ "type": "module", "private": true, "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", @@ -39,4 +43,4 @@ "dependencies": { "ws": "^8.11.0" } -} +} \ No newline at end of file diff --git a/packages/logger/package.json b/packages/logger/package.json index fc0db8f4b..b629d4bae 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -5,6 +5,10 @@ "types": "./src/index.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "lint": "eslint \"**/*.ts*\"" }, @@ -24,4 +28,4 @@ "dependencies": { "chalk": "^5.1.2" } -} +} \ No newline at end of file diff --git a/packages/plugins/cache/package.json b/packages/plugins/cache/package.json index fa2a99dd6..ab2ac1ae6 100644 --- a/packages/plugins/cache/package.json +++ b/packages/plugins/cache/package.json @@ -5,6 +5,10 @@ "types": "./dist/index.d.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", @@ -34,4 +38,4 @@ "tsconfig": "*", "typescript": "^4.9.3" } -} +} \ No newline at end of file diff --git a/packages/plugins/fileloader/package.json b/packages/plugins/fileloader/package.json index 685b0a8f1..13e380c55 100644 --- a/packages/plugins/fileloader/package.json +++ b/packages/plugins/fileloader/package.json @@ -5,6 +5,10 @@ "types": "./dist/index.d.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", diff --git a/packages/plugins/permissions/package.json b/packages/plugins/permissions/package.json index 00d3dd196..23a811793 100644 --- a/packages/plugins/permissions/package.json +++ b/packages/plugins/permissions/package.json @@ -5,6 +5,10 @@ "types": "./dist/index.d.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", diff --git a/packages/plugins/utils/package.json b/packages/plugins/utils/package.json index 07546e171..a2f8a79fb 100644 --- a/packages/plugins/utils/package.json +++ b/packages/plugins/utils/package.json @@ -5,6 +5,10 @@ "types": "./dist/index.d.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", @@ -33,4 +37,4 @@ "tsconfig": "*", "typescript": "^4.9.3" } -} +} \ No newline at end of file diff --git a/packages/plugins/validations/package.json b/packages/plugins/validations/package.json index 1b652d692..5e2589b89 100644 --- a/packages/plugins/validations/package.json +++ b/packages/plugins/validations/package.json @@ -5,6 +5,10 @@ "types": "./dist/index.d.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", diff --git a/packages/rest/package.json b/packages/rest/package.json index a26255bf5..2e2047245 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -1,10 +1,14 @@ { "name": "@discordeno/rest", - "version": "18.0.0-alpha.1", + "version": "18.0.0-next.a88e1e7", "main": "./dist/index.js", "types": "./dist/index.d.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", @@ -34,4 +38,4 @@ "tsconfig": "*", "typescript": "^4.9.3" } -} +} \ No newline at end of file diff --git a/packages/types/package.json b/packages/types/package.json index 54a33c79f..bb815da5c 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -5,6 +5,10 @@ "types": "./dist/index.d.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", @@ -24,4 +28,4 @@ "dependencies": { "@types/node": "^18.11.9" } -} +} \ No newline at end of file diff --git a/packages/utils/package.json b/packages/utils/package.json index 02bc60799..2148c767b 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,10 +1,14 @@ { "name": "@discordeno/utils", - "version": "18.0.0-alpha.1", + "version": "18.0.0-next.a88e1e7", "main": "./dist/index.js", "types": "./dist/index.d.ts", "type": "module", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/discordeno/discordeno.git" + }, "scripts": { "build": "swc src --out-dir dist", "build:type": "tsc --skipDefaultLibCheck --declaration --emitDeclarationOnly --declarationDir dist", @@ -34,4 +38,4 @@ "tsconfig": "*", "typescript": "^4.9.3" } -} +} \ No newline at end of file diff --git a/scripts/bumpVersionByCommit.js b/scripts/bumpVersionByCommit.js new file mode 100644 index 000000000..5c37a55b4 --- /dev/null +++ b/scripts/bumpVersionByCommit.js @@ -0,0 +1,28 @@ +import childProcess from 'node:child_process' +import fs from 'node:fs/promises' +import { argv } from 'node:process' + +const packageName = argv[2] + +if (!packageName) { + throw new Error('No package name specified') +} + +const commitHash = childProcess + .execSync('git rev-parse HEAD') + .toString() + .trim() + .slice(0, 7) + +const file = JSON.parse( + await fs.readFile(`packages/${packageName}/package.json`, 'utf-8') +) +file.version = `${file.version.split('-')[0]}-next.${commitHash}` +await fs.writeFile( + `packages/${packageName}/package.json`, + JSON.stringify(file, null, 2) +) + +console.log( + `Bumped ${packageName} to ${file.version.split('-')[0]}-next.${commitHash}` +)