Edits history of script submission #5871 for ' Git repo test read write (windmill)'

  • deno
    import * as wmill from "npm:[email protected]";
    import { basename } from "https://deno.land/[email protected]/path/mod.ts";
    
    export async function main(repo_url_resource_path: string) {
      const cwd = Deno.cwd();
      Deno.env.set("HOME", ".");
      console.log(`Cloning repo from resource`);
    
      const repo_name = await git_clone(repo_url_resource_path);
    
      Deno.chdir(`${cwd}/${repo_name}`);
    
      console.log(`Attempting an empty push to repository ${repo_name}`);
      await git_push();
    
      console.log("Finished");
      Deno.chdir(`${cwd}`);
    }
    
    async function git_clone(repo_resource_path: string): Promise<string> {
      // TODO: handle private SSH keys as well
      let repo_url = (await wmill.getResource(repo_resource_path)).url;
    
      const azureMatch = repo_url.match(/AZURE_DEVOPS_TOKEN\((?<url>.+)\)/);
    
      if (azureMatch) {
        console.log(
          "Requires Azure DevOps service account access token, requesting..."
        );
        const azureResource = await wmill.getResource(azureMatch.groups.url);
    
        const response = await fetch(
          `https://login.microsoftonline.com/${azureResource.azureTenantId}/oauth2/token`,
          {
            method: "POST",
            body: new URLSearchParams({
              client_id: azureResource.azureClientId,
              client_secret: azureResource.azureClientSecret,
              grant_type: "client_credentials",
              resource: "499b84ac-1321-427f-aa17-267ca6975798/.default",
            }),
          }
        );
    
        const { access_token } = await response.json();
    
        repo_url = repo_url.replace(azureMatch[0], access_token);
      }
    
      const repo_name = basename(repo_url, ".git");
    
      await sh_run("git", "clone", "--quiet", "--depth", "1", repo_url, repo_name);
      return repo_name;
    }
    
    async function git_push() {
      await sh_run("git", "config", "user.email", Deno.env.get("WM_EMAIL"));
      await sh_run("git", "config", "user.name", Deno.env.get("WM_USERNAME"));
      await sh_run("git", "push");
    }
    
    async function sh_run(cmd: string, ...args: string[]) {
      // console.log(`Running '${cmd} ${args.join(" ")}'`)
      const command = new Deno.Command(cmd, {
        args: args,
      });
      const { code, stdout: _stdout, stderr: _stderr } = await command.output();
    
      if (code !== 0) {
        throw `SH command '${cmd} ${args.join(
          " "
        )}' returned with a non-zero status ${code}`;
      }
    }
    

    Submitted by hugo697 671 days ago

  • deno
    import * as wmill from "npm:[email protected]";
    import { basename } from "https://deno.land/[email protected]/path/mod.ts";
    
    export async function main(repo_url_resource_path: string) {
      const cwd = Deno.cwd();
      Deno.env.set("HOME", ".");
      console.log(`Cloning repo from resource`);
    
      const repo_name = await git_clone(repo_url_resource_path);
    
      Deno.chdir(`${cwd}/${repo_name}`);
    
      console.log(`Attempting an empty push to repository ${repo_name}`);
      await git_push();
    
      console.log("Finished");
      Deno.chdir(`${cwd}`);
    }
    
    async function git_clone(repo_resource_path: string): Promise<string> {
      // TODO: handle private SSH keys as well
      const repo_url = (await wmill.getResource(repo_resource_path)).url;
      const repo_name = basename(repo_url, ".git");
    
      await sh_run("git", "clone", "--quiet", "--depth", "1", repo_url, repo_name);
      return repo_name;
    }
    
    async function git_push() {
      await sh_run("git", "config", "user.email", Deno.env.get("WM_EMAIL"));
      await sh_run("git", "config", "user.name", Deno.env.get("WM_USERNAME"));
      await sh_run("git", "push");
    }
    
    async function sh_run(cmd: string, ...args: string[]) {
      // console.log(`Running '${cmd} ${args.join(" ")}'`)
      const command = new Deno.Command(cmd, {
        args: args,
      });
      const { code, stdout: _stdout, stderr: _stderr } = await command.output();
    
      if (code !== 0) {
        throw `SH command '${cmd} ${args.join(
          " "
        )}' returned with a non-zero status ${code}`;
      }
    }
    

    Submitted by hugo697 826 days ago

  • deno
    import * as wmill from "npm:[email protected]";
    import { basename } from "https://deno.land/[email protected]/path/mod.ts";
    
    export async function main(
      repo_url_resource_path: string,
    ) {
      const cwd = Deno.cwd();
      Deno.env.set("HOME", ".");
      console.log(`Cloning repo from resource`);
    
      const repo_name = await git_clone(repo_url_resource_path);
    
      Deno.chdir(`${cwd}/${repo_name}`);
    
      console.log(`Attempting an empty push to repository ${repo_name}`);
      await git_push();
    
      console.log("Finished");
      Deno.chdir(`${cwd}`);
    }
    
    async function git_clone(repo_resource_path: string): Promise<string> {
      // TODO: handle private SSH keys as well
      const repo_url = (await wmill.getResource(repo_resource_path)).url;
      const repo_name = basename(repo_url, ".git");
    
      await sh_run(
        "git",
        "clone",
        "--quiet",
        "--depth",
        "1",
        repo_url,
        repo_name,
      );
      return repo_name;
    }
    
    async function git_push() {
      await sh_run(
        "git",
        "config",
        "user.email",
        Deno.env.get("WM_EMAIL"),
      );
      await sh_run(
        "git",
        "config",
        "user.name",
        Deno.env.get("WM_USERNAME"),
      );
      await sh_run(
        "git",
        "push",
      );
    }
    
    async function sh_run(cmd: string, ...args: string[]) {
      // console.log(`Running '${cmd} ${args.join(" ")}'`)
      const command = new Deno.Command(cmd, {
        args: args,
      });
      const { code, stdout: _stdout, stderr: _stderr } = await command.output();
    
      if (code !== 0) {
        throw `SH command '${cmd} ${
          args.join(" ")
        }' returned with a non-zero status ${code}`;
      }
    }
    

    Submitted by hugo697 885 days ago

  • deno
    import * as wmill from "npm:windmill-client@1";
    import { basename } from "https://deno.land/[email protected]/path/mod.ts";
    
    export async function main(
      repo_url_resource_path: string,
    ) {
      const cwd = Deno.cwd();
      Deno.env.set("HOME", ".");
      console.log(`Cloning repo from resource`);
    
      const repo_name = await git_clone(repo_url_resource_path);
    
      Deno.chdir(`${cwd}/${repo_name}`);
    
      console.log(`Attempting an empty push to repository ${repo_name}`);
      await git_push();
    
      console.log("Finished");
      Deno.chdir(`${cwd}`);
    }
    
    async function git_clone(repo_resource_path: string): Promise<string> {
      // TODO: handle private SSH keys as well
      const repo_url = (await wmill.getResource(repo_resource_path)).url;
      const repo_name = basename(repo_url, ".git");
    
      await sh_run(
        "git",
        "clone",
        "--quiet",
        "--depth",
        "1",
        repo_url,
        repo_name,
      );
      return repo_name;
    }
    
    async function git_push() {
      await sh_run(
        "git",
        "config",
        "user.email",
        Deno.env.get("WM_EMAIL"),
      );
      await sh_run(
        "git",
        "config",
        "user.name",
        Deno.env.get("WM_USERNAME"),
      );
      await sh_run(
        "git",
        "push",
      );
    }
    
    async function sh_run(cmd: string, ...args: string[]) {
      // console.log(`Running '${cmd} ${args.join(" ")}'`)
      const command = new Deno.Command(cmd, {
        args: args,
      });
      const { code, stdout: _stdout, stderr: _stderr } = await command.output();
    
      if (code !== 0) {
        throw `SH command '${cmd} ${
          args.join(" ")
        }' returned with a non-zero status ${code}`;
      }
    }
    

    Submitted by hugo697 914 days ago

  • deno
    import * as wmill from "npm:windmill-client@1";
    import { basename } from "https://deno.land/[email protected]/path/mod.ts";
    
    export async function main(
      repo_url_resource_path: string,
    ) {
      const cwd = Deno.cwd();
      Deno.env.set("HOME", ".");
      console.log(`Cloning repo from resource`);
    
      const repo_name = await git_clone(repo_url_resource_path);
    
      Deno.chdir(`${cwd}/${repo_name}`);
    
      console.log(`Attempting an empty push to repository ${repo_name}`);
      await git_push();
    
      console.log("Finished");
      Deno.chdir(`${cwd}`);
    }
    
    async function git_clone(repo_resource_path: string): Promise<string> {
      const repo_url = (await wmill.getResource(repo_resource_path)).url;
      const repo_name = basename(repo_url, ".git");
    
      await sh_run(
        "git",
        "clone",
        "--quiet",
        "--depth",
        "1",
        repo_url,
        repo_name,
      );
      return repo_name;
    }
    
    async function git_push() {
      await sh_run(
        "git",
        "config",
        "user.email",
        Deno.env.get("WM_EMAIL"),
      );
      await sh_run(
        "git",
        "config",
        "user.name",
        Deno.env.get("WM_USERNAME"),
      );
      await sh_run(
        "git",
        "push",
      );
    }
    
    async function sh_run(cmd: string, ...args: string[]) {
      const command = new Deno.Command(cmd, {
        args: args,
      });
      const { code, stdout: _stdout, stderr: _stderr } = await command.output();
    
      if (code !== 0) {
        throw `SH command '${cmd} ${
          args.join(" ")
        }' returned with a non-zero status ${code}`;
      }
    }
    

    Submitted by hugo697 914 days ago

  • deno
    import * as wmill from "npm:windmill-client@1";
    import { basename } from "https://deno.land/[email protected]/path/mod.ts";
    
    export async function main(
      repo_url_resource_path: string,
    ) {
      const cwd = Deno.cwd();
      Deno.env.set("HOME", ".");
      console.log(`Cloning repo from resource`);
    
      const repo_name = await git_clone(repo_url_resource_path);
    
      Deno.chdir(`${cwd}/${repo_name}`);
    
      console.log(`Attempting an empty push to repository ${repo_name}`);
      await git_push();
    
      console.log("Finished");
      Deno.chdir(`${cwd}`);
    }
    
    async function git_clone(repo_resource_path: string): Promise<string> {
      // TODO: handle private SSH keys as well
      const repo_url = (await wmill.getResource(repo_resource_path)).url;
      const repo_name = basename(repo_url, ".git");
    
      await sh_run(
        "git",
        "clone",
        "--quiet",
        "--depth",
        "1",
        repo_url,
        repo_name,
      );
      return repo_name;
    }
    
    async function git_push() {
      await sh_run(
        "git",
        "config",
        "user.email",
        Deno.env.get("WM_EMAIL"),
      );
      await sh_run(
        "git",
        "config",
        "user.name",
        Deno.env.get("WM_USERNAME"),
      );
      await sh_run(
        "git",
        "push",
      );
    }
    
    async function sh_run(cmd: string, ...args: string[]) {
      const command = new Deno.Command(cmd, {
        args: args,
      });
      const { code, stdout: _stdout, stderr: _stderr } = await command.output();
    
      if (code !== 0) {
        throw `SH command '${cmd} ${
          args.join(" ")
        }' returned with a non-zero status ${code}`;
      }
    }
    

    Submitted by hugo697 914 days ago

  • deno
    import * as wmillclient from "npm:windmill-client@1";
    import wmill from "https://deno.land/x/[email protected]/main.ts";
    import { basename } from "https://deno.land/[email protected]/path/mod.ts";
    
    export async function main(
      repo_url_resource_path: string,
      path: string,
      commit_msg: string,
    ) {
      const cwd = Deno.cwd();
      Deno.env.set("HOME", ".");
      console.log(`Syncing script/flow/app ${path}`);
    
      const repo_name = await git_clone(repo_url_resource_path);
    
      Deno.chdir(`${cwd}/${repo_name}`);
      console.log(`Pushing to repository ${repo_name}`);
    
      await wmill_sync_pull(path);
    
      await git_push(path, commit_msg);
    
      console.log("Finished syncing");
      Deno.chdir(`${cwd}`);
    }
    
    async function git_clone(repo_resource_path: string): Promise<string> {
      // TODO: handle private SSH keys as well
      const repo_url = (await wmillclient.getResource(repo_resource_path)).url;
      const repo_name = basename(repo_url, ".git");
    
      await sh_run(
        "git",
        "clone",
        "--quiet",
        "--depth",
        "1",
        // TODO: We could maybe use --sparse here to make the clone more lightweight
        // TODO: It will use the default branch - we could add the branch name to the resource if needed
        repo_url,
        repo_name,
      );
      return repo_name;
    }
    
    async function git_push(path: string, commit_msg: string) {
      await sh_run(
        "git",
        "config",
        "user.email",
        Deno.env.get("WM_EMAIL"),
      );
      await sh_run(
        "git",
        "config",
        "user.name",
        Deno.env.get("WM_USERNAME"),
      );
      await sh_run(
        "git",
        "add",
        `${path}*`,
      );
      try {
        await sh_run(
          "git",
          "diff",
          "--cached",
          "--quiet",
        );
      } catch {
        // git diff returns exit-code = 1 when there's at least on staged changes
        await sh_run(
          "git",
          "commit",
          "-m",
          commit_msg,
        );
        await sh_run(
          "git",
          "push",
        );
        return;
      }
      console.log("No changes detected, nothing to commit. Returning...");
    }
    
    async function sh_run(cmd: string, ...args: string[]) {
      // console.log(`Running '${cmd} ${args.join(" ")}'`)
      const command = new Deno.Command(cmd, {
        args: args,
      });
      const { code, stdout: _stdout, stderr: _stderr } = await command.output();
    
      if (code !== 0) {
        throw `SH command '${cmd} ${
          args.join(" ")
        }' returned with a non-zero status ${code}`;
      }
    }
    
    async function wmill_sync_pull(path: string) {
      await Deno.writeTextFile(".wmillignore", `*\n!${path}`);
      await wmill_run(
        "version",
      );
      console.log("Adding Windmill workspace");
      await wmill_run(
        "workspace",
        "add",
        Deno.env.get("WM_WORKSPACE"),
        Deno.env.get("WM_WORKSPACE"),
        Deno.env.get("BASE_INTERNAL_URL") + "/",
        "--token",
        Deno.env.get("WM_TOKEN") ?? "",
      );
      console.log("Pulling workspace into git repo");
      await wmill_run(
        "sync",
        "pull",
        "--token",
        Deno.env.get("WM_TOKEN") ?? "",
        "--workspace",
        Deno.env.get("WM_WORKSPACE"),
        "--yes",
        "--raw",
        "--skip-variables",
        "--skip-secrets",
        "--skip-resources",
      );
      await Deno.remove(".wmillignore");
    }
    
    async function wmill_run(...cmd: string[]) {
      // console.log(`Running '${cmd.join(" ")}'`)
      await wmill.parse(cmd);
    }
    

    Submitted by hugo697 914 days ago

  • deno
    import * as wmill from "npm:windmill-client@1";
    import { basename } from "https://deno.land/[email protected]/path/mod.ts";
    
    export async function main(
      repo_url_resource_path: string,
    ) {
      const cwd = Deno.cwd();
      Deno.env.set("HOME", ".");
      console.log(`Cloning repo from resource`);
    
      const repo_name = await git_clone(repo_url_resource_path);
    
      Deno.chdir(`${cwd}/${repo_name}`);
    
      console.log(`Attempting an empty push to repository ${repo_name}`);
      await git_push();
    
      console.log("Finished");
      Deno.chdir(`${cwd}`);
    }
    
    async function git_clone(repo_resource_path: string): Promise<string> {
      // TODO: handle private SSH keys as well
      const repo_url = (await wmill.getResource(repo_resource_path)).url;
      const repo_name = basename(repo_url, ".git");
    
      await sh_run(
        "git",
        "clone",
        "--quiet",
        "--depth",
        "1",
        repo_url,
        repo_name,
      );
      return repo_name;
    }
    
    async function git_push() {
      await sh_run(
        "git",
        "config",
        "user.email",
        Deno.env.get("WM_EMAIL"),
      );
      await sh_run(
        "git",
        "config",
        "user.name",
        Deno.env.get("WM_USERNAME"),
      );
      await sh_run(
        "git",
        "push",
      );
    }
    
    async function sh_run(cmd: string, ...args: string[]) {
      const command = new Deno.Command(cmd, {
        args: args,
      });
      const { code, stdout: _stdout, stderr: _stderr } = await command.output();
    
      if (code !== 0) {
        throw `SH command '${cmd} ${
          args.join(" ")
        }' returned with a non-zero status ${code}`;
      }
    }
    

    Submitted by hugo697 914 days ago