From 3cb5b422dbdfaa9d4a8b03ed11996f4c40e22741 Mon Sep 17 00:00:00 2001 From: Zhou xiao Date: Fri, 26 Jul 2024 06:36:13 +0800 Subject: [PATCH] workflow(cd): add release action (#10) * chore: add release script * chore: fix pkg version * workflow(cd): add release action --- .github/workflows/release.yml | 61 ++++++++++ package.json | 12 +- packages/midscene/package.json | 2 +- packages/web-integration/package.json | 2 +- pnpm-lock.yaml | 142 +++++++++++++++++++++-- scripts/release.js | 157 ++++++++++++++++++++++++++ 6 files changed, 364 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 scripts/release.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..df1d9104c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,61 @@ +name: Release +on: + workflow_dispatch: + inputs: + version: + description: 'Release Version(minor,patch,preminor,prepatch)' + required: true + default: 'patch' + branch: + description: 'Release Branch(confirm release branch)' + required: true + default: 'main' + +jobs: + release: + runs-on: ubuntu-20.04 + strategy: + matrix: + node-version: [16.14.0] + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.branch }} + - name: Pushing to the protected branch 'protected' + uses: CasperWA/push-protected@v2 + with: + token: ${{ secrets.PUSH_TO_PROTECTED_BRANCH }} + branch: ${{ github.event.inputs.branch }} + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - name: Cache .pnpm-store + uses: actions/cache@v2 + with: + path: ~/.pnpm-store + key: ${{ runner.os }}-node${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }} + + - name: Setup pnpm + uses: pnpm/action-setup@v2 + with: + version: 9.3.0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: release + run: node ./scripts/release.js --version=${{ github.event.inputs.version }} + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: changelog + run: npx conventional-github-releaser -p angular + env: + CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/package.json b/package.json index db50c76d8..94a74a72d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "infra", + "name": "midscene", "private": true, - "version": "1.0.0", + "version": "0.0.1", "description": "", "main": "index.js", "scripts": { @@ -31,7 +31,13 @@ "pretty-quick": "3.1.3", "@changesets/cli": "2.24.1", "commitizen": "4.2.5", - "nx": "19.5.2" + "nx": "19.5.2", + "semver": "7.3.7", + "dayjs": "1.11.2", + "minimist": "1.2.5", + "execa": "4.1.0", + "chalk": "4.1.2", + "@jsdevtools/version-bump-prompt": "6.1.0" }, "config": { "commitizen": { diff --git a/packages/midscene/package.json b/packages/midscene/package.json index fe231a5f7..f132e3440 100644 --- a/packages/midscene/package.json +++ b/packages/midscene/package.json @@ -1,7 +1,7 @@ { "name": "@midscene/core", "description": "Hello, It's MidScene", - "version": "0.1.1", + "version": "0.0.1", "jsnext:source": "./src/index.ts", "main": "./dist/lib/index.js", "module": "./dist/es/index.js", diff --git a/packages/web-integration/package.json b/packages/web-integration/package.json index 404a625b0..16ec6cfcb 100644 --- a/packages/web-integration/package.json +++ b/packages/web-integration/package.json @@ -1,7 +1,7 @@ { "name": "@midscene/web", "description": "Web integration for MidScene.js", - "version": "0.1.1", + "version": "0.0.1", "jsnext:source": "./src/index.ts", "main": "./dist/lib/index.js", "module": "./dist/es/index.js", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 18fd191de..2da0b0009 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,21 +19,36 @@ importers: '@commitlint/config-conventional': specifier: ^17.0.3 version: 17.8.1 + '@jsdevtools/version-bump-prompt': + specifier: 6.1.0 + version: 6.1.0 '@modern-js/eslint-config': specifier: ^2.54.2 version: 2.56.1(typescript@5.5.4) + chalk: + specifier: 4.1.2 + version: 4.1.2 commitizen: specifier: 4.2.5 version: 4.2.5(@types/node@20.5.1)(typescript@5.5.4) + dayjs: + specifier: 1.11.2 + version: 1.11.2 eslint: specifier: ^8.57.0 version: 8.57.0 + execa: + specifier: 4.1.0 + version: 4.1.0 husky: specifier: ^8.0.1 version: 8.0.3 lint-staged: specifier: ^13.0.3 version: 13.3.0(enquirer@2.4.1) + minimist: + specifier: 1.2.5 + version: 1.2.5 nx: specifier: 19.5.2 version: 19.5.2 @@ -43,6 +58,9 @@ importers: pretty-quick: specifier: 3.1.3 version: 3.1.3(prettier@2.8.8) + semver: + specifier: 7.3.7 + version: 7.3.7 apps/site: dependencies: @@ -1897,6 +1915,15 @@ packages: '@jridgewell/trace-mapping@0.3.9': resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} + '@jsdevtools/ez-spawn@3.0.4': + resolution: {integrity: sha512-f5DRIOZf7wxogefH03RjMPMdBF7ADTWUMoOs9kaJo06EfwF+aFhMZMDZxHg/Xe12hptN9xoZjGso2fdjapBRIA==} + engines: {node: '>=10'} + + '@jsdevtools/version-bump-prompt@6.1.0': + resolution: {integrity: sha512-NJFLJRiD3LLFBgSxAb6B255xhWCGgdtzmh6UjHK2b7SRGX2DDKJH5O4BJ0GTStBu4NnaNgMbkr1TLW3pLOBkOQ==} + engines: {node: '>=10'} + hasBin: true + '@loadable/babel-plugin@5.15.3': resolution: {integrity: sha512-kwEsPxCk8vnwbTfbA4lHqT5t0u0czCQTnCcmOaTjxT5lCn7yZCBTBa9D7lHs+MLM2WyPsZlee3Qh0TTkMMi5jg==} engines: {node: '>=8'} @@ -3739,6 +3766,10 @@ packages: resolution: {integrity: sha512-sKpyeERZ02v1FeCZT8lrfJq5u6goHCtpTAzPwJYe7c8SPFOboNjNg1vz2L4VTn9T4PQxEx13TbXLmYUcS6Ug7Q==} engines: {node: '>=0.10.0'} + array-back@3.1.0: + resolution: {integrity: sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==} + engines: {node: '>=6'} + array-buffer-byte-length@1.0.1: resolution: {integrity: sha512-ahC5W1xgou+KTXix4sAO8Ki12Q+jf4i0+tmk3sC+zgcynshkHxzpXdImBehiUYKKKDwvfFiJl1tZt6ewscS1Mg==} engines: {node: '>= 0.4'} @@ -3986,6 +4017,9 @@ packages: resolution: {integrity: sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==} engines: {node: '>= 0.4'} + call-me-maybe@1.0.2: + resolution: {integrity: sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ==} + callsites@3.1.0: resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==} engines: {node: '>=6'} @@ -4192,6 +4226,10 @@ packages: comma-separated-tokens@2.0.3: resolution: {integrity: sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==} + command-line-args@5.2.1: + resolution: {integrity: sha512-H4UfQhZyakIjC74I9d34fGYDwk3XpSr17QhEd0Q3I9Xq1CETHo4Hcuo87WyWHpAF1aSLjLRf5lD9ZGX2qStUvg==} + engines: {node: '>=4.0.0'} + commander@10.0.1: resolution: {integrity: sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==} engines: {node: '>=14'} @@ -4485,6 +4523,9 @@ packages: dayjs@1.11.11: resolution: {integrity: sha512-okzr3f11N6WuqYtZSvm+F776mB41wRZMhKP+hc34YdW+KmtYYK9iqvHSwo2k9FEH3fhGXvOPV6yz2IcSrfRUDg==} + dayjs@1.11.2: + resolution: {integrity: sha512-F4LXf1OeU9hrSYRPTTj/6FbO4HTjPKXvEIC1P2kcnFurViINCVk3ZV0xAS3XVx9MkMsXbbqlK6hjseaYbgKEHw==} + de-indent@1.0.2: resolution: {integrity: sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==} @@ -5146,6 +5187,10 @@ packages: find-node-modules@2.1.3: resolution: {integrity: sha512-UC2I2+nx1ZuOBclWVNdcnbDR5dlrOdVb7xNjmT/lHE+LsgztWks3dG7boJ37yTS/venXw84B/mAW9uHVoC5QRg==} + find-replace@3.0.0: + resolution: {integrity: sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==} + engines: {node: '>=4.0.0'} + find-root@1.1.0: resolution: {integrity: sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==} @@ -5742,6 +5787,10 @@ packages: inline-style-parser@0.1.1: resolution: {integrity: sha512-7NXolsK4CAS5+xvdj5OMMbI962hU/wvwoxk+LWR9Ek9bVtyuuYScDN6eS0rUm6TxApFpw7CX1o4uJzcd4AyD3Q==} + inquirer@7.3.3: + resolution: {integrity: sha512-JG3eIAj5V9CwcGvuOmoo6LB9kbAYT8HXffUl6memuszlwDC/qvFAJw49XJ5NROSFNPxp3iQg1GqkFhaY/CR0IA==} + engines: {node: '>=8.0.0'} + inquirer@8.2.4: resolution: {integrity: sha512-nn4F01dxU8VeKfq192IjLsxu0/OmMZ4Lg3xKAns148rCaXP6ntAoEkVYZThWjwON8AlzdZZi6oqnhNbxUG9hVg==} engines: {node: '>=12.0.0'} @@ -6823,6 +6872,9 @@ packages: resolution: {integrity: sha512-Q4r8ghd80yhO/0j1O3B2BjweX3fiHg9cdOwjJd2J76Q135c+NDxGCqdYKQ1SKBuFfgWbAUzBfvYjPUEeNgqN1A==} engines: {node: '>= 6'} + minimist@1.2.5: + resolution: {integrity: sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==} + minimist@1.2.6: resolution: {integrity: sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==} @@ -8260,6 +8312,10 @@ packages: run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} + rxjs@6.6.7: + resolution: {integrity: sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==} + engines: {npm: '>=2.0.0'} + rxjs@7.8.1: resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==} @@ -8439,6 +8495,11 @@ packages: resolution: {integrity: sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==} hasBin: true + semver@7.3.7: + resolution: {integrity: sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==} + engines: {node: '>=10'} + hasBin: true + semver@7.5.4: resolution: {integrity: sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==} engines: {node: '>=10'} @@ -9094,6 +9155,10 @@ packages: engines: {node: '>=14.17'} hasBin: true + typical@4.0.0: + resolution: {integrity: sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==} + engines: {node: '>=8'} + ufo@1.5.4: resolution: {integrity: sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==} @@ -11585,6 +11650,24 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 + '@jsdevtools/ez-spawn@3.0.4': + dependencies: + call-me-maybe: 1.0.2 + cross-spawn: 7.0.3 + string-argv: 0.3.2 + type-detect: 4.0.8 + + '@jsdevtools/version-bump-prompt@6.1.0': + dependencies: + '@jsdevtools/ez-spawn': 3.0.4 + command-line-args: 5.2.1 + detect-indent: 6.1.0 + detect-newline: 3.1.0 + globby: 11.1.0 + inquirer: 7.3.3 + log-symbols: 4.1.0 + semver: 7.3.7 + '@loadable/babel-plugin@5.15.3(@babel/core@7.24.9)': dependencies: '@babel/core': 7.24.9 @@ -14075,7 +14158,7 @@ snapshots: graphemer: 1.4.0 ignore: 5.3.1 natural-compare-lite: 1.4.0 - semver: 7.6.3 + semver: 7.3.7 tsutils: 3.21.0(typescript@5.5.4) optionalDependencies: typescript: 5.5.4 @@ -14120,7 +14203,7 @@ snapshots: debug: 4.3.5(supports-color@5.5.0) globby: 11.1.0 is-glob: 4.0.3 - semver: 7.6.3 + semver: 7.3.7 tsutils: 3.21.0(typescript@5.5.4) optionalDependencies: typescript: 5.5.4 @@ -14137,7 +14220,7 @@ snapshots: '@typescript-eslint/typescript-estree': 5.62.0(typescript@5.5.4) eslint: 8.57.0 eslint-scope: 5.1.1 - semver: 7.6.3 + semver: 7.3.7 transitivePeerDependencies: - supports-color - typescript @@ -14552,6 +14635,8 @@ snapshots: arr-union@3.1.0: {} + array-back@3.1.0: {} + array-buffer-byte-length@1.0.1: dependencies: call-bind: 1.0.7 @@ -14871,6 +14956,8 @@ snapshots: get-intrinsic: 1.2.4 set-function-length: 1.2.2 + call-me-maybe@1.0.2: {} + callsites@3.1.0: {} camel-case@4.1.2: @@ -15073,6 +15160,13 @@ snapshots: comma-separated-tokens@2.0.3: {} + command-line-args@5.2.1: + dependencies: + array-back: 3.1.0 + find-replace: 3.0.0 + lodash.camelcase: 4.3.0 + typical: 4.0.0 + commander@10.0.1: {} commander@11.0.0: {} @@ -15429,6 +15523,8 @@ snapshots: dayjs@1.11.11: {} + dayjs@1.11.2: {} + de-indent@1.0.2: optional: true @@ -16332,6 +16428,10 @@ snapshots: findup-sync: 4.0.0 merge: 2.1.1 + find-replace@3.0.0: + dependencies: + array-back: 3.1.0 + find-root@1.1.0: {} find-up@3.0.0: @@ -16403,7 +16503,7 @@ snapshots: minimatch: 3.1.2 node-abort-controller: 3.1.1 schema-utils: 3.3.0 - semver: 7.6.3 + semver: 7.3.7 tapable: 2.2.1 typescript: 5.0.4 webpack: 5.93.0 @@ -17027,6 +17127,22 @@ snapshots: inline-style-parser@0.1.1: {} + inquirer@7.3.3: + dependencies: + ansi-escapes: 4.3.2 + chalk: 4.1.2 + cli-cursor: 3.1.0 + cli-width: 3.0.0 + external-editor: 3.1.0 + figures: 3.2.0 + lodash: 4.17.21 + mute-stream: 0.0.8 + run-async: 2.4.1 + rxjs: 6.6.7 + string-width: 4.2.3 + strip-ansi: 6.0.1 + through: 2.3.8 + inquirer@8.2.4: dependencies: ansi-escapes: 4.3.2 @@ -17737,7 +17853,7 @@ snapshots: json5@1.0.2: dependencies: - minimist: 1.2.8 + minimist: 1.2.5 json5@2.2.3: {} @@ -18551,6 +18667,8 @@ snapshots: is-plain-obj: 1.1.0 kind-of: 6.0.3 + minimist@1.2.5: {} + minimist@1.2.6: {} minimist@1.2.8: {} @@ -18652,7 +18770,7 @@ snapshots: dependencies: hosted-git-info: 4.1.0 is-core-module: 2.15.0 - semver: 7.6.3 + semver: 7.3.7 validate-npm-package-license: 3.0.4 normalize-path@3.0.0: {} @@ -20256,6 +20374,10 @@ snapshots: dependencies: queue-microtask: 1.2.3 + rxjs@6.6.7: + dependencies: + tslib: 1.14.1 + rxjs@7.8.1: dependencies: tslib: 2.6.3 @@ -20401,6 +20523,10 @@ snapshots: semver@6.3.1: {} + semver@7.3.7: + dependencies: + lru-cache: 6.0.0 + semver@7.5.4: dependencies: lru-cache: 6.0.0 @@ -20753,7 +20879,7 @@ snapshots: strong-log-transformer@2.1.0: dependencies: duplexer: 0.1.2 - minimist: 1.2.8 + minimist: 1.2.5 through: 2.3.8 style-inject@0.3.0: {} @@ -21178,6 +21304,8 @@ snapshots: typescript@5.5.4: {} + typical@4.0.0: {} + ufo@1.5.4: {} unbox-primitive@1.0.2: diff --git a/scripts/release.js b/scripts/release.js new file mode 100644 index 000000000..9f67a7375 --- /dev/null +++ b/scripts/release.js @@ -0,0 +1,157 @@ +const fs = require('fs'); +const semver = require('semver'); +const dayjs = require('dayjs'); +const args = require('minimist')(process.argv.slice(2)); +const bumpPrompt = require('@jsdevtools/version-bump-prompt'); +const execa = require('execa'); +const chalk = require('chalk'); + +const step = (msg) => { + console.log(chalk.cyan(msg)); +}; + +const run = async (bin, args, opts = {}) => { + return await execa(bin, args, { stdio: 'inherit', ...opts }); +}; + +const currentVersion = require('../package.json').version; + +const actionPublishCanary = + ['preminor', 'prepatch'].includes(args.version) && process.env.CI; + +async function main() { + // build all packages with types + step('\nSelect bumpVersion...'); + const selectVersion = await bumpVersion(); + if (selectVersion) { + step( + `\nbumpVersion ${selectVersion.oldVersion} => ${selectVersion.newVersion}...`, + ); + } + + // run tests before release + step('\nRunning tests...'); + await test(); + + // build all packages with types + step('\nBuilding all packages...'); + await build(); + + const { stdout } = await run('git', ['diff'], { stdio: 'pipe' }); + if (stdout) { + if (process.env.CI) { + step('\nSetting git info...'); + await run('git', [ + 'config', + '--global', + 'user.name', + 'github-actions[bot]', + ]); + await run('git', [ + 'config', + '--global', + 'user.email', + 'github-actions[bot]@users.noreply.github.com', + ]); + } + step('\nCommitting changes...'); + + // canary don't need to push + if (!actionPublishCanary) { + await run('git', ['add', '-A']); + await run('git', [ + 'commit', + '-m', + `release: v${selectVersion.newVersion}`, + ]); + } + } else { + console.log('No changes to commit.'); + } + + if (selectVersion) { + step('\nPublishing...'); + await publish(selectVersion.newVersion); + } else { + console.log('No new version:', selectVersion); + } + + if (!actionPublishCanary) { + // canary don't need to push + // push to GitHub + step('\nPushing to GitHub...'); + await pushToGithub(selectVersion); + } +} + +async function build() { + await run('pnpm', ['build']); +} + +async function test() { + await run('pnpm', ['test']); +} + +async function bumpVersion() { + let version = args.version; + if (version && actionPublishCanary) { + const hash = dayjs().format('YYYYMMDDHHmmss'); + version = semver.inc(currentVersion, version, 'beta-' + hash); + } + + return await bumpPrompt({ + files: ['package.json', 'packages/*/package.json'], + release: version || '', + push: false, + tag: false, + }); +} + +async function pushToGithub(selectVersion) { + // push to GitHub + await run('git', ['tag', `v${selectVersion.newVersion}`]); + await run('git', ['push']); + await run('git', ['push', 'origin', '--tags']); +} + +async function publish(version) { + step('\nSetting npmrc ...'); + await writeNpmrc(); + + let releaseTag = 'latest'; + if (version.includes('alpha')) { + releaseTag = 'alpha'; + } else if (version.includes('beta')) { + releaseTag = 'beta'; + } else if (version.includes('rc')) { + releaseTag = 'rc'; + } + let publishArgs = ['-r', 'publish', '--access', 'public', '--no-git-checks']; + if (version) { + publishArgs = publishArgs.concat(['--tag', releaseTag]); + } + + await run('pnpm', publishArgs); +} + +async function writeNpmrc() { + if (process.env.CI) { + const npmRcPath = `${process.env.HOME}/.npmrc`; + console.info( + `curring .npmrc file path is ${npmRcPath}, npm token is ${process.env.NPM_TOKEN}`, + ); + if (fs.existsSync(npmRcPath)) { + console.info('Found existing .npmrc file'); + } else { + console.info('No .npmrc file found, creating one'); + fs.writeFileSync( + npmRcPath, + `//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}`, + ); + } + } +} + +main().catch((err) => { + console.error(err); +});