diff --git a/csv/format/BUILD b/csv/format/BUILD index bc63beba4a..1bb8bf6d7f 100644 --- a/csv/format/BUILD +++ b/csv/format/BUILD @@ -1 +1 @@ -# empty \ No newline at end of file +# empty diff --git a/csv/format/rules.bzl b/csv/format/rules.bzl index 325878cf5c..2ae5c7ffe4 100644 --- a/csv/format/rules.bzl +++ b/csv/format/rules.bzl @@ -1,18 +1,17 @@ - def csv_format(name, src = None, out = None, separator = ",", **kwargs): if out == None: out = src + "_formatted.csv" native.genrule( name = name, - exec_tools = [ "//go/cmd/csvpretty:csvpretty" ], + exec_tools = ["//go/cmd/csvpretty:csvpretty"], cmd_bash = """ $(execpath //go/cmd/csvpretty:csvpretty) \\ --input "$<" \\ --output "$@" \\ --comma \"""" + separator + """\" """, - outs = [ out ], - srcs = [ src ], + outs = [out], + srcs = [src], **kwargs - ) \ No newline at end of file + ) diff --git a/csv/lint/rules.bzl b/csv/lint/rules.bzl index 83d5c4f4e8..e61604c26d 100644 --- a/csv/lint/rules.bzl +++ b/csv/lint/rules.bzl @@ -14,9 +14,8 @@ def csv_lint_test(name, srcs = [], **kwargs): file1 = name + src + "_format", file2 = src, ) - + native.test_suite( name = name, - tests = [name + src + "_test" for src in srcs ] + tests = [name + src + "_test" for src in srcs], ) - diff --git a/csv/lint/testing/BUILD b/csv/lint/testing/BUILD index f7860d0cd0..98a7f6a7c0 100644 --- a/csv/lint/testing/BUILD +++ b/csv/lint/testing/BUILD @@ -2,5 +2,5 @@ load("//csv/lint:rules.bzl", "csv_lint_test") csv_lint_test( name = "test", - srcs = [ "test_out.csv" ] -) \ No newline at end of file + srcs = ["test_out.csv"], +) diff --git a/deploy/deploy_test.ts b/deploy/deploy_test.ts index 8b9589bb44..ce19bc8c60 100644 --- a/deploy/deploy_test.ts +++ b/deploy/deploy_test.ts @@ -2,5 +2,5 @@ import program from './program'; test('deploy', async () => { process.env.NPM_TOKEN = '123fake'; - await program.parseAsync(['--dryRun', 'true']); + await program.parseAsync(['xxx', 'ok', '--dryRun', 'true']); }); diff --git a/deploy/program.ts b/deploy/program.ts index a63ff2e677..728e4d7ccd 100644 --- a/deploy/program.ts +++ b/deploy/program.ts @@ -20,20 +20,22 @@ interface ArtifactInfo { kind: 'artifact'; filename: string; buildTag: string; - published: Promise; + publish: (c: Context) => Promise; } const artifact = - (filename: string, buildTag: string) => - async ({ publish }: Context): Promise => { + (filename: string, buildTag: string) => async (): Promise => { return { kind: 'artifact', filename, buildTag, - published: publish( - filename, - await fs.readFile(runfiles.resolveWorkspaceRelative(buildTag)) - ), + publish: async ({ publish }: Context) => + publish( + filename, + await fs.readFile( + runfiles.resolveWorkspaceRelative(buildTag) + ) + ), }; }; @@ -41,27 +43,29 @@ interface NpmPackageInfo { kind: 'npm_publication'; package_name: string; buildTag: string; - published: Promise; + publish: (c: Context) => Promise; } const npmPackage = (packageName: string, buildTag: string) => - async ({ exec }: Context): Promise => { - if (!('NPM_TOKEN' in process.env)) - throw new Error( - "Missing NPM_TOKEN. We won't be able to publish any NPM packages." - ); + async (): Promise => { return { buildTag, kind: 'npm_publication', package_name: packageName, - published: exec(runfiles.resolveWorkspaceRelative(buildTag)), + async publish({ exec }: Context) { + if (!('NPM_TOKEN' in process.env)) + throw new Error( + "Missing NPM_TOKEN. We won't be able to publish any NPM packages." + ); + exec(runfiles.resolveWorkspaceRelative(buildTag)); + }, }; }; -interface ReleaseProps { +interface ReleaseProps { dryRun: boolean; - releaseNotes: (items: T[]) => string; + releaseNotes: (items: (ArtifactInfo | NpmPackageInfo)[]) => string; createRelease(data: { body: string }): Promise<{ release_id: number }>; uploadReleaseAsset(data: { release_id: number; @@ -71,30 +75,29 @@ interface ReleaseProps { } const release = - }>( - ...fns: ((c: Context) => Promise)[] - ) => + (...fns: (() => Promise)[]) => async ({ dryRun, createRelease, releaseNotes, uploadReleaseAsset, - }: ReleaseProps) => { - let set_release_id: ((release_id: number) => void) | undefined; - const release_id = new Promise(ok => (set_release_id = ok)); - - const publish: Context['publish'] = dryRun - ? async (filename: string, content: Buffer) => { - if (!filename) throw new Error('Empty filename.'); - if (content.length == 0) - throw new Error(`Empty content for ${filename}`); - } - : async (file: string, content: Buffer) => - uploadReleaseAsset({ - release_id: await release_id, - name: file, - data: content, - }); + }: ReleaseProps) => { + const logInfo = await Promise.all(fns.map(f => f())); + + const { release_id } = await createRelease({ + body: releaseNotes(logInfo), + }); + + const publish: Context['publish'] = async ( + file: string, + content: Buffer + ) => + uploadReleaseAsset({ + release_id, + name: file, + data: content, + }); + const exec: Context['exec'] = dryRun ? async (filename: string) => { if (filename == '') @@ -103,17 +106,9 @@ const release = : async (filename: string) => void (await promisify(child_process.execFile)(filename)); - const logInfo = await Promise.all(fns.map(f => f({ publish, exec }))); - - const { release_id: concreteReleaseId } = await createRelease({ - body: releaseNotes(logInfo), - }); - - if (!set_release_id) throw new Error(); - - set_release_id(concreteReleaseId); - - await Promise.all(logInfo.map(itm => itm.published)); + await Promise.all( + logInfo.map(({ publish: p }) => p({ publish, exec })) + ); }; export const program = Program.name('release') @@ -130,17 +125,17 @@ export const program = Program.name('release') ? getOctokit(process.env['GITHUB_TOKEN']!) : undefined; - const releaser = release( + const releaser = release( artifact( 'recursive_vassals.zip', - 'project/ck3/recursive-vassals/mod_zip.zip' + '//project/ck3/recursive-vassals/mod_zip.zip' ), artifact( 'recursive_vassals.patch', '//project/ck3/recursive-vassals/mod.patch' ), - artifact('svgshot.tar.gz', 'ts/cmd/svgshot/svgshot.tgz'), - npmPackage('svgshot', 'ts/cmd/svgshot/npm_pkg.publish.sh') + artifact('svgshot.tar.gz', '//ts/cmd/svgshot/svgshot.tgz'), + npmPackage('svgshot', '//ts/cmd/svgshot/npm_pkg.publish.sh') ); releaser({ @@ -160,57 +155,68 @@ export const program = Program.name('release') if (!data) throw new Error('data is empty'); }, - createRelease: Github - ? async ({ body }) => ({ - release_id: ( - await Github.rest.repos.createRelease({ - // could probably use a spread operator here - // but i also think that would be uglier... - owner: context.repo.owner, - repo: context.repo.repo, - - tag_name: syntheticVersion, - - body, - - generate_release_notes: true, - - name: syntheticVersion, - - target_commitish: context.ref, - }) - ).data.id, - }) - : async ({ body }) => { - if (body === '') - throw new Error('Release body is empty.'); - return { release_id: 0 }; - }, + createRelease: + Github !== undefined + ? async ({ body }) => ({ + release_id: ( + await Github.rest.repos.createRelease({ + // could probably use a spread operator here + // but i also think that would be uglier... + owner: context.repo.owner, + repo: context.repo.repo, + + tag_name: syntheticVersion, + + body, + + generate_release_notes: true, + + name: syntheticVersion, + + target_commitish: context.ref, + }) + ).data.id, + }) + : async ({ body }) => { + if (body === '') + throw new Error(`Release body is empty.`); + return { release_id: 0 }; + }, dryRun: dryRun, releaseNotes: (notes: (NpmPackageInfo | ArtifactInfo)[]) => { const artifacts: ArtifactInfo[] = []; const npmPackages: NpmPackageInfo[] = []; for (const note of notes) { - if (note.kind === 'artifact') artifacts.push(note); - if (note.kind === 'npm_publication') npmPackages.push(note); - throw new Error(); + if (note.kind === 'artifact') { + artifacts.push(note); + continue; + } + if (note.kind === 'npm_publication') { + npmPackages.push(note); + continue; + } + throw new Error(`Unknown kind ${(note as any).kind}`); } return `${ artifacts.length - ? `This release contains the following artifacts:\n ${artifacts.map( - artifact => - ` - ${artifact.buildTag} → ${artifact.filename}` - )}` + ? `This release contains the following artifacts:\n ${artifacts + .map( + artifact => + ` - ${artifact.buildTag} → ${artifact.filename}` + ) + .join('\n')}` : '' } ${ npmPackages.length - ? `This release contains the following NPM packages:\n: ${npmPackages.map( - pkg => - ` - ${pkg.buildTag} → [${pkg.package_name}](https://npmjs.com/package/svgshot)` - )}` + ? `This release contains the following NPM packages:\n ${npmPackages + .map( + pkg => + ` - ${pkg.buildTag} → [${pkg.package_name}](https://npmjs.com/package/svgshot)` + ) + .join('\n')}` : '' } `;