From c8e0978a16ccbfee1c6d599c63d3c08a485e304c Mon Sep 17 00:00:00 2001 From: Emily Date: Wed, 24 Apr 2024 11:03:02 +0200 Subject: [PATCH 01/17] workflow --- .github/workflows/release.yml | 37 ++++++ package.json | 7 + pnpm-lock.yaml | 244 +++++++++++++++++++++++++++++++++- scripts/release-cli.ts | 115 ++++++++++++++++ 4 files changed, 401 insertions(+), 2 deletions(-) create mode 100644 scripts/release-cli.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 55331ed46..8517b18e0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,3 +65,40 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + release-cli-assets: + name: Release CLI assets + needs: release + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + steps: + - uses: actions/checkout@v3 + with: + # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits + fetch-depth: 0 + # This makes the PR pushed to use GITHUB_TOKEN and trigger the checks + persist-credentials: false + + - name: Install pnpm + uses: pnpm/action-setup@v2 + with: + version: 8 + + - name: Use Node.js ${{ steps.config.outputs.NVMRC }} + uses: actions/setup-node@v3 + with: + node-version: ${{ steps.config.outputs.NVMRC }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build + run: pnpm build + + - name: Release CLI Assets + run: npx changeset version && pnpm run release:cli + env: + MATRIX_OS: ${{ matrix.os }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/package.json b/package.json index 72e23d501..11c6c6e69 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "test": "vitest", "test:canary": "tsx ./scripts/test-canary.ts", + "release:cli": "tsx ./scripts/release-cli.ts", "lint": "eslint .", "lint:fix": "eslint . --fix", "prepare": "husky install", @@ -107,5 +108,11 @@ "engines": { "node": "18.x", "pnpm": "8.x" + }, + "dependencies": { + "@octokit/core": "^6.1.2", + "@pnpm/exportable-manifest": "^6.0.0", + "@pnpm/read-project-manifest": "^6.0.0", + "@pnpm/write-project-manifest": "^6.0.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cf2e54103..f9ad825ef 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,19 @@ settings: importers: .: + dependencies: + '@octokit/core': + specifier: ^6.1.2 + version: 6.1.2 + '@pnpm/exportable-manifest': + specifier: ^6.0.0 + version: 6.0.0 + '@pnpm/read-project-manifest': + specifier: ^6.0.0 + version: 6.0.0 + '@pnpm/write-project-manifest': + specifier: ^6.0.0 + version: 6.0.0 devDependencies: '@babel/core': specifier: ^7.24.4 @@ -3979,6 +3992,12 @@ packages: protobufjs: 7.2.5 yargs: 17.7.2 + /@gwhitney/detect-indent@7.0.1: + resolution: + { integrity: sha512-7bQW+gkKa2kKZPeJf6+c6gFK9ARxQfn+FKy9ScTBppyKRWH2KzsmweXUoklqeEiHiNVWaeP5csIdsNq6w7QhzA== } + engines: { node: '>=12.20' } + dev: false + /@honeycombio/opentelemetry-node@0.4.0(supports-color@9.4.0): resolution: { integrity: sha512-6PFX8FGW7uA7vQ3mxNIoN36rH9Zx5kXh4kKP9zu28nynyWyy9JE3l8PNJYd9FS2L/d88ZUpQAiQ1pROaANd5MA== } @@ -4929,6 +4948,76 @@ packages: - supports-color dev: true + /@octokit/auth-token@5.1.1: + resolution: + { integrity: sha512-rh3G3wDO8J9wSjfI436JUKzHIxq8NaiL0tVeB2aXmG6p/9859aUOAjA9pmSPNGGZxfwmaJ9ozOJImuNVJdpvbA== } + engines: { node: '>= 18' } + dev: false + + /@octokit/core@6.1.2: + resolution: + { integrity: sha512-hEb7Ma4cGJGEUNOAVmyfdB/3WirWMg5hDuNFVejGEDFqupeOysLc2sG6HJxY2etBp5YQu5Wtxwi020jS9xlUwg== } + engines: { node: '>= 18' } + dependencies: + '@octokit/auth-token': 5.1.1 + '@octokit/graphql': 8.1.1 + '@octokit/request': 9.1.1 + '@octokit/request-error': 6.1.1 + '@octokit/types': 13.4.1 + before-after-hook: 3.0.2 + universal-user-agent: 7.0.2 + dev: false + + /@octokit/endpoint@10.1.1: + resolution: + { integrity: sha512-JYjh5rMOwXMJyUpj028cu0Gbp7qe/ihxfJMLc8VZBMMqSwLgOxDI1911gV4Enl1QSavAQNJcwmwBF9M0VvLh6Q== } + engines: { node: '>= 18' } + dependencies: + '@octokit/types': 13.4.1 + universal-user-agent: 7.0.2 + dev: false + + /@octokit/graphql@8.1.1: + resolution: + { integrity: sha512-ukiRmuHTi6ebQx/HFRCXKbDlOh/7xEV6QUXaE7MJEKGNAncGI/STSbOkl12qVXZrfZdpXctx5O9X1AIaebiDBg== } + engines: { node: '>= 18' } + dependencies: + '@octokit/request': 9.1.1 + '@octokit/types': 13.4.1 + universal-user-agent: 7.0.2 + dev: false + + /@octokit/openapi-types@22.1.0: + resolution: + { integrity: sha512-pGUdSP+eEPfZiQHNkZI0U01HLipxncisdJQB4G//OAmfeO8sqTQ9KRa0KF03TUPCziNsoXUrTg4B2Q1EX++T0Q== } + dev: false + + /@octokit/request-error@6.1.1: + resolution: + { integrity: sha512-1mw1gqT3fR/WFvnoVpY/zUM2o/XkMs/2AszUUG9I69xn0JFLv6PGkPhNk5lbfvROs79wiS0bqiJNxfCZcRJJdg== } + engines: { node: '>= 18' } + dependencies: + '@octokit/types': 13.4.1 + dev: false + + /@octokit/request@9.1.1: + resolution: + { integrity: sha512-pyAguc0p+f+GbQho0uNetNQMmLG1e80WjkIaqqgUkihqUp0boRU6nKItXO4VWnr+nbZiLGEyy4TeKRwqaLvYgw== } + engines: { node: '>= 18' } + dependencies: + '@octokit/endpoint': 10.1.1 + '@octokit/request-error': 6.1.1 + '@octokit/types': 13.4.1 + universal-user-agent: 7.0.2 + dev: false + + /@octokit/types@13.4.1: + resolution: + { integrity: sha512-Y73oOAzRBAUzR/iRAbGULzpNkX8vaxKCqEtg6K74Ff3w9f5apFnWtE/2nade7dMWWW3bS5Kkd6DJS4HF04xreg== } + dependencies: + '@octokit/openapi-types': 22.1.0 + dev: false + /@open-draft/deferred-promise@2.2.0: resolution: { integrity: sha512-CecwLWx3rhxVQF6V4bAgPS5t+So2sTbPgAzafKkVizyi7tlwpcFpdFqq+wqF2OwNBmqFuu6tOyouTuxgpMfzmA== } @@ -5566,6 +5655,92 @@ packages: dev: true optional: true + /@pnpm/constants@8.0.0: + resolution: + { integrity: sha512-yQosGUvYPpAjb1jOFcdbwekRjZRVxN6C0hHzfRCZrMKbxGjt/E0g0RcFlEDNVZ95tm4oMMcr7nEPa7H7LX3emw== } + engines: { node: '>=18.12' } + dev: false + + /@pnpm/error@6.0.0: + resolution: + { integrity: sha512-SKtHdV09k9+6jkohv9YuYmKMKNpxknoGjo0c6eN8x2Z3MHW2cuSt1OD/L16eCqdKQL+FUbvULxig0b9X9VK2/g== } + engines: { node: '>=18.12' } + dependencies: + '@pnpm/constants': 8.0.0 + dev: false + + /@pnpm/exportable-manifest@6.0.0: + resolution: + { integrity: sha512-5RLrRE4ZbIijBIXjTOtTVxTvO+lu0oh+kLi0WO/eEnoV50UfiG9h9VEUx5Sj5RW4cixTbnAQMlsRX1XYeDLTgQ== } + engines: { node: '>=18.12' } + dependencies: + '@pnpm/error': 6.0.0 + '@pnpm/read-project-manifest': 6.0.0 + '@pnpm/types': 10.0.0 + p-map-values: 1.0.0 + ramda: /@pnpm/ramda@0.28.1 + dev: false + + /@pnpm/graceful-fs@4.0.0: + resolution: + { integrity: sha512-933nhV2Prp51522poxX6Chvb7kEW3U3kzVWoqDU1+icB+QE7z/2qQ8wYHsBt4jm0Uil/sF67t77ugOr8bR63kg== } + engines: { node: '>=18.12' } + dependencies: + graceful-fs: 4.2.11 + dev: false + + /@pnpm/ramda@0.28.1: + resolution: + { integrity: sha512-zcAG+lvU0fMziNeGXpPyCyCJYp5ZVrPElEE4t14jAmViaihohocZ+dDkcRIyAomox8pQsuZnv1EyHR+pOhmUWw== } + dev: false + + /@pnpm/read-project-manifest@6.0.0: + resolution: + { integrity: sha512-X2LYdHErr7BQroRcV0LlilGXMA4SILf0D1adxQmr0CoEAxJThxcCEPIMLZqi9YukUF9oF5vV7qe/mdvI/r79Bw== } + engines: { node: '>=18.12' } + dependencies: + '@gwhitney/detect-indent': 7.0.1 + '@pnpm/error': 6.0.0 + '@pnpm/graceful-fs': 4.0.0 + '@pnpm/text.comments-parser': 3.0.0 + '@pnpm/types': 10.0.0 + '@pnpm/write-project-manifest': 6.0.0 + fast-deep-equal: 3.1.3 + is-windows: 1.0.2 + json5: 2.2.3 + lodash.clonedeep: 4.5.0 + parse-json: 5.2.0 + read-yaml-file: 2.1.0 + sort-keys: 4.2.0 + strip-bom: 4.0.0 + dev: false + + /@pnpm/text.comments-parser@3.0.0: + resolution: + { integrity: sha512-BSGvYd59kPKVTUk1InekEp+TiPnJ8650/bQyiOUFSvqHi61YipcR+E4H2i3xTnk2e+GHdGbXvEtAZbQmyxb0/g== } + engines: { node: '>=18.12' } + dependencies: + strip-comments-strings: 1.2.0 + dev: false + + /@pnpm/types@10.0.0: + resolution: + { integrity: sha512-P608MRTOExt5BkIN2hsrb/ycEchwaPW/x80ujJUAqxKZSXNVAOrlEu3KJ+2+jTCunyWmo/EcE01ZdwCw8jgVrQ== } + engines: { node: '>=18.12' } + dev: false + + /@pnpm/write-project-manifest@6.0.0: + resolution: + { integrity: sha512-DTjuH7Ls4v8CpfvOCtZkIIySpEKPGh7hEUpH5tqvVblzWQwfheoHfeBvyjGo975lvHsR2bCt2s8F7bv6DQ8o8g== } + engines: { node: '>=18.12' } + dependencies: + '@pnpm/text.comments-parser': 3.0.0 + '@pnpm/types': 10.0.0 + json5: 2.2.3 + write-file-atomic: 5.0.1 + write-yaml-file: 5.0.0 + dev: false + /@protobufjs/aspromise@1.1.2: resolution: { integrity: sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ== } @@ -7738,6 +7913,11 @@ packages: { integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== } dev: false + /before-after-hook@3.0.2: + resolution: + { integrity: sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A== } + dev: false + /better-ajv-errors@1.2.0(ajv@8.12.0): resolution: { integrity: sha512-UW+IsFycygIo7bclP9h5ugkNH8EjCSgqyFB/yQ4Hqqa1OEYDtb0uFIkYE0b6+CjkgJYVM5UKI/pJPxjYe9EZlA== } @@ -11140,7 +11320,6 @@ packages: resolution: { integrity: sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA== } engines: { node: '>=0.8.19' } - dev: true /indent-string@4.0.0: resolution: @@ -11545,7 +11724,6 @@ packages: resolution: { integrity: sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== } engines: { node: '>=0.10.0' } - dev: true /is-wsl@2.2.0: resolution: @@ -12052,6 +12230,11 @@ packages: { integrity: sha512-ZzydJKfUHJwHa+hF5X66zLFCBrWn5GeF28OHEr4WVWtNDXlQ/IjWKPBiikqKo2ne0+v6JgCgJ0GzJp8k8bHC7w== } dev: false + /lodash.clonedeep@4.5.0: + resolution: + { integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ== } + dev: false + /lodash.compact@3.0.1: resolution: { integrity: sha512-2ozeiPi+5eBXW1CLtzjk8XQFhQOEMwwfxblqeq6EGyTxZJ1bPATqilY0e6g2SLQpP4KuMeuioBhEnWz5Pr7ICQ== } @@ -13519,6 +13702,12 @@ packages: p-limit: 4.0.0 dev: false + /p-map-values@1.0.0: + resolution: + { integrity: sha512-/n8QJM4Os3HLRMSuQWwAocsMExENSQwWTgRi8m3JVEOWQ/4gud14igBcnYvSGQTbiyZbuizxEmwf0w3ITn67gg== } + engines: { node: '>=14' } + dev: false + /p-map@2.1.0: resolution: { integrity: sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw== } @@ -14394,6 +14583,15 @@ packages: strip-bom: 3.0.0 dev: true + /read-yaml-file@2.1.0: + resolution: + { integrity: sha512-UkRNRIwnhG+y7hpqnycCL/xbTk7+ia9VuVTC0S+zVbwd65DI9eUpRMfsWIGrCWxTU/mi+JW8cHQCrv+zfCbEPQ== } + engines: { node: '>=10.13' } + dependencies: + js-yaml: 4.1.0 + strip-bom: 4.0.0 + dev: false + /readable-stream@1.0.34: resolution: { integrity: sha512-ok1qVCJuRkNmvebYikljxJA/UEsKwLl2nI1OmaqAu4/UE+h0wKCHok4XkL/gvi39OacXvw59RJUOFUkDib2rHg== } @@ -15252,6 +15450,14 @@ packages: tslib: 2.6.2 dev: true + /sort-keys@4.2.0: + resolution: + { integrity: sha512-aUYIEU/UviqPgc8mHR6IW1EGxkAXpeRETYcrzg8cLAvUPZcpAlleSXHV2mY7G12GphSH6Gzv+4MMVSSkbdteHg== } + engines: { node: '>=8' } + dependencies: + is-plain-obj: 2.1.0 + dev: false + /sort-object-keys@1.1.3: resolution: { integrity: sha512-855pvK+VkU7PaKYPc+Jjnmt4EzejQHyhhF33q31qG8x7maDzkeFhAAThdCYay11CISO+qAMwjOBP+fPZe0IPyg== } @@ -15496,6 +15702,17 @@ packages: engines: { node: '>=4' } dev: true + /strip-bom@4.0.0: + resolution: + { integrity: sha512-3xurFv5tEgii33Zi8Jtp55wEIILR9eh34FAW00PZf+JnSsTmV/ioewSgQl97JHvgjoRGwPShsWm+IdrxB35d0w== } + engines: { node: '>=8' } + dev: false + + /strip-comments-strings@1.2.0: + resolution: + { integrity: sha512-zwF4bmnyEjZwRhaak9jUWNxc0DoeKBJ7lwSN/LEc8dQXZcUFG6auaaTQJokQWXopLdM3iTx01nQT8E4aL29DAQ== } + dev: false + /strip-final-newline@2.0.0: resolution: { integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA== } @@ -16227,6 +16444,11 @@ packages: unist-util-is: 4.1.0 dev: true + /universal-user-agent@7.0.2: + resolution: + { integrity: sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q== } + dev: false + /universalify@0.1.2: resolution: { integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== } @@ -16643,6 +16865,24 @@ packages: resolution: { integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== } + /write-file-atomic@5.0.1: + resolution: + { integrity: sha512-+QU2zd6OTD8XWIJCbffaiQeH9U73qIqafo1x6V1snCWYGJf6cVE0cDR4D8xRzcEnfI21IFrUPzPGtcPf8AC+Rw== } + engines: { node: ^14.17.0 || ^16.13.0 || >=18.0.0 } + dependencies: + imurmurhash: 0.1.4 + signal-exit: 4.1.0 + dev: false + + /write-yaml-file@5.0.0: + resolution: + { integrity: sha512-FdNA4RyH1L43TlvGG8qOMIfcEczwA5ij+zLXUy3Z83CjxhLvcV7/Q/8pk22wnCgYw7PJhtK+7lhO+qqyT4NdvQ== } + engines: { node: '>=16.14' } + dependencies: + js-yaml: 4.1.0 + write-file-atomic: 5.0.1 + dev: false + /ws@7.5.9: resolution: { integrity: sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q== } diff --git a/scripts/release-cli.ts b/scripts/release-cli.ts new file mode 100644 index 000000000..193f187d9 --- /dev/null +++ b/scripts/release-cli.ts @@ -0,0 +1,115 @@ +import { createExportableManifest } from '@pnpm/exportable-manifest'; +import { readProjectManifest } from '@pnpm/read-project-manifest'; +import { writeProjectManifest } from '@pnpm/write-project-manifest'; +import { execFile, exec as execRaw } from 'child_process'; +import { Octokit } from '@octokit/core'; +import fs from 'fs'; +import * as util from 'util'; +const exec = util.promisify(execRaw); + +const PATH_TO_CLI = process.cwd() + '/cli'; +const PATH_TO_CLIENT = process.cwd() + '/packages/client'; +const PATH_TO_CODEGEN = process.cwd() + '/packages/codegen'; +const PATH_TO_IMPORTER = process.cwd() + '/packages/importer'; +const PATH_TO_PGROLL = process.cwd() + '/packages/pgroll'; + +const base = { + owner: 'xataio', + repo: 'client-ts', + headers: { + 'X-GitHub-Api-Version': '2022-11-28' + } +}; + +const matrixToOclif = (os: string) => { + switch (os) { + case 'windows-latest': + return 'win'; + case 'macos-latest': + return 'macos'; + case 'ubuntu-latest': + return 'deb'; + default: + throw new Error('Unsupported OS'); + } +}; + +async function main() { + if (!process.env.MATRIX_OS) throw new Error('MATRIX_OS is not set'); + if (!process.env.GITHUB_TOKEN) throw new Error('GITHUB_TOKEN is not set'); + + const operatingSystem = matrixToOclif(process.env.MATRIX_OS); + + const { manifest, fileName } = await readProjectManifest(PATH_TO_CLI); + const { + manifest: { version: clientVersion } + } = await readProjectManifest(PATH_TO_CLIENT); + const { + manifest: { version: codegenVersion } + } = await readProjectManifest(PATH_TO_CODEGEN); + const { + manifest: { version: importerVersion } + } = await readProjectManifest(PATH_TO_IMPORTER); + const { + manifest: { version: pgrollVersion } + } = await readProjectManifest(PATH_TO_PGROLL); + + // Assume changeset version has been called and all the + // versions in package jsons are up to date + + const workspaceProtocolPackageManifest = await createExportableManifest(PATH_TO_CLI, { + ...manifest, + dependencies: { + ...manifest.dependencies, + '@xata.io/client': clientVersion ?? 'latest', + '@xata.io/codegen': codegenVersion ?? 'latest', + '@xata.io/importer': importerVersion ?? 'latest', + '@xata.io/pgroll': pgrollVersion ?? 'latest' + } + }); + + await writeProjectManifest(`${PATH_TO_CLI}/${fileName}`, workspaceProtocolPackageManifest); + + process.chdir(PATH_TO_CLI); + + execFile('rm', ['-rf', `${PATH_TO_CLI}/npm-shrinkwrap.json`]); + execFile('touch', [`${PATH_TO_CLI}/npm-shrinkwrap.json`]); + + const pack = await exec(`pnpm oclif pack ${operatingSystem}`); + if (pack.stderr) { + throw new Error(`Failed to pack: ${pack.stderr}`); + } + console.log('Successfully packed CLI', pack.stdout); + + const octokit = new Octokit({ + auth: process.env.GITHUB_TOKEN + }); + + const tag = encodeURIComponent(`@xata.io/cli@${manifest.version}`); + + const release = await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { + ...base, + tag + }); + + if (!release.data) throw new Error('Release not found'); + + const pathToAsset = `${PATH_TO_CLI}/dist/${operatingSystem}`; + + const files = fs.readdirSync(pathToAsset); + + for (const file of files) { + const data = fs.readFileSync(pathToAsset + `/${file}`); + const upload = await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}', { + ...base, + name: file, + label: file, + release_id: release.data.id, + data: data, + baseUrl: 'https://uploads.github.com' + }); + console.log('Finished uploading asset', upload.status); + } +} + +main(); From 93f2c8be2d4da5adb85edf3e9056d066e985f54d Mon Sep 17 00:00:00 2001 From: Emily Date: Wed, 24 Apr 2024 11:09:37 +0200 Subject: [PATCH 02/17] fix --- cli/package.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cli/package.json b/cli/package.json index 923c0fde6..d2878752c 100644 --- a/cli/package.json +++ b/cli/package.json @@ -77,6 +77,15 @@ "hooks": { "init": "./dist/hooks/init/compatibility" }, + "macos": { + "identifier": "com.xata.cli" + }, + "deb": { + "identifier": "com.xata.cli" + }, + "win": { + "identifier": "com.xata.cli" + }, "dirname": "xata", "commands": "./dist/commands", "plugins": [ From d94a31aa9262716ebcdd0038349dcdcb7213f225 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 10:35:21 +0200 Subject: [PATCH 03/17] build for windows --- .github/workflows/release.yml | 9 ++++++++- scripts/release-cli.ts | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8517b18e0..0bfe0e512 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -71,7 +71,7 @@ jobs: needs: release strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/checkout@v3 with: @@ -97,6 +97,13 @@ jobs: - name: Build run: pnpm build + - name: Install windows dependencies + if: matrix.os == 'windows-latest' + run: | + sudo apt-get update + sudo apt-get install -y nsis + sudo apt-get install -y p7zip + - name: Release CLI Assets run: npx changeset version && pnpm run release:cli env: diff --git a/scripts/release-cli.ts b/scripts/release-cli.ts index 193f187d9..d5f4cee8e 100644 --- a/scripts/release-cli.ts +++ b/scripts/release-cli.ts @@ -94,7 +94,8 @@ async function main() { if (!release.data) throw new Error('Release not found'); - const pathToAsset = `${PATH_TO_CLI}/dist/${operatingSystem}`; + // windows installer is saved in "win32" folder in cli/dist + const pathToAsset = `${PATH_TO_CLI}/dist/${operatingSystem === 'win' ? 'win32' : operatingSystem}`; const files = fs.readdirSync(pathToAsset); From f122b11954fc67040160204f9c2dc744e0c1034f Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 10:38:41 +0200 Subject: [PATCH 04/17] test build --- .github/workflows/release.yml | 121 +++++++++++++++++----------------- scripts/release-cli.ts | 38 ++++++----- 2 files changed, 81 insertions(+), 78 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0bfe0e512..18b476f41 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,70 +1,71 @@ -name: Release +name: Release Test on: push: branches: - - main - - next + - feat/release-assets + # - main + # - next concurrency: ${{ github.workflow }}-${{ github.ref }} jobs: - release: - name: Release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits - fetch-depth: 0 - # This makes the PR pushed to use GITHUB_TOKEN and trigger the checks - persist-credentials: false - - - name: Configure - run: | - git config user.email "system@xata.io" - git config user.name "Xata" - echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT - echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc - id: config - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - - name: Install pnpm - uses: pnpm/action-setup@v2 - with: - version: 8 - - - name: Use Node.js ${{ steps.config.outputs.NVMRC }} - uses: actions/setup-node@v3 - with: - node-version: ${{ steps.config.outputs.NVMRC }} - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install --frozen-lockfile - - - name: Build - run: pnpm build - - - name: Update next channel - if: github.ref_name == 'next' - env: - GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} - run: | - npx changeset version - npx changeset publish - - - name: Create Release Pull Request or Publish to npm - uses: changesets/action@v1 - if: github.ref_name == 'main' - with: - title: Release tracking - publish: npx changeset publish - version: node ./scripts/changeset-version.mjs - env: - GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + # release: + # name: Release + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # with: + # # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits + # fetch-depth: 0 + # # This makes the PR pushed to use GITHUB_TOKEN and trigger the checks + # persist-credentials: false + + # - name: Configure + # run: | + # git config user.email "system@xata.io" + # git config user.name "Xata" + # echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT + # echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc + # id: config + # env: + # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + # - name: Install pnpm + # uses: pnpm/action-setup@v2 + # with: + # version: 8 + + # - name: Use Node.js ${{ steps.config.outputs.NVMRC }} + # uses: actions/setup-node@v3 + # with: + # node-version: ${{ steps.config.outputs.NVMRC }} + # cache: 'pnpm' + + # - name: Install dependencies + # run: pnpm install --frozen-lockfile + + # - name: Build + # run: pnpm build + + # - name: Update next channel + # if: github.ref_name == 'next' + # env: + # GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} + # run: | + # npx changeset version + # npx changeset publish + + # - name: Create Release Pull Request or Publish to npm + # uses: changesets/action@v1 + # if: github.ref_name == 'main' + # with: + # title: Release tracking + # publish: npx changeset publish + # version: node ./scripts/changeset-version.mjs + # env: + # GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} + # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} release-cli-assets: name: Release CLI assets @@ -105,7 +106,7 @@ jobs: sudo apt-get install -y p7zip - name: Release CLI Assets - run: npx changeset version && pnpm run release:cli + run: pnpm run release:cli env: MATRIX_OS: ${{ matrix.os }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/release-cli.ts b/scripts/release-cli.ts index d5f4cee8e..469458819 100644 --- a/scripts/release-cli.ts +++ b/scripts/release-cli.ts @@ -81,18 +81,18 @@ async function main() { } console.log('Successfully packed CLI', pack.stdout); - const octokit = new Octokit({ - auth: process.env.GITHUB_TOKEN - }); + // const octokit = new Octokit({ + // auth: process.env.GITHUB_TOKEN + // }); - const tag = encodeURIComponent(`@xata.io/cli@${manifest.version}`); + // const tag = encodeURIComponent(`@xata.io/cli@${manifest.version}`); - const release = await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { - ...base, - tag - }); + // const release = await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { + // ...base, + // tag + // }); - if (!release.data) throw new Error('Release not found'); + // if (!release.data) throw new Error('Release not found'); // windows installer is saved in "win32" folder in cli/dist const pathToAsset = `${PATH_TO_CLI}/dist/${operatingSystem === 'win' ? 'win32' : operatingSystem}`; @@ -100,16 +100,18 @@ async function main() { const files = fs.readdirSync(pathToAsset); for (const file of files) { + console.log('file in directory', file); const data = fs.readFileSync(pathToAsset + `/${file}`); - const upload = await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}', { - ...base, - name: file, - label: file, - release_id: release.data.id, - data: data, - baseUrl: 'https://uploads.github.com' - }); - console.log('Finished uploading asset', upload.status); + console.log('data...', data); + // const upload = await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}', { + // ...base, + // name: file, + // label: file, + // release_id: release.data.id, + // data: data, + // baseUrl: 'https://uploads.github.com' + // }); + // console.log('Finished uploading asset', upload.status); } } From 888309807a43d16035cb36505e3a147793db5321 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 10:41:46 +0200 Subject: [PATCH 05/17] runs on --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 18b476f41..eb37d89be 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -73,6 +73,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 with: From b1b5e10fa1c4c5a2c4afd4c02a8014879f10d9a7 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 10:42:37 +0200 Subject: [PATCH 06/17] fix --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb37d89be..d305d177c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -69,7 +69,7 @@ jobs: release-cli-assets: name: Release CLI assets - needs: release + # needs: release strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] From 4211c0065d4d3dc75aa3ac563704b832410f7675 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 10:51:56 +0200 Subject: [PATCH 07/17] fix windows commands --- .github/workflows/release.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d305d177c..1403d0a74 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -102,9 +102,8 @@ jobs: - name: Install windows dependencies if: matrix.os == 'windows-latest' run: | - sudo apt-get update - sudo apt-get install -y nsis - sudo apt-get install -y p7zip + choco install nsis + choco install p7zip - name: Release CLI Assets run: pnpm run release:cli From 9bfc0ae09631706aa3d61603564b1a514c0e0d13 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 10:58:27 +0200 Subject: [PATCH 08/17] name --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1403d0a74..b4bac52ed 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -103,7 +103,7 @@ jobs: if: matrix.os == 'windows-latest' run: | choco install nsis - choco install p7zip + choco install 7zip - name: Release CLI Assets run: pnpm run release:cli From c05723abe695db529bdb9a5337fe719499dfa32b Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 11:09:32 +0200 Subject: [PATCH 09/17] try bundling win on linux --- .github/workflows/release.yml | 9 +++++---- scripts/release-cli.ts | 14 +++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b4bac52ed..81ae53a4c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -72,7 +72,7 @@ jobs: # needs: release strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -100,10 +100,11 @@ jobs: run: pnpm build - name: Install windows dependencies - if: matrix.os == 'windows-latest' + if: matrix.os == 'ubuntu-latest' run: | - choco install nsis - choco install 7zip + sudo apt-get update + sudo apt-get install -y nsis + sudo apt-get install -y p7zip - name: Release CLI Assets run: pnpm run release:cli diff --git a/scripts/release-cli.ts b/scripts/release-cli.ts index 469458819..e11f2e036 100644 --- a/scripts/release-cli.ts +++ b/scripts/release-cli.ts @@ -95,7 +95,8 @@ async function main() { // if (!release.data) throw new Error('Release not found'); // windows installer is saved in "win32" folder in cli/dist - const pathToAsset = `${PATH_TO_CLI}/dist/${operatingSystem === 'win' ? 'win32' : operatingSystem}`; + const pathToAsset = `${PATH_TO_CLI}/dist/${operatingSystem}`; + const pathToAssetWindows = operatingSystem === 'deb' ? `${PATH_TO_CLI}/dist/win32` : undefined; const files = fs.readdirSync(pathToAsset); @@ -103,6 +104,7 @@ async function main() { console.log('file in directory', file); const data = fs.readFileSync(pathToAsset + `/${file}`); console.log('data...', data); + // TODO debian has redundant packages. Only upload .deb files // const upload = await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}', { // ...base, // name: file, @@ -113,6 +115,16 @@ async function main() { // }); // console.log('Finished uploading asset', upload.status); } + if (pathToAssetWindows) { + // win is bundled on linux + const files = fs.readdirSync(pathToAssetWindows); + + for (const file of files) { + console.log('file in directory', file); + const data = fs.readFileSync(pathToAssetWindows + `/${file}`); + console.log('data from win32...', data); + } + } } main(); From 5f680fdcca3c0ef2a251e9ba15302edd923f5088 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 11:21:20 +0200 Subject: [PATCH 10/17] pack win --- scripts/release-cli.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/release-cli.ts b/scripts/release-cli.ts index e11f2e036..113490da6 100644 --- a/scripts/release-cli.ts +++ b/scripts/release-cli.ts @@ -117,6 +117,12 @@ async function main() { } if (pathToAssetWindows) { // win is bundled on linux + const pack = await exec(`pnpm oclif pack win`); + if (pack.stderr) { + throw new Error(`Failed to pack: ${pack.stderr}`); + } + console.log('Successfully packed CLI', pack.stdout); + const files = fs.readdirSync(pathToAssetWindows); for (const file of files) { From 8d2de3c5185f50cc4dcac7ef8b3b7bb35422acdf Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 11:30:50 +0200 Subject: [PATCH 11/17] try and bundle on ubuntu only --- .github/workflows/release.yml | 7 +-- scripts/release-cli.ts | 96 +++++++++++++++-------------------- 2 files changed, 41 insertions(+), 62 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 81ae53a4c..4bd183eda 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -70,10 +70,7 @@ jobs: release-cli-assets: name: Release CLI assets # needs: release - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} + runs-on: 'ubuntu-latest' steps: - uses: actions/checkout@v3 with: @@ -100,7 +97,6 @@ jobs: run: pnpm build - name: Install windows dependencies - if: matrix.os == 'ubuntu-latest' run: | sudo apt-get update sudo apt-get install -y nsis @@ -109,5 +105,4 @@ jobs: - name: Release CLI Assets run: pnpm run release:cli env: - MATRIX_OS: ${{ matrix.os }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/release-cli.ts b/scripts/release-cli.ts index 113490da6..712b893c9 100644 --- a/scripts/release-cli.ts +++ b/scripts/release-cli.ts @@ -21,24 +21,23 @@ const base = { } }; -const matrixToOclif = (os: string) => { - switch (os) { - case 'windows-latest': - return 'win'; - case 'macos-latest': - return 'macos'; - case 'ubuntu-latest': - return 'deb'; - default: - throw new Error('Unsupported OS'); - } -}; +// const matrixToOclif = (os: string) => { +// switch (os) { +// case 'windows-latest': +// return 'win'; +// case 'macos-latest': +// return 'macos'; +// case 'ubuntu-latest': +// return 'deb'; +// default: +// throw new Error('Unsupported OS'); +// } +// }; async function main() { - if (!process.env.MATRIX_OS) throw new Error('MATRIX_OS is not set'); if (!process.env.GITHUB_TOKEN) throw new Error('GITHUB_TOKEN is not set'); - const operatingSystem = matrixToOclif(process.env.MATRIX_OS); + const operatingSystems = ['deb', 'win', 'macos']; const { manifest, fileName } = await readProjectManifest(PATH_TO_CLI); const { @@ -75,11 +74,34 @@ async function main() { execFile('rm', ['-rf', `${PATH_TO_CLI}/npm-shrinkwrap.json`]); execFile('touch', [`${PATH_TO_CLI}/npm-shrinkwrap.json`]); - const pack = await exec(`pnpm oclif pack ${operatingSystem}`); - if (pack.stderr) { - throw new Error(`Failed to pack: ${pack.stderr}`); + for (const operatingSystem of operatingSystems) { + const build = await exec(`pnpm oclif build ${operatingSystem}`); + if (build.stderr) { + throw new Error(`Failed to build: ${build.stderr}`); + } + console.log('Successfully built CLI', build.stdout); + + // windows installer is saved in "win32" folder in cli/dist + const pathToAsset = `${PATH_TO_CLI}/dist/${operatingSystem === 'win' ? 'win32' : operatingSystem}`; + + const files = fs.readdirSync(pathToAsset); + + for (const file of files) { + console.log('file in directory', file); + const data = fs.readFileSync(pathToAsset + `/${file}`); + console.log('data...', data); + // TODO debian has redundant packages. Only upload .deb files + // const upload = await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}', { + // ...base, + // name: file, + // label: file, + // release_id: release.data.id, + // data: data, + // baseUrl: 'https://uploads.github.com' + // }); + // console.log('Finished uploading asset', upload.status); + } } - console.log('Successfully packed CLI', pack.stdout); // const octokit = new Octokit({ // auth: process.env.GITHUB_TOKEN @@ -93,44 +115,6 @@ async function main() { // }); // if (!release.data) throw new Error('Release not found'); - - // windows installer is saved in "win32" folder in cli/dist - const pathToAsset = `${PATH_TO_CLI}/dist/${operatingSystem}`; - const pathToAssetWindows = operatingSystem === 'deb' ? `${PATH_TO_CLI}/dist/win32` : undefined; - - const files = fs.readdirSync(pathToAsset); - - for (const file of files) { - console.log('file in directory', file); - const data = fs.readFileSync(pathToAsset + `/${file}`); - console.log('data...', data); - // TODO debian has redundant packages. Only upload .deb files - // const upload = await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}', { - // ...base, - // name: file, - // label: file, - // release_id: release.data.id, - // data: data, - // baseUrl: 'https://uploads.github.com' - // }); - // console.log('Finished uploading asset', upload.status); - } - if (pathToAssetWindows) { - // win is bundled on linux - const pack = await exec(`pnpm oclif pack win`); - if (pack.stderr) { - throw new Error(`Failed to pack: ${pack.stderr}`); - } - console.log('Successfully packed CLI', pack.stdout); - - const files = fs.readdirSync(pathToAssetWindows); - - for (const file of files) { - console.log('file in directory', file); - const data = fs.readFileSync(pathToAssetWindows + `/${file}`); - console.log('data from win32...', data); - } - } } main(); From 1d94eceadfedaac0d5f29c22ae909c7d62b5ecc9 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 11:32:51 +0200 Subject: [PATCH 12/17] correct command --- scripts/release-cli.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/scripts/release-cli.ts b/scripts/release-cli.ts index 712b893c9..4f2886175 100644 --- a/scripts/release-cli.ts +++ b/scripts/release-cli.ts @@ -21,19 +21,6 @@ const base = { } }; -// const matrixToOclif = (os: string) => { -// switch (os) { -// case 'windows-latest': -// return 'win'; -// case 'macos-latest': -// return 'macos'; -// case 'ubuntu-latest': -// return 'deb'; -// default: -// throw new Error('Unsupported OS'); -// } -// }; - async function main() { if (!process.env.GITHUB_TOKEN) throw new Error('GITHUB_TOKEN is not set'); @@ -75,7 +62,7 @@ async function main() { execFile('touch', [`${PATH_TO_CLI}/npm-shrinkwrap.json`]); for (const operatingSystem of operatingSystems) { - const build = await exec(`pnpm oclif build ${operatingSystem}`); + const build = await exec(`pnpm oclif pack ${operatingSystem}`); if (build.stderr) { throw new Error(`Failed to build: ${build.stderr}`); } From ed770b3ffe02fe2b8d3896160585fad9a9ce05f6 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 11:55:21 +0200 Subject: [PATCH 13/17] clean --- .github/workflows/release.yml | 126 ++++++++++++++++++---------------- scripts/release-cli.ts | 111 ++++++++++++++++++++---------- 2 files changed, 141 insertions(+), 96 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4bd183eda..3a3b553a4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,74 +3,76 @@ name: Release Test on: push: branches: - - feat/release-assets - # - main - # - next + - main + - next concurrency: ${{ github.workflow }}-${{ github.ref }} jobs: - # release: - # name: Release - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - # with: - # # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits - # fetch-depth: 0 - # # This makes the PR pushed to use GITHUB_TOKEN and trigger the checks - # persist-credentials: false - - # - name: Configure - # run: | - # git config user.email "system@xata.io" - # git config user.name "Xata" - # echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT - # echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc - # id: config - # env: - # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - # - name: Install pnpm - # uses: pnpm/action-setup@v2 - # with: - # version: 8 - - # - name: Use Node.js ${{ steps.config.outputs.NVMRC }} - # uses: actions/setup-node@v3 - # with: - # node-version: ${{ steps.config.outputs.NVMRC }} - # cache: 'pnpm' - - # - name: Install dependencies - # run: pnpm install --frozen-lockfile - - # - name: Build - # run: pnpm build - - # - name: Update next channel - # if: github.ref_name == 'next' - # env: - # GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} - # run: | - # npx changeset version - # npx changeset publish - - # - name: Create Release Pull Request or Publish to npm - # uses: changesets/action@v1 - # if: github.ref_name == 'main' - # with: - # title: Release tracking - # publish: npx changeset publish - # version: node ./scripts/changeset-version.mjs - # env: - # GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} - # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + release: + name: Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits + fetch-depth: 0 + # This makes the PR pushed to use GITHUB_TOKEN and trigger the checks + persist-credentials: false + + - name: Configure + run: | + git config user.email "system@xata.io" + git config user.name "Xata" + echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT + echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc + id: config + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Install pnpm + uses: pnpm/action-setup@v2 + with: + version: 8 + + - name: Use Node.js ${{ steps.config.outputs.NVMRC }} + uses: actions/setup-node@v3 + with: + node-version: ${{ steps.config.outputs.NVMRC }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build + run: pnpm build + + - name: Update next channel + if: github.ref_name == 'next' + env: + GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} + run: | + npx changeset version + npx changeset publish + + - name: Create Release Pull Request or Publish to npm + uses: changesets/action@v1 + if: github.ref_name == 'main' + with: + title: Release tracking + publish: npx changeset publish + version: node ./scripts/changeset-version.mjs + env: + GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} release-cli-assets: name: Release CLI assets - # needs: release - runs-on: 'ubuntu-latest' + needs: release + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 with: @@ -97,6 +99,7 @@ jobs: run: pnpm build - name: Install windows dependencies + if: matrix.os == 'ubuntu-latest' run: | sudo apt-get update sudo apt-get install -y nsis @@ -105,4 +108,5 @@ jobs: - name: Release CLI Assets run: pnpm run release:cli env: + MATRIX_OS: ${{ matrix.os }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/release-cli.ts b/scripts/release-cli.ts index 4f2886175..83a46ef4d 100644 --- a/scripts/release-cli.ts +++ b/scripts/release-cli.ts @@ -21,10 +21,22 @@ const base = { } }; +const matrixToOclif = (os: string) => { + switch (os) { + case 'macos-latest': + return 'macos'; + case 'ubuntu-latest': + return 'deb'; + default: + throw new Error('Unsupported OS'); + } +}; + async function main() { + if (!process.env.MATRIX_OS) throw new Error('MATRIX_OS is not set'); if (!process.env.GITHUB_TOKEN) throw new Error('GITHUB_TOKEN is not set'); - const operatingSystems = ['deb', 'win', 'macos']; + const operatingSystem = matrixToOclif(process.env.MATRIX_OS); const { manifest, fileName } = await readProjectManifest(PATH_TO_CLI); const { @@ -61,47 +73,76 @@ async function main() { execFile('rm', ['-rf', `${PATH_TO_CLI}/npm-shrinkwrap.json`]); execFile('touch', [`${PATH_TO_CLI}/npm-shrinkwrap.json`]); - for (const operatingSystem of operatingSystems) { - const build = await exec(`pnpm oclif pack ${operatingSystem}`); - if (build.stderr) { - throw new Error(`Failed to build: ${build.stderr}`); - } - console.log('Successfully built CLI', build.stdout); + await oclifPack({ os: operatingSystem }); + + const octokit = new Octokit({ + auth: process.env.GITHUB_TOKEN + }); + + const tag = encodeURIComponent(`@xata.io/cli@${manifest.version}`); + + const release = await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { + ...base, + tag + }); - // windows installer is saved in "win32" folder in cli/dist - const pathToAsset = `${PATH_TO_CLI}/dist/${operatingSystem === 'win' ? 'win32' : operatingSystem}`; + if (!release.data) throw new Error('Release not found'); - const files = fs.readdirSync(pathToAsset); + const pathToAsset = `${PATH_TO_CLI}/dist/${operatingSystem}`; + // Debian pack results in redundant files. Only upload .deb files + const files = fs + .readdirSync(pathToAsset) + .filter((file) => (operatingSystem === 'deb' ? file.endsWith('.deb') : true)); + for (const file of files) { + await uploadFiles({ pathToFile: pathToAsset + `/${file}`, fileName: file, octokit, releaseId: release.data.id }); + } + // Pack windows on linux + if (operatingSystem === 'deb') { + await oclifPack({ os: 'win' }); + // Windows packs files under "win32" directory + const pathToAssetWindows = `${PATH_TO_CLI}/dist/win32`; + const files = fs.readdirSync(pathToAssetWindows); for (const file of files) { - console.log('file in directory', file); - const data = fs.readFileSync(pathToAsset + `/${file}`); - console.log('data...', data); - // TODO debian has redundant packages. Only upload .deb files - // const upload = await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}', { - // ...base, - // name: file, - // label: file, - // release_id: release.data.id, - // data: data, - // baseUrl: 'https://uploads.github.com' - // }); - // console.log('Finished uploading asset', upload.status); + await uploadFiles({ + pathToFile: pathToAssetWindows + `/${file}`, + fileName: file, + octokit, + releaseId: release.data.id + }); } } +} - // const octokit = new Octokit({ - // auth: process.env.GITHUB_TOKEN - // }); - - // const tag = encodeURIComponent(`@xata.io/cli@${manifest.version}`); - - // const release = await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { - // ...base, - // tag - // }); +const oclifPack = async ({ os }: { os: 'win' | 'macos' | 'deb' }) => { + const pack = await exec(`pnpm oclif pack ${os}`); + if (pack.stderr) { + throw new Error(`Failed to pack: ${pack.stderr}`); + } + console.log('Successfully packed CLI', pack.stdout); +}; - // if (!release.data) throw new Error('Release not found'); -} +const uploadFiles = async ({ + pathToFile, + fileName, + octokit, + releaseId +}: { + pathToFile: string; + fileName: string; + octokit: Octokit; + releaseId: number; +}) => { + const data = fs.readFileSync(pathToFile); + const upload = await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}', { + ...base, + name: fileName, + label: fileName, + release_id: releaseId, + data: data, + baseUrl: 'https://uploads.github.com' + }); + console.log('Finished uploading asset', upload.status); +}; main(); From 3ab23da479b87739fa89247e668059a8f322d26a Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 17:10:51 +0200 Subject: [PATCH 14/17] reuseable workflow --- .github/workflows/release-cli-assets.yml | 52 ++++++++++++++++++++++++ .github/workflows/release.yml | 47 ++------------------- 2 files changed, 56 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/release-cli-assets.yml diff --git a/.github/workflows/release-cli-assets.yml b/.github/workflows/release-cli-assets.yml new file mode 100644 index 000000000..7d8ba2a0c --- /dev/null +++ b/.github/workflows/release-cli-assets.yml @@ -0,0 +1,52 @@ +name: Release CLI Assets + +on: + workflow_call: + secrets: + GITHUB_TOKEN: + required: true + +jobs: + release-cli-assets: + name: Release CLI assets + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + with: + # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits + fetch-depth: 0 + # This makes the PR pushed to use GITHUB_TOKEN and trigger the checks + persist-credentials: false + + - name: Install pnpm + uses: pnpm/action-setup@v2 + with: + version: 8 + + - name: Use Node.js ${{ steps.config.outputs.NVMRC }} + uses: actions/setup-node@v3 + with: + node-version: ${{ steps.config.outputs.NVMRC }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build + run: pnpm build + + - name: Install windows dependencies + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install -y nsis + sudo apt-get install -y p7zip + + - name: Release CLI Assets + run: pnpm run release:cli + env: + MATRIX_OS: ${{ matrix.os }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3a3b553a4..aee16bc89 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Release Test +name: Release on: push: @@ -67,46 +67,7 @@ jobs: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} release-cli-assets: - name: Release CLI assets needs: release - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v3 - with: - # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits - fetch-depth: 0 - # This makes the PR pushed to use GITHUB_TOKEN and trigger the checks - persist-credentials: false - - - name: Install pnpm - uses: pnpm/action-setup@v2 - with: - version: 8 - - - name: Use Node.js ${{ steps.config.outputs.NVMRC }} - uses: actions/setup-node@v3 - with: - node-version: ${{ steps.config.outputs.NVMRC }} - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install --frozen-lockfile - - - name: Build - run: pnpm build - - - name: Install windows dependencies - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get install -y nsis - sudo apt-get install -y p7zip - - - name: Release CLI Assets - run: pnpm run release:cli - env: - MATRIX_OS: ${{ matrix.os }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: ./.github/workflows/release-cli-assets.yml + secrets: + GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} From 58263f991a4791047e14f2175d57ebd7d2aa9466 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 25 Apr 2024 17:12:24 +0200 Subject: [PATCH 15/17] fix --- .github/workflows/release-cli-assets.yml | 3 --- .github/workflows/release.yml | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/release-cli-assets.yml b/.github/workflows/release-cli-assets.yml index 7d8ba2a0c..9536986bc 100644 --- a/.github/workflows/release-cli-assets.yml +++ b/.github/workflows/release-cli-assets.yml @@ -2,9 +2,6 @@ name: Release CLI Assets on: workflow_call: - secrets: - GITHUB_TOKEN: - required: true jobs: release-cli-assets: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index aee16bc89..117f19a74 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -69,5 +69,4 @@ jobs: release-cli-assets: needs: release uses: ./.github/workflows/release-cli-assets.yml - secrets: - GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} + secrets: inherit From 95b46da70ffff63c364b3487c841e7611bad83a4 Mon Sep 17 00:00:00 2001 From: Alexis Rico Date: Tue, 30 Apr 2024 10:11:12 +0200 Subject: [PATCH 16/17] Apply suggestions from code review --- cli/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/package.json b/cli/package.json index d2878752c..ba302e830 100644 --- a/cli/package.json +++ b/cli/package.json @@ -78,13 +78,13 @@ "init": "./dist/hooks/init/compatibility" }, "macos": { - "identifier": "com.xata.cli" + "identifier": "io.xata.cli" }, "deb": { - "identifier": "com.xata.cli" + "identifier": "io.xata.cli" }, "win": { - "identifier": "com.xata.cli" + "identifier": "io.xata.cli" }, "dirname": "xata", "commands": "./dist/commands", From 4d95e58d7cd841cff52e2a534ad43d47c3eedadb Mon Sep 17 00:00:00 2001 From: Alexis Rico Date: Tue, 30 Apr 2024 10:14:43 +0200 Subject: [PATCH 17/17] Move to step --- .github/workflows/release.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 117f19a74..a24f96be7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -57,6 +57,7 @@ jobs: - name: Create Release Pull Request or Publish to npm uses: changesets/action@v1 + id: changesets if: github.ref_name == 'main' with: title: Release tracking @@ -66,7 +67,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - release-cli-assets: - needs: release - uses: ./.github/workflows/release-cli-assets.yml - secrets: inherit + - name: Publish CLI assets + uses: ./.github/workflows/release-cli-assets.yml + if: steps.changesets.outputs.published == true