Unverified Commit ebf0c14e authored by Moraxyc's avatar Moraxyc
Browse files

acli: init at 1.3.7

parent 12e0c042
Loading
Loading
Loading
Loading
+63 −0
Original line number Diff line number Diff line
{
  lib,
  stdenvNoCC,
  buildFHSEnv,
  callPackage,
  fetchurl,
}:
let
  sources = builtins.fromJSON (builtins.readFile ./sources.json);

  src =
    fetchurl
      sources.sources.${stdenvNoCC.hostPlatform.system}
        or (throw "Unsupported system: ${stdenvNoCC.hostPlatform.system}");
  version = sources.version;

  meta = {
    description = "Atlassian Command Line Interface";
    homepage = "https://developer.atlassian.com/cloud/acli/guides/introduction";
    maintainers = with lib.maintainers; [ moraxyc ];
    platforms = lib.attrNames sources.sources;
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
    license = lib.licenses.unfree;
    mainProgram = "acli";
  };

  updateScript = ./update.py;

  unwrapped = callPackage ./unwrapped.nix {
    inherit
      src
      version
      meta
      updateScript
      ;
  };
  wrapped = buildFHSEnv {
    pname = "acli";
    inherit version;

    targetPkgs =
      p: with p; [
        unwrapped

        cacert
        openssl

        # For rovodev
        zlib
        libffi
        sqlite
      ];

    runScript = "acli";

    passthru = {
      inherit unwrapped updateScript;
    };

    inherit meta;
  };
in
if stdenvNoCC.hostPlatform.isLinux then wrapped else unwrapped.override { pname = "acli"; }
+21 −0
Original line number Diff line number Diff line
{
  "version": "1.3.7-stable",
  "sources": {
    "aarch64-darwin": {
      "url": "https://acli.atlassian.com/darwin/1.3.7-stable/acli_1.3.7-stable_darwin_arm64.tar.gz",
      "sha256": "0996a8833625bb74f6af55ec628a1208546631f2e10157ee171e98f38d30dce3"
    },
    "aarch64-linux": {
      "url": "https://acli.atlassian.com/linux/1.3.7-stable/acli_1.3.7-stable_linux_arm64.tar.gz",
      "sha256": "698e66275bbb1fadbb1bc25c3ac0c014d846ec7fcb8c87c332cdfda3cf539d5f"
    },
    "x86_64-darwin": {
      "url": "https://acli.atlassian.com/darwin/1.3.7-stable/acli_1.3.7-stable_darwin_amd64.tar.gz",
      "sha256": "02597287d54a39f514dae9ca8d60d3f4ad1eee28fcb2ffc7282fe182398a1438"
    },
    "x86_64-linux": {
      "url": "https://acli.atlassian.com/linux/1.3.7-stable/acli_1.3.7-stable_linux_amd64.tar.gz",
      "sha256": "43c54b31f5def20cf0f29af9f8987c8b6180d6a875b26e129e11179b8b0d2654"
    }
  }
}
+57 −0
Original line number Diff line number Diff line
{
  lib,
  stdenvNoCC,
  fetchurl,
  versionCheckHook,
  installShellFiles,

  writeShellApplication,
  curl,
  gnugrep,
  common-updater-scripts,

  pname ? "acli-unwrapped",
  src,
  version,
  meta,
  updateScript,
}:
stdenvNoCC.mkDerivation (finalAttrs: {
  inherit
    pname
    src
    version
    meta
    ;

  dontBuild = true;

  nativeBuildInputs = [ installShellFiles ];

  installPhase = ''
    runHook preInstall

    install -Dm755 acli $out/bin/acli
  ''
  + lib.optionalString (stdenvNoCC.buildPlatform.canExecute stdenvNoCC.hostPlatform) ''
    installShellCompletion --cmd acli \
      --bash <($out/bin/acli completion bash) \
      --fish <($out/bin/acli completion fish) \
      --zsh <($out/bin/acli completion zsh)

    mkdir -p $out/share/powershell
    $out/bin/acli completion powershell > $out/share/powershell/acli.Completion.ps1
  ''
  + ''
    runHook postInstall
  '';

  passthru = {
    inherit updateScript;
  };

  nativeInstallCheckInputs = [ versionCheckHook ];
  versionCheckProgramArg = "-v";
  doInstallCheck = true;

})
+90 −0
Original line number Diff line number Diff line
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p

import re
import json
import os
import sys
from urllib.request import urlopen, Request


def get_arch_os_key(url) -> str:
    if "darwin_amd64" in url:
        return "x86_64-darwin"
    elif "darwin_arm64" in url:
        return "aarch64-darwin"
    elif "linux_amd64" in url:
        return "x86_64-linux"
    elif "linux_arm64" in url:
        return "aarch64-linux"
    else:
        raise Exception(f"Unknown architecture: {url}")


def fetch_content(url: str) -> str:
    req = Request(url)
    if "GITHUB_TOKEN" in os.environ:
        req.add_header("Authorization", f"Bearer {os.environ['GITHUB_TOKEN']}")

    with urlopen(req) as resp:
        return resp.read().decode("utf-8")


def parse_and_check(content):
    data = {"version": "", "sources": {}}

    version_match = re.search(r'version\s+"([^"]+)"', content)
    if not version_match:
        raise ValueError("Could not find version!")

    version = version_match.group(1)
    data["version"] = version
    print(f"Detected version: {version}")

    old_version = os.environ.get("UPDATE_NIX_OLD_VERSION")
    if old_version == version:
        print("No newer version available!")
        sys.exit(0)

    pattern = re.compile(
        r'url\s+"([^"]+)"(?:,\s*using:\s*\S+)?\s+sha256\s+"([a-fA-F0-9]+)"'
    )
    matches = pattern.findall(content)

    if not matches:
        raise ValueError(
            "Regex failed to find any URL/SHA256 pairs. The Formula format might have changed."
        )

    for url, hex_sha in matches:
        key = get_arch_os_key(url)

        data["sources"][key] = {"url": url, "sha256": hex_sha}

    data["sources"] = dict(sorted(data["sources"].items()))

    return data


def main():
    try:
        ruby_content = fetch_content(
            "https://github.com/atlassian/homebrew-acli/raw/refs/heads/main/Formula/acli.rb"
        )
        result = parse_and_check(ruby_content)

        output_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "sources.json"
        )

        with open(output_path, "w") as f:
            json.dump(result, f, indent=2)
            f.write("\n")

    except Exception as e:
        print(f"Error: {e}", file=sys.stderr)
        sys.exit(1)


if __name__ == "__main__":
    main()