-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sergey Tatarintsev
committed
Apr 29, 2024
1 parent
3d2d757
commit 321ad6e
Showing
7 changed files
with
237 additions
and
2,423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Update client and publish a new version | ||
on: | ||
pull_request: | ||
# TODO: cron | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: 'publish' | ||
|
||
jobs: | ||
check-update: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
latest: ${{ steps.check-update.outputs.latest }} | ||
dev: ${{ steps.check-update.outputs.dev }} | ||
integration: ${{ steps.check-update.outputs.dev }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup | ||
uses: ./.github/actions/setup | ||
|
||
- name: Check for updates | ||
id: check-update | ||
run: yarn check-update | ||
|
||
test-publish: | ||
runs-on: ubuntu-latest | ||
|
||
needs: | ||
- check-update | ||
steps: | ||
- name: Update and publish latest | ||
if: ${{ needs.check-update.outputs.latest != ''}} | ||
run: echo "Latest" | ||
- name: Update and publish dev | ||
if: ${{ needs.check-update.outputs.dev != ''}} | ||
run: echo "Latest" | ||
- name: Update and publish integration | ||
if: ${{ needs.check-update.outputs.integration != ''}} | ||
run: echo "Latest" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { $ } from 'zx'; | ||
import pRetry from 'p-retry'; | ||
import { downloadEngine, ensureNpmTag, writeVersionFile } from './utils'; | ||
|
||
async function main() { | ||
const version = process.argv[2]; | ||
const tag = process.argv[2]; | ||
ensureNpmTag(tag); | ||
const version = process.argv[3]; | ||
if (!version) { | ||
console.error(`Usage: bump-engines <version>`); | ||
console.error(`Usage: bump-engines <tag> <version>`); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
await $`yarn up prisma@${version} @prisma/client@${version}`; | ||
const enginesVersion = require('@prisma/engines-version').enginesVersion; | ||
|
||
await fs.writeFile( | ||
path.resolve(__dirname, '..', '.versions', 'engine'), | ||
enginesVersion | ||
); | ||
|
||
// await $`git add -A`; | ||
// await $`git commit -m "Bump client to ${version}"`; | ||
await writeVersionFile('engine', enginesVersion); | ||
await writeVersionFile(`prisma-${tag}`, version); | ||
// downloading updated engine | ||
await downloadEngine(); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import fs from 'node:fs/promises'; | ||
import { $ } from 'zx'; | ||
import pRetry from 'p-retry'; | ||
Check warning on line 3 in scripts/check-updates.ts GitHub Actions / Lint
|
||
import { NPM_TAGS, type NpmTag, readVersionFile } from './utils'; | ||
|
||
async function main() { | ||
for (let tag of NPM_TAGS) { | ||
await checkUpdate(tag); | ||
} | ||
} | ||
|
||
async function checkUpdate(tag: NpmTag) { | ||
console.log(`Checking update for npm tag: ${tag}`); | ||
const currentVersion = await readVersionFile(`prisma-${tag}`); | ||
const npmVersion = await getNpmVersion(tag); | ||
console.log(`Current version ${currentVersion}`); | ||
console.log(`npm version ${npmVersion}`); | ||
if (currentVersion !== npmVersion) { | ||
console.log('Update needed'); | ||
const ghOut = process.env.GITHUB_OUT; | ||
if (ghOut) { | ||
await fs.appendFile(ghOut, `${tag}=${npmVersion}\n`); | ||
} | ||
} else { | ||
console.log('Up to date'); | ||
} | ||
} | ||
|
||
async function getNpmVersion(tag: NpmTag) { | ||
const content = await pRetry( | ||
() => $`yarn npm info prisma@${tag} --json -f version`, | ||
{ | ||
retries: 3, | ||
} | ||
); | ||
|
||
const parsed = JSON.parse(content.stdout); | ||
if (typeof parsed?.version !== 'string') { | ||
throw new Error(`Can not get npm version for prisma@${tag}`); | ||
} | ||
return parsed.version; | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,3 @@ | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { pipeline } from 'node:stream/promises'; | ||
import { Extract } from 'unzipper'; | ||
import { downloadEngine } from './utils'; | ||
|
||
async function main() { | ||
const version = await fs.readFile( | ||
path.resolve(__dirname, '..', '.versions', 'engine'), | ||
'utf8' | ||
); | ||
|
||
console.log(`Downloading engine ${version}`); | ||
|
||
const url = `https://binaries.prisma.sh/all_commits/${version}/react-native/binaries.zip`; | ||
|
||
console.log(url); | ||
|
||
const resp = await fetch(url); | ||
if (!resp.body) { | ||
throw new Error('Failed to read the response from binaries server'); | ||
} | ||
await pipeline( | ||
resp.body, | ||
Extract({ path: path.resolve(__dirname, '..', 'engines') }) | ||
); | ||
|
||
console.log('Download complete'); | ||
} | ||
|
||
main(); | ||
downloadEngine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { pipeline } from 'node:stream/promises'; | ||
import { Extract } from 'unzipper'; | ||
|
||
export const NPM_TAGS = ['dev', 'latest', 'integration'] as const; | ||
|
||
type VersionFile = | ||
| 'prisma-dev' | ||
| 'prisma-integration' | ||
| 'prisma-latest' | ||
| 'engine'; | ||
|
||
export type NpmTag = (typeof NPM_TAGS)[number]; | ||
|
||
export function ensureNpmTag(str: string): asserts str is NpmTag { | ||
if (!(NPM_TAGS as readonly string[]).includes(str)) { | ||
throw new Error(`${str} is not supported npm tag`); | ||
} | ||
} | ||
|
||
export function readVersionFile(file: VersionFile): Promise<string> { | ||
return fs.readFile(versionFilePath(file), 'utf8'); | ||
} | ||
|
||
export function writeVersionFile( | ||
file: VersionFile, | ||
version: string | ||
): Promise<void> { | ||
return fs.writeFile(versionFilePath(file), version); | ||
} | ||
|
||
export async function downloadEngine() { | ||
const version = await readVersionFile('engine'); | ||
|
||
console.log(`Downloading engine ${version}`); | ||
|
||
const url = `https://binaries.prisma.sh/all_commits/${version}/react-native/binaries.zip`; | ||
|
||
const resp = await fetch(url); | ||
if (!resp.body) { | ||
throw new Error('Failed to read the response from binaries server'); | ||
} | ||
await pipeline( | ||
resp.body, | ||
Extract({ path: path.resolve(__dirname, '..', 'engines') }) | ||
); | ||
|
||
console.log('Download complete'); | ||
} | ||
function versionFilePath(file: VersionFile): string { | ||
return path.resolve(__dirname, '..', '.versions', file); | ||
} |
Oops, something went wrong.