From 5cd60fa66044dd5dae54d8e85431d6de78867ad6 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Sun, 1 Oct 2023 08:55:33 +0300 Subject: [PATCH 1/6] make it compatible with Dagger Zenith --- dagger.json | 5 ++ deno.json | 4 +- deno.lock | 78 +++++++++++++++++++++++- deps.ts | 21 ++++++- gen/nexus.ts | 135 +++++++++++++++++++++++++++++++++++++++++ mod.ts | 2 + schema.graphql | 7 +++ src/dagger/dagger.ts | 9 +++ src/dagger/jobs.ts | 23 ++++--- src/dagger/pipeline.ts | 18 +++--- src/dagger/queries.ts | 7 +++ src/dagger/schema.ts | 31 ++++++++++ 12 files changed, 312 insertions(+), 28 deletions(-) create mode 100644 dagger.json create mode 100644 gen/nexus.ts create mode 100644 schema.graphql create mode 100644 src/dagger/dagger.ts create mode 100644 src/dagger/queries.ts create mode 100644 src/dagger/schema.ts diff --git a/dagger.json b/dagger.json new file mode 100644 index 0000000..7fdff41 --- /dev/null +++ b/dagger.json @@ -0,0 +1,5 @@ +{ + "root": "", + "name": "codecov", + "sdk": "deno" +} \ No newline at end of file diff --git a/deno.json b/deno.json index 9f6bbca..807146b 100644 --- a/deno.json +++ b/deno.json @@ -3,6 +3,8 @@ "tasks": { "esm:add": "deno run -A https://esm.sh/v128 add", "esm:update": "deno run -A https://esm.sh/v128 update", - "esm:remove": "deno run -A https://esm.sh/v128 remove" + "esm:remove": "deno run -A https://esm.sh/v128 remove", + "schema": "deno run -A src/dagger/schema.ts", + "clean": "rm -rf gen schema.graphql" } } \ No newline at end of file diff --git a/deno.lock b/deno.lock index 2b47a36..c20ee47 100644 --- a/deno.lock +++ b/deno.lock @@ -1,5 +1,32 @@ { - "version": "2", + "version": "3", + "packages": { + "specifiers": { + "npm:nexus": "npm:nexus@1.3.0_graphql@16.8.1" + }, + "npm": { + "graphql@16.8.1": { + "integrity": "sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==", + "dependencies": {} + }, + "iterall@1.3.0": { + "integrity": "sha512-QZ9qOMdF+QLHxy1QIpUHUU1D5pS2CG2P69LF6L6CPjPYA/XMOmKV3PZpawHoAjHNyB0swdVTRxdYT4tbBbxqwg==", + "dependencies": {} + }, + "nexus@1.3.0_graphql@16.8.1": { + "integrity": "sha512-w/s19OiNOs0LrtP7pBmD9/FqJHvZLmCipVRt6v1PM8cRUYIbhEswyNKGHVoC4eHZGPSnD+bOf5A3+gnbt0A5/A==", + "dependencies": { + "graphql": "graphql@16.8.1", + "iterall": "iterall@1.3.0", + "tslib": "tslib@2.6.2" + } + }, + "tslib@2.6.2": { + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "dependencies": {} + } + } + }, "remote": { "https://cdn.jsdelivr.net/gh/tsirysndr/tar@v0.1.1/deps.ts": "096395daebc7ed8a18f0484e4ffcc3a7f70e50946735f7df9611a7fcfd8272cc", "https://cdn.jsdelivr.net/gh/tsirysndr/tar@v0.1.1/mod.ts": "e269d71c72ae68e82c1960e5db2a0c7419c97c9683ef717de0ab75d90f364713", @@ -84,6 +111,44 @@ "https://deno.land/std@0.191.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", "https://deno.land/std@0.191.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", "https://deno.land/std@0.191.0/testing/asserts.ts": "e16d98b4d73ffc4ed498d717307a12500ae4f2cbe668f1a215632d19fcffc22f", + "https://deno.land/std@0.203.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", + "https://deno.land/std@0.203.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", + "https://deno.land/std@0.203.0/path/_basename.ts": "057d420c9049821f983f784fd87fa73ac471901fb628920b67972b0f44319343", + "https://deno.land/std@0.203.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", + "https://deno.land/std@0.203.0/path/_dirname.ts": "355e297236b2218600aee7a5301b937204c62e12da9db4b0b044993d9e658395", + "https://deno.land/std@0.203.0/path/_extname.ts": "eaaa5aae1acf1f03254d681bd6a8ce42a9cb5b7ff2213a9d4740e8ab31283664", + "https://deno.land/std@0.203.0/path/_format.ts": "4a99270d6810f082e614309164fad75d6f1a483b68eed97c830a506cc589f8b4", + "https://deno.land/std@0.203.0/path/_from_file_url.ts": "6eadfae2e6f63ad9ee46b26db4a1b16583055c0392acedfb50ed2fc694b6f581", + "https://deno.land/std@0.203.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b", + "https://deno.land/std@0.203.0/path/_is_absolute.ts": "05dac10b5e93c63198b92e3687baa2be178df5321c527dc555266c0f4f51558c", + "https://deno.land/std@0.203.0/path/_join.ts": "815f5e85b042285175b1492dd5781240ce126c23bd97bad6b8211fe7129c538e", + "https://deno.land/std@0.203.0/path/_normalize.ts": "a19ec8706b2707f9dd974662a5cd89fad438e62ab1857e08b314a8eb49a34d81", + "https://deno.land/std@0.203.0/path/_os.ts": "30b0c2875f360c9296dbe6b7f2d528f0f9c741cecad2e97f803f5219e91b40a2", + "https://deno.land/std@0.203.0/path/_parse.ts": "0f9b0ff43682dd9964eb1c4398610c4e165d8db9d3ac9d594220217adf480cfa", + "https://deno.land/std@0.203.0/path/_relative.ts": "27bdeffb5311a47d85be26d37ad1969979359f7636c5cd9fcf05dcd0d5099dc5", + "https://deno.land/std@0.203.0/path/_resolve.ts": "7a3616f1093735ed327e758313b79c3c04ea921808ca5f19ddf240cb68d0adf6", + "https://deno.land/std@0.203.0/path/_to_file_url.ts": "a141e4a525303e1a3a0c0571fd024552b5f3553a2af7d75d1ff3a503dcbb66d8", + "https://deno.land/std@0.203.0/path/_to_namespaced_path.ts": "0d5f4caa2ed98ef7a8786286df6af804b50e38859ae897b5b5b4c8c5930a75c8", + "https://deno.land/std@0.203.0/path/_util.ts": "4e191b1bac6b3bf0c31aab42e5ca2e01a86ab5a0d2e08b75acf8585047a86221", + "https://deno.land/std@0.203.0/path/basename.ts": "bdfa5a624c6a45564dc6758ef2077f2822978a6dbe77b0a3514f7d1f81362930", + "https://deno.land/std@0.203.0/path/common.ts": "ee7505ab01fd22de3963b64e46cff31f40de34f9f8de1fff6a1bd2fe79380000", + "https://deno.land/std@0.203.0/path/dirname.ts": "b6533f4ee4174a526dec50c279534df5345836dfdc15318400b08c62a62a39dd", + "https://deno.land/std@0.203.0/path/extname.ts": "62c4b376300795342fe1e4746c0de518b4dc9c4b0b4617bfee62a2973a9555cf", + "https://deno.land/std@0.203.0/path/format.ts": "110270b238514dd68455a4c54956215a1aff7e37e22e4427b7771cefe1920aa5", + "https://deno.land/std@0.203.0/path/from_file_url.ts": "9f5cb58d58be14c775ec2e57fc70029ac8b17ed3bd7fe93e475b07280adde0ac", + "https://deno.land/std@0.203.0/path/glob.ts": "593e2c3573883225c25c5a21aaa8e9382a696b8e175ea20a3b6a1471ad17aaed", + "https://deno.land/std@0.203.0/path/is_absolute.ts": "0b92eb35a0a8780e9f16f16bb23655b67dace6a8e0d92d42039e518ee38103c1", + "https://deno.land/std@0.203.0/path/join.ts": "31c5419f23d91655b08ec7aec403f4e4cd1a63d39e28f6e42642ea207c2734f8", + "https://deno.land/std@0.203.0/path/mod.ts": "6e1efb0b13121463aedb53ea51dabf5639a3172ab58c89900bbb72b486872532", + "https://deno.land/std@0.203.0/path/normalize.ts": "6ea523e0040979dd7ae2f1be5bf2083941881a252554c0f32566a18b03021955", + "https://deno.land/std@0.203.0/path/parse.ts": "be8de342bb9e1924d78dc4d93c45215c152db7bf738ec32475560424b119b394", + "https://deno.land/std@0.203.0/path/posix.ts": "0a1c1952d132323a88736d03e92bd236f3ed5f9f079e5823fae07c8d978ee61b", + "https://deno.land/std@0.203.0/path/relative.ts": "8bedac226afd360afc45d451a6c29fabceaf32978526bcb38e0c852661f66c61", + "https://deno.land/std@0.203.0/path/resolve.ts": "133161e4949fc97f9ca67988d51376b0f5eef8968a6372325ab84d39d30b80dc", + "https://deno.land/std@0.203.0/path/separator.ts": "40a3e9a4ad10bef23bc2cd6c610291b6c502a06237c2c4cd034a15ca78dedc1f", + "https://deno.land/std@0.203.0/path/to_file_url.ts": "00e6322373dd51ad109956b775e4e72e5f9fa68ce2c6b04e4af2a6eed3825d31", + "https://deno.land/std@0.203.0/path/to_namespaced_path.ts": "1b1db3055c343ab389901adfbda34e82b7386bcd1c744d54f9c1496ee0fd0c3d", + "https://deno.land/std@0.203.0/path/win32.ts": "8b3f80ef7a462511d5e8020ff490edcaa0a0d118f1b1e9da50e2916bdd73f9dd", "https://deno.land/std@0.52.0/fmt/colors.ts": "ec9d653672a9a3c7b6eafe53c5bc797364a2db2dcf766ab649c1155fea7a80b2", "https://deno.land/x/crc32@v0.2.0/mod.ts": "de7a3fa2d4ef24b96fc21e1cc4d2d65d1d2b1dcea92f63960e3e11bfa82df0fa", "https://deno.land/x/fluent_aws_codepipeline@v0.2.3/mod.ts": "79cc758901d20a3573d7e3cc2db9f0a5fe56833f4d9befcedc072b94d542eec7", @@ -127,6 +192,7 @@ "https://deno.land/x/zod@v3.22.1/mod.ts": "64e55237cb4410e17d968cd08975566059f27638ebb0b86048031b987ba251c4", "https://deno.land/x/zod@v3.22.1/types.ts": "4edc1823385f446532c8c9f676d84550c6dc54b17135e34508576647d9612d0e", "https://esm.sh/@dagger.io/dagger@0.8.4": "424bddc1457c1fc4975c978425730be068b5414e92dca7a64f2d80e2123c4719", + "https://esm.sh/graphql-tag@2.12.6": "2d8f017bc251d9e7346bafc3f3aef4b65f7fdc302c6e0d085e3359f44c893068", "https://esm.sh/nanoid@4.0.2": "df5af492771eb7ed903cec5e5d8ff721bc75e6c09ddf9fc9263215c8497961f4", "https://esm.sh/stringify-tree@1.1.1": "a0515b0f4fe97a6972047a588b7982592d9079e7aeac3323b0d26448a757cf84", "https://esm.sh/v128/cross-fetch@3.1.8/denonext/cross-fetch.mjs": "8fba9e7c3fbaf0d2168beb63ce0cd21b5bfbfbd77e2fcbf8d957d533a71222f6", @@ -180,11 +246,19 @@ "https://esm.sh/yaml@v2.3.1": "5471fa3592a8a9d1a4a3d8cacf54070b01aedaca82f14fdbbdd056a491db00ec", "https://nix.fluentci.io/v0.5.1/deps.ts": "d2fee07fcb79b609f64f988990ad5d67c7bf17455f75dcbf1b3bbfa5de7c73b2", "https://nix.fluentci.io/v0.5.1/src/dagger/steps.ts": "b766f4fa9624a032e7af884a5ca47bc666a529c4a472d38b74b55ca0d63cf81d", + "https://nix.fluentci.io/zenith/deps.ts": "a8fd3aa32faea5de2779cc6494471b4fd9588f039d199ff1a1ff1b00343aef26", + "https://nix.fluentci.io/zenith/src/dagger/steps.ts": "b766f4fa9624a032e7af884a5ca47bc666a529c4a472d38b74b55ca0d63cf81d", "https://sdk.fluentci.io/v0.1.9/deps.ts": "1b036b7614a602b11e062a6911f26a6e2ac4e470cc74ac230125afd466cc77ea", "https://sdk.fluentci.io/v0.1.9/mod.ts": "a3c03bdb97c5a3b998c7c9f616c7b00d4268013c3b16e8a90c1a36a85529d841", "https://sdk.fluentci.io/v0.1.9/src/client.ts": "a8dd54861feccd11a53df39b2d45bfb3b2a8a3dff509f5700c41b517d4dff44d", "https://sdk.fluentci.io/v0.1.9/src/connect.ts": "1bb42b4e0c5073bb2125b90f1d7d08a66fcad9ad8c453924b944be72d3a56c98", "https://sdk.fluentci.io/v0.1.9/src/context.ts": "2939ff58d0a79d7377d5553e725c9a2110a0013035a5a57abe9a9a5da975c4ce", - "https://sdk.fluentci.io/v0.1.9/src/utils.ts": "394d131cfd465f0f3d8f876237f3bad1ab4dba73b9b7a396ee705d02aee40c16" + "https://sdk.fluentci.io/v0.1.9/src/utils.ts": "394d131cfd465f0f3d8f876237f3bad1ab4dba73b9b7a396ee705d02aee40c16", + "https://sdk.fluentci.io/z1/deps.ts": "1b036b7614a602b11e062a6911f26a6e2ac4e470cc74ac230125afd466cc77ea", + "https://sdk.fluentci.io/z1/mod.ts": "261ba81a4728f5def4e327a5cd80664ea8449515a2f4eea5f3f416acae39a1fa", + "https://sdk.fluentci.io/z1/src/client.ts": "dde6d20c41df43e5bb7763782eb3702a8d830a827444d1fb388fc574b2e6a64c", + "https://sdk.fluentci.io/z1/src/connect.ts": "4aff111c403cf78672384a10214a9885e08319dde579ec458f98a7bb04874101", + "https://sdk.fluentci.io/z1/src/context.ts": "2939ff58d0a79d7377d5553e725c9a2110a0013035a5a57abe9a9a5da975c4ce", + "https://sdk.fluentci.io/z1/src/utils.ts": "5dcd6d83553930502069d067ff42bc44698e22c23426fdb78630c4b39769d308" } } diff --git a/deps.ts b/deps.ts index 63ef493..4a9e5f6 100644 --- a/deps.ts +++ b/deps.ts @@ -1,11 +1,26 @@ export { assertEquals } from "https://deno.land/std@0.191.0/testing/asserts.ts"; -import Client from "https://sdk.fluentci.io/v0.1.9/mod.ts"; +import Client from "https://sdk.fluentci.io/z1/mod.ts"; export default Client; -export { connect, uploadContext } from "https://sdk.fluentci.io/v0.1.9/mod.ts"; +export { connect, uploadContext } from "https://sdk.fluentci.io/z1/mod.ts"; export { brightGreen } from "https://deno.land/std@0.191.0/fmt/colors.ts"; -export { withDevbox } from "https://nix.fluentci.io/v0.5.1/src/dagger/steps.ts"; +export { withDevbox } from "https://nix.fluentci.io/zenith/src/dagger/steps.ts"; export { stringifyTree } from "https://esm.sh/stringify-tree@1.1.1"; +import gql from "https://esm.sh/graphql-tag@2.12.6"; +export { gql }; +export { + arg, + queryType, + stringArg, + intArg, + nonNull, + makeSchema, +} from "npm:nexus"; +export { + dirname, + join, + resolve, +} from "https://deno.land/std@0.203.0/path/mod.ts"; export * as FluentGitlabCI from "https://deno.land/x/fluent_gitlab_ci@v0.4.2/mod.ts"; export * as FluentGithubActions from "https://deno.land/x/fluent_github_actions@v0.2.1/mod.ts"; diff --git a/gen/nexus.ts b/gen/nexus.ts new file mode 100644 index 0000000..2e9b642 --- /dev/null +++ b/gen/nexus.ts @@ -0,0 +1,135 @@ +/** + * This file was generated by Nexus Schema + * Do not make changes to this file directly + */ + + + + + + + +declare global { + interface NexusGen extends NexusGenTypes {} +} + +export interface NexusGenInputs { +} + +export interface NexusGenEnums { +} + +export interface NexusGenScalars { + String: string + Int: number + Float: number + Boolean: boolean + ID: string +} + +export interface NexusGenObjects { + Query: {}; +} + +export interface NexusGenInterfaces { +} + +export interface NexusGenUnions { +} + +export type NexusGenRootTypes = NexusGenObjects + +export type NexusGenAllTypes = NexusGenRootTypes & NexusGenScalars + +export interface NexusGenFieldTypes { + Query: { // field return type + upload: string | null; // String + } +} + +export interface NexusGenFieldTypeNames { + Query: { // field return type name + upload: 'String' + } +} + +export interface NexusGenArgTypes { + Query: { + upload: { // args + src: string; // String! + token: string; // String! + } + } +} + +export interface NexusGenAbstractTypeMembers { +} + +export interface NexusGenTypeInterfaces { +} + +export type NexusGenObjectNames = keyof NexusGenObjects; + +export type NexusGenInputNames = never; + +export type NexusGenEnumNames = never; + +export type NexusGenInterfaceNames = never; + +export type NexusGenScalarNames = keyof NexusGenScalars; + +export type NexusGenUnionNames = never; + +export type NexusGenObjectsUsingAbstractStrategyIsTypeOf = never; + +export type NexusGenAbstractsUsingStrategyResolveType = never; + +export type NexusGenFeaturesConfig = { + abstractTypeStrategies: { + isTypeOf: false + resolveType: true + __typename: false + } +} + +export interface NexusGenTypes { + context: any; + inputTypes: NexusGenInputs; + rootTypes: NexusGenRootTypes; + inputTypeShapes: NexusGenInputs & NexusGenEnums & NexusGenScalars; + argTypes: NexusGenArgTypes; + fieldTypes: NexusGenFieldTypes; + fieldTypeNames: NexusGenFieldTypeNames; + allTypes: NexusGenAllTypes; + typeInterfaces: NexusGenTypeInterfaces; + objectNames: NexusGenObjectNames; + inputNames: NexusGenInputNames; + enumNames: NexusGenEnumNames; + interfaceNames: NexusGenInterfaceNames; + scalarNames: NexusGenScalarNames; + unionNames: NexusGenUnionNames; + allInputTypes: NexusGenTypes['inputNames'] | NexusGenTypes['enumNames'] | NexusGenTypes['scalarNames']; + allOutputTypes: NexusGenTypes['objectNames'] | NexusGenTypes['enumNames'] | NexusGenTypes['unionNames'] | NexusGenTypes['interfaceNames'] | NexusGenTypes['scalarNames']; + allNamedTypes: NexusGenTypes['allInputTypes'] | NexusGenTypes['allOutputTypes'] + abstractTypes: NexusGenTypes['interfaceNames'] | NexusGenTypes['unionNames']; + abstractTypeMembers: NexusGenAbstractTypeMembers; + objectsUsingAbstractStrategyIsTypeOf: NexusGenObjectsUsingAbstractStrategyIsTypeOf; + abstractsUsingStrategyResolveType: NexusGenAbstractsUsingStrategyResolveType; + features: NexusGenFeaturesConfig; +} + + +declare global { + interface NexusGenPluginTypeConfig { + } + interface NexusGenPluginInputTypeConfig { + } + interface NexusGenPluginFieldConfig { + } + interface NexusGenPluginInputFieldConfig { + } + interface NexusGenPluginSchemaConfig { + } + interface NexusGenPluginArgConfig { + } +} \ No newline at end of file diff --git a/mod.ts b/mod.ts index fbc1f17..52470dd 100644 --- a/mod.ts +++ b/mod.ts @@ -1 +1,3 @@ export * from "./src/dagger/index.ts"; +export * as queries from "./src/dagger/queries.ts"; +export { schema } from "./src/dagger/schema.ts"; diff --git a/schema.graphql b/schema.graphql new file mode 100644 index 0000000..f18b08a --- /dev/null +++ b/schema.graphql @@ -0,0 +1,7 @@ +### This file was generated by Nexus Schema +### Do not make changes to this file directly + + +type Query { + upload(src: String!, token: String!): String +} \ No newline at end of file diff --git a/src/dagger/dagger.ts b/src/dagger/dagger.ts new file mode 100644 index 0000000..fc24bc7 --- /dev/null +++ b/src/dagger/dagger.ts @@ -0,0 +1,9 @@ +import Client from "../../deps.ts"; + +const sessionToken = Deno.env.get("DAGGER_SESSION_TOKEN"); +const host = `127.0.0.1:${Deno.env.get("DAGGER_SESSION_PORT")}`; + +export const client = new Client({ + host, + sessionToken, +}); diff --git a/src/dagger/jobs.ts b/src/dagger/jobs.ts index bb45bae..bac6532 100644 --- a/src/dagger/jobs.ts +++ b/src/dagger/jobs.ts @@ -1,4 +1,4 @@ -import Client from "../../deps.ts"; +import { client } from "./dagger.ts"; export enum Job { upload = "upload", @@ -6,9 +6,9 @@ export enum Job { export const exclude = [".devbox", "node_modules", ".fluentci"]; -export const upload = async (client: Client, src = ".") => { +export const upload = async (src = ".", token?: string) => { const context = client.host().directory(src); - if (!Deno.env.get("CODECOV_TOKEN")) { + if (!Deno.env.get("CODECOV_TOKEN") && !token) { console.log("CODECOV_TOKEN is not set. Skipping code coverage upload."); Deno.exit(1); } @@ -28,7 +28,10 @@ export const upload = async (client: Client, src = ".") => { .withExec(["mv", "codecov", "/usr/local/bin/codecov"]) .withDirectory("/app", context, { exclude }) .withWorkdir("/app") - .withEnvVariable("CODECOV_TOKEN", Deno.env.get("CODECOV_TOKEN")!) + .withEnvVariable( + "CODECOV_TOKEN", + Deno.env.get("CODECOV_TOKEN") ? Deno.env.get("CODECOV_TOKEN")! : token! + ) .withEnvVariable("CODECOV_URL", Deno.env.get("CODECOV_URL") || "") .withExec(["ls", "-la"]) .withExec([ @@ -45,21 +48,17 @@ export const upload = async (client: Client, src = ".") => { const result = await ctr.stdout(); - console.log(result); + return result; }; -export type JobExec = ( - client: Client, - src?: string -) => - | Promise +export type JobExec = (src?: string) => + | Promise | (( - client: Client, src?: string, options?: { ignore: string[]; } - ) => Promise); + ) => Promise); export const runnableJobs: Record = { [Job.upload]: upload, diff --git a/src/dagger/pipeline.ts b/src/dagger/pipeline.ts index 9eba263..5a6007a 100644 --- a/src/dagger/pipeline.ts +++ b/src/dagger/pipeline.ts @@ -1,4 +1,4 @@ -import Client, { connect, uploadContext } from "../../deps.ts"; +import { uploadContext } from "../../deps.ts"; import * as jobs from "./jobs.ts"; const { upload, runnableJobs, exclude } = jobs; @@ -7,22 +7,20 @@ export default async function pipeline(src = ".", args: string[] = []) { if (Deno.env.has("FLUENTCI_SESSION_ID")) { await uploadContext(src, exclude); } - connect(async (client: Client) => { - if (args.length > 0) { - await runSpecificJobs(client, args as jobs.Job[]); - return; - } + if (args.length > 0) { + await runSpecificJobs(args as jobs.Job[]); + return; + } - await upload(client); - }); + await upload(); } -async function runSpecificJobs(client: Client, args: jobs.Job[]) { +async function runSpecificJobs(args: jobs.Job[]) { for (const name of args) { const job = runnableJobs[name]; if (!job) { throw new Error(`Job ${name} not found`); } - await job(client); + await job(); } } diff --git a/src/dagger/queries.ts b/src/dagger/queries.ts new file mode 100644 index 0000000..d6a73f4 --- /dev/null +++ b/src/dagger/queries.ts @@ -0,0 +1,7 @@ +import { gql } from "../../deps.ts"; + +export const upload = gql` + query Upload($src: String!, $token: String!) { + upload(src: $src, token: $token) + } +`; diff --git a/src/dagger/schema.ts b/src/dagger/schema.ts new file mode 100644 index 0000000..b6d376a --- /dev/null +++ b/src/dagger/schema.ts @@ -0,0 +1,31 @@ +import { + queryType, + makeSchema, + dirname, + join, + resolve, + stringArg, + nonNull, +} from "../../deps.ts"; + +import { upload } from "./jobs.ts"; + +const Query = queryType({ + definition(t) { + t.string("upload", { + args: { + src: nonNull(stringArg()), + token: nonNull(stringArg()), + }, + resolve: async (_root, args, _ctx) => await upload(args.src, args.token), + }); + }, +}); + +export const schema = makeSchema({ + types: [Query], + outputs: { + schema: resolve(join(dirname(".."), dirname(".."), "schema.graphql")), + typegen: resolve(join(dirname(".."), dirname(".."), "gen", "nexus.ts")), + }, +}); From bfb9f3658d67620c481be4f59569177b97d989a1 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Sun, 1 Oct 2023 09:08:53 +0300 Subject: [PATCH 2/6] fix upload return value --- .envrc | 4 ++++ src/dagger/jobs.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..2b538b1 --- /dev/null +++ b/.envrc @@ -0,0 +1,4 @@ +DAGGER_SRC_ROOT=$(cd ../dagger && pwd) +export _EXPERIMENTAL_DAGGER_CLI_BIN=$DAGGER_SRC_ROOT/bin/dagger +export _EXPERIMENTAL_DAGGER_RUNNER_HOST=docker-container://dagger-engine.dev +export PATH=$DAGGER_SRC_ROOT/bin:$PATH \ No newline at end of file diff --git a/src/dagger/jobs.ts b/src/dagger/jobs.ts index bac6532..f787702 100644 --- a/src/dagger/jobs.ts +++ b/src/dagger/jobs.ts @@ -48,7 +48,7 @@ export const upload = async (src = ".", token?: string) => { const result = await ctr.stdout(); - return result; + return result.replace(/(\r\n|\n|\r)/gm, ""); }; export type JobExec = (src?: string) => From c04d568bbe265d1b291716c7e5c8856b0cc5cefa Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Sun, 1 Oct 2023 09:53:06 +0300 Subject: [PATCH 3/6] fix 'upload' return value --- src/dagger/jobs.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dagger/jobs.ts b/src/dagger/jobs.ts index f787702..5069a67 100644 --- a/src/dagger/jobs.ts +++ b/src/dagger/jobs.ts @@ -48,7 +48,9 @@ export const upload = async (src = ".", token?: string) => { const result = await ctr.stdout(); - return result.replace(/(\r\n|\n|\r)/gm, ""); + console.log(result); + + return "Code coverage uploaded"; }; export type JobExec = (src?: string) => From a903407563c560e5353a100a00b6475a49915e4b Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Sun, 1 Oct 2023 09:56:41 +0300 Subject: [PATCH 4/6] update 'upload' return value --- src/dagger/jobs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dagger/jobs.ts b/src/dagger/jobs.ts index 5069a67..f68e429 100644 --- a/src/dagger/jobs.ts +++ b/src/dagger/jobs.ts @@ -50,7 +50,7 @@ export const upload = async (src = ".", token?: string) => { console.log(result); - return "Code coverage uploaded"; + return "Codecov upload complete."; }; export type JobExec = (src?: string) => From 783a4af7452339441f5c794c023bfb0f25b91688 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Sun, 15 Oct 2023 05:41:09 +0000 Subject: [PATCH 5/6] setup deno sdkruntime --- .envrc | 4 --- dagger.json | 2 +- src/dagger/dagger.ts | 9 ----- src/dagger/jobs.ts | 83 ++++++++++++++++++++++---------------------- 4 files changed, 43 insertions(+), 55 deletions(-) delete mode 100644 .envrc delete mode 100644 src/dagger/dagger.ts diff --git a/.envrc b/.envrc deleted file mode 100644 index 2b538b1..0000000 --- a/.envrc +++ /dev/null @@ -1,4 +0,0 @@ -DAGGER_SRC_ROOT=$(cd ../dagger && pwd) -export _EXPERIMENTAL_DAGGER_CLI_BIN=$DAGGER_SRC_ROOT/bin/dagger -export _EXPERIMENTAL_DAGGER_RUNNER_HOST=docker-container://dagger-engine.dev -export PATH=$DAGGER_SRC_ROOT/bin:$PATH \ No newline at end of file diff --git a/dagger.json b/dagger.json index 7fdff41..cdf3b93 100644 --- a/dagger.json +++ b/dagger.json @@ -1,5 +1,5 @@ { "root": "", "name": "codecov", - "sdk": "deno" + "sdkRuntime": "tsiry/dagger-sdk-deno" } \ No newline at end of file diff --git a/src/dagger/dagger.ts b/src/dagger/dagger.ts deleted file mode 100644 index fc24bc7..0000000 --- a/src/dagger/dagger.ts +++ /dev/null @@ -1,9 +0,0 @@ -import Client from "../../deps.ts"; - -const sessionToken = Deno.env.get("DAGGER_SESSION_TOKEN"); -const host = `127.0.0.1:${Deno.env.get("DAGGER_SESSION_PORT")}`; - -export const client = new Client({ - host, - sessionToken, -}); diff --git a/src/dagger/jobs.ts b/src/dagger/jobs.ts index f68e429..ac237c3 100644 --- a/src/dagger/jobs.ts +++ b/src/dagger/jobs.ts @@ -1,4 +1,4 @@ -import { client } from "./dagger.ts"; +import Client, { connect } from "../../deps.ts"; export enum Job { upload = "upload", @@ -7,49 +7,50 @@ export enum Job { export const exclude = [".devbox", "node_modules", ".fluentci"]; export const upload = async (src = ".", token?: string) => { - const context = client.host().directory(src); - if (!Deno.env.get("CODECOV_TOKEN") && !token) { - console.log("CODECOV_TOKEN is not set. Skipping code coverage upload."); - Deno.exit(1); - } + await connect(async (client: Client) => { + const context = client.host().directory(src); + if (!Deno.env.get("CODECOV_TOKEN") && !token) { + console.log("CODECOV_TOKEN is not set. Skipping code coverage upload."); + Deno.exit(1); + } - const ctr = client - .pipeline(Job.upload) - .container() - .from("alpine:latest") - .withExec(["apk", "update"]) - .withExec(["apk", "add", "curl", "git"]) - .withExec([ - "curl", - "-Os", - "https://uploader.codecov.io/latest/alpine/codecov", - ]) - .withExec(["chmod", "a+x", "codecov"]) - .withExec(["mv", "codecov", "/usr/local/bin/codecov"]) - .withDirectory("/app", context, { exclude }) - .withWorkdir("/app") - .withEnvVariable( - "CODECOV_TOKEN", - Deno.env.get("CODECOV_TOKEN") ? Deno.env.get("CODECOV_TOKEN")! : token! - ) - .withEnvVariable("CODECOV_URL", Deno.env.get("CODECOV_URL") || "") - .withExec(["ls", "-la"]) - .withExec([ - "sh", - "-c", - `codecov -t $CODECOV_TOKEN ${ - Deno.env.get("CODECOV_URL") ? `--url $CODECOV_URL` : "" - } ${ - Deno.env.get("COVERAGE_FILE") - ? `-f ${Deno.env.get("COVERAGE_FILE")}` - : "" - }`, - ]); + const ctr = client + .pipeline(Job.upload) + .container() + .from("alpine:latest") + .withExec(["apk", "update"]) + .withExec(["apk", "add", "curl", "git"]) + .withExec([ + "curl", + "-Os", + "https://uploader.codecov.io/latest/alpine/codecov", + ]) + .withExec(["chmod", "a+x", "codecov"]) + .withExec(["mv", "codecov", "/usr/local/bin/codecov"]) + .withDirectory("/app", context, { exclude }) + .withWorkdir("/app") + .withEnvVariable( + "CODECOV_TOKEN", + Deno.env.get("CODECOV_TOKEN") ? Deno.env.get("CODECOV_TOKEN")! : token! + ) + .withEnvVariable("CODECOV_URL", Deno.env.get("CODECOV_URL") || "") + .withExec(["ls", "-la"]) + .withExec([ + "sh", + "-c", + `codecov -t $CODECOV_TOKEN ${ + Deno.env.get("CODECOV_URL") ? `--url $CODECOV_URL` : "" + } ${ + Deno.env.get("COVERAGE_FILE") + ? `-f ${Deno.env.get("COVERAGE_FILE")}` + : "" + }`, + ]); - const result = await ctr.stdout(); - - console.log(result); + const result = await ctr.stdout(); + console.log(result); + }); return "Codecov upload complete."; }; From c81b042094407348303f81a76f608518afd5d768 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Sat, 21 Oct 2023 19:18:51 +0000 Subject: [PATCH 6/6] update README.md --- README.md | 14 +++++--------- ci.ts | 9 +-------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 2c6d304..d514f6e 100644 --- a/README.md +++ b/README.md @@ -31,20 +31,16 @@ fluentci run codecov_pipeline |---------|----------------------------------| | upload | Uploads coverage to Codecov. | +```graphql +upload(src: String!, token: String!): String +``` + ## Programmatic usage You can also use this pipeline programmatically: ```typescript -import Client, { connect } from "https://sdk.fluentci.io/v0.1.9/mod.ts"; import { upload } from "https://deno.land/x/codecov_pipeline/mod.ts"; -function pipeline(src = ".") { - connect(async (client: Client) => { - await upload(client, src); - }); -} - -pipeline(); - +await upload(); ``` diff --git a/ci.ts b/ci.ts index 1f727d6..1514aa0 100644 --- a/ci.ts +++ b/ci.ts @@ -1,10 +1,3 @@ -import Client, { connect } from "https://sdk.fluentci.io/v0.1.9/mod.ts"; import { upload } from "https://deno.land/x/codecov_pipeline/mod.ts"; -function pipeline(src = ".") { - connect(async (client: Client) => { - await upload(client, src); - }); -} - -pipeline(); +await upload();