Skip to content

Support self-hosted GitHub Enterprise #3724

Open
@joshuaspence

Description

@joshuaspence

Is your feature request related to a problem? Please describe.

I want to use Chezmoi to install various binaries from a self-hosted GitHub Enterprise installation. I am already using chezmoiexternals and the githubLatestRelease function to install binaries from github.com, for example:

---
.local/bin/chezmoi:
  type: 'file'
  executable: true
  url: '{{ (gitHubLatestRelease "twpayne/chezmoi").HTMLURL | replace "/releases/tag/" "/releases/download/" }}/chezmoi-{{ .chezmoi.os }}-{{ .chezmoi.arch }}'

But this doesn't work for self-hosted GitHub Enterprise as I don't believe there is a way to pass in a custom hostname. Similarly there isn't a way to pass in an auth token (there is $CHEZMOI_GITHUB_ACCESS_TOKEN but I would need a way to provide a token that is scoped to a single domain).

Describe the solution you'd like

Either a new family of functions (e.g. githubEnterpriseLatestRelease) or extending the existing GitHub functions to accept a hostname (e.g. githubLatestRelease "https://git.example.com/owner/repo"). Additionally, a way to provide the auth token for git.example.com in chezmoi.yaml.

Describe alternatives you've considered

Previously I was just using a script to do this:

#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

{{ $version := output "gh" "release" "--repo=git.example.com/owner/repo" "view" "--json=name" "--template={{.name}}" -}}
gh release --repo git.example.com/owner/repo download --output=- --pattern=example_{{ .chezmoi.os }}_{{ .chezmoi.arch }}.tar.gz {{ $version }} | tar --extract --file=- --gunzip --directory ~/.local/bin example

I have since changed to using a template since I want Chezmoi to purge unmanaged files from ~/.local/bin.

# dot_local/bin/executable_example.tmpl
{{- $version := output "gh" "--repo=git.example.com/owner/repo" "release" "view" "--json=name" "--jq=.name" | trim -}}
{{ output "sh" "-c" (printf "gh --repo=git.example.com/owner/repo release download --output=- --pattern=example_%s_%s.tar.gz %s | tar --extract --to-stdout --gunzip example" .chezmoi.os .chezmoi.arch $version) }}

This works okay, but seems a bit hacky and is definitely less readable.

I realize I could also do this using the git-repo external, but I would then need to add some sort is post-install script to do the actual compilation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions