From 402446852bd65a7d2ba46973381fc8574f7165d1 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Mon, 2 Oct 2023 08:37:59 -0600 Subject: [PATCH] Further automate publishing of undici-types using GitHub Actions workflow (#2290) * add workflow * improve automation * linting --- .github/workflows/publish-undici-types.yml | 21 +++++++ package.json | 1 - scripts/generate-undici-types-package-json.js | 23 ++++++++ scripts/update-undici-types-version.js | 18 ------ types/package.json | 55 ------------------- 5 files changed, 44 insertions(+), 74 deletions(-) create mode 100644 .github/workflows/publish-undici-types.yml create mode 100644 scripts/generate-undici-types-package-json.js delete mode 100644 scripts/update-undici-types-version.js delete mode 100644 types/package.json diff --git a/.github/workflows/publish-undici-types.yml b/.github/workflows/publish-undici-types.yml new file mode 100644 index 00000000000..b0afae73eb1 --- /dev/null +++ b/.github/workflows/publish-undici-types.yml @@ -0,0 +1,21 @@ +on: + push: + tags: + - 'v*' + workflow_dispatch: + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: '16.x' + registry-url: 'https://registry.npmjs.org' + - run: npm ci + - run: node scripts/generate-undici-types-package-json.js + - run: cd types + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index dc3374a5958..b67d3ba0f9d 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,6 @@ "bench:run": "CONNECTIONS=1 node benchmarks/benchmark.js; CONNECTIONS=50 node benchmarks/benchmark.js", "serve:website": "docsify serve .", "prepare": "husky install", - "postpublish": "node scripts/update-undici-types-version.js && cd types && npm publish", "fuzz": "jsfuzz test/fuzzing/fuzz.js corpus" }, "devDependencies": { diff --git a/scripts/generate-undici-types-package-json.js b/scripts/generate-undici-types-package-json.js new file mode 100644 index 00000000000..250cfc08aa2 --- /dev/null +++ b/scripts/generate-undici-types-package-json.js @@ -0,0 +1,23 @@ +const fs = require('node:fs') +const path = require('node:path') + +const packageJSONPath = path.join(__dirname, '..', 'package.json') +const packageJSONRaw = fs.readFileSync(packageJSONPath, 'utf-8') +const packageJSON = JSON.parse(packageJSONRaw) + +const packageTypesJSON = { + name: 'undici-types', + version: packageJSON.version, + description: 'A stand-alone types package for Undici', + homepage: packageJSON.homepage, + bugs: packageJSON.bugs, + repository: packageJSON.repository, + license: packageJSON.license, + types: 'index.d.ts', + files: ['*.d.ts'], + contributors: packageJSON.contributors +} + +const packageTypesPath = path.join(__dirname, '..', 'types', 'package.json') + +fs.writeFileSync(packageTypesPath, JSON.stringify(packageTypesJSON, null, 2)) diff --git a/scripts/update-undici-types-version.js b/scripts/update-undici-types-version.js deleted file mode 100644 index 2308e97905a..00000000000 --- a/scripts/update-undici-types-version.js +++ /dev/null @@ -1,18 +0,0 @@ -const fs = require('node:fs') -const path = require('node:path') -const childProcess = require('node:child_process') - -const packageJSONPath = path.join(__dirname, '..', 'package.json') -const packageJSONRaw = fs.readFileSync(packageJSONPath, 'utf-8') -const packageJSON = JSON.parse(packageJSONRaw) -const version = packageJSON.version - -const packageTypesJSONPath = path.join(__dirname, '..', 'types', 'package.json') -const packageTypesJSONRaw = fs.readFileSync(packageTypesJSONPath, 'utf-8') -const packageTypesJSON = JSON.parse(packageTypesJSONRaw) -packageTypesJSON.version = version - -fs.writeFileSync(packageTypesJSONPath, JSON.stringify(packageTypesJSON, null, 2)) - -childProcess.execSync('git add types/package.json', { cwd: path.join(__dirname, '..') }) -childProcess.execSync(`git commit -n -m 'undici-types@${version}'`, { cwd: path.join(__dirname, '..') }) diff --git a/types/package.json b/types/package.json deleted file mode 100644 index 6fcb70aa6bd..00000000000 --- a/types/package.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "name": "undici-types", - "version": "5.25.3", - "description": "A stand-alone types package for Undici", - "homepage": "https://undici.nodejs.org", - "bugs": { - "url": "https://github.com/nodejs/undici/issues" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/nodejs/undici.git" - }, - "license": "MIT", - "types": "index.d.ts", - "files": [ - "*.d.ts" - ], - "contributors": [ - { - "name": "Daniele Belardi", - "url": "https://github.com/dnlup", - "author": true - }, - { - "name": "Ethan Arrowood", - "url": "https://github.com/ethan-arrowood", - "author": true - }, - { - "name": "Matteo Collina", - "url": "https://github.com/mcollina", - "author": true - }, - { - "name": "Matthew Aitken", - "url": "https://github.com/KhafraDev", - "author": true - }, - { - "name": "Robert Nagy", - "url": "https://github.com/ronag", - "author": true - }, - { - "name": "Szymon Marczak", - "url": "https://github.com/szmarczak", - "author": true - }, - { - "name": "Tomas Della Vedova", - "url": "https://github.com/delvedor", - "author": true - } - ] -} \ No newline at end of file