Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
"dotnet",
"eclipse-deps",
"git-lfs",
"github-cli",
"github-copilot-cli",
"gitlab-cli",
"go",
Expand Down
4 changes: 4 additions & 0 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func init() {
gotaskr.Task("Feature:git-lfs:Package", func() error { return packageFeature("git-lfs") })
gotaskr.Task("Feature:git-lfs:Test", func() error { return testFeature("git-lfs") })

////////// github-cli
gotaskr.Task("Feature:github-cli:Package", func() error { return packageFeature("github-cli") })
gotaskr.Task("Feature:github-cli:Test", func() error { return testFeature("github-cli") })

////////// github-copilot-cli
gotaskr.Task("Feature:github-copilot-cli:Package", func() error { return packageFeature("github-copilot-cli") })
gotaskr.Task("Feature:github-copilot-cli:Test", func() error { return testFeature("github-copilot-cli") })
Expand Down
11 changes: 11 additions & 0 deletions features/src/github-cli/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Notes

### System Compatibility

Debian, Ubuntu, Alpine

### Accessed Urls

Needs access to the following URL for downloading and resolving:
* https://github.com
* https://api.github.com
33 changes: 33 additions & 0 deletions features/src/github-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# GitHub CLI (github-cli)

Installs the GitHub CLI.

## Example Usage

```json
"features": {
"ghcr.io/postfinance/devcontainer-features/github-cli:1.0.0": {
"version": "latest",
"downloadUrl": ""
}
}
```

## Options

| Option | Description | Type | Default Value | Proposals |
|-----|-----|-----|-----|-----|
| version | The version of GitHub CLI to install. | string | latest | latest, 2.67.0 |
| downloadUrl | The download URL to use for GitHub CLI binaries. | string | <empty> | https://mycompany.com/artifactory/github-releases-remote |

## Notes

### System Compatibility

Debian, Ubuntu, Alpine

### Accessed Urls

Needs access to the following URL for downloading and resolving:
* https://github.com
* https://api.github.com
25 changes: 25 additions & 0 deletions features/src/github-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"id": "github-cli",
"version": "1.0.0",
"name": "GitHub CLI",
"description": "Installs the GitHub CLI.",
"options": {
"version": {
"type": "string",
"proposals": [
"latest",
"2.67.0"
],
"default": "latest",
"description": "The version of GitHub CLI to install."
},
"downloadUrl": {
"type": "string",
"default": "",
"proposals": [
"https://mycompany.com/artifactory/github-releases-remote"
],
"description": "The download URL to use for GitHub CLI binaries."
}
}
}
5 changes: 5 additions & 0 deletions features/src/github-cli/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
. ./functions.sh

"./installer_$(detect_arch)" \
-version="${VERSION:-"latest"}" \
-downloadUrl="${DOWNLOADURL:-""}"
104 changes: 104 additions & 0 deletions features/src/github-cli/installer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package main

import (
"builder/installer"
"flag"
"fmt"
"os"
"path/filepath"
"regexp"

"github.com/roemer/gover"
)

//////////
// Configuration
//////////

var versionRegex *regexp.Regexp = regexp.MustCompile(`(?m)^v(?P<raw>(\d+)\.(\d+)\.(\d+))$`)

//////////
// Main
//////////

func main() {
if err := runMain(); err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
}

func runMain() error {
// Handle the flags
version := flag.String("version", "latest", "")
downloadUrl := flag.String("downloadUrl", "", "")
flag.Parse()

// Load settings from an external file
if err := installer.LoadOverrides(); err != nil {
return err
}

// Apply override logic for URLs
installer.HandleGitHubOverride(downloadUrl, "cli/cli", "github-cli-download-url")

// Create and process the feature
feature := installer.NewFeature("GitHub CLI", false,
&ghComponent{
ComponentBase: installer.NewComponentBase("GitHub CLI", *version),
DownloadUrl: *downloadUrl,
})
return feature.Process()
}

//////////
// Implementation
//////////

type ghComponent struct {
*installer.ComponentBase
DownloadUrl string
}

func (c *ghComponent) GetAllVersions() ([]*gover.Version, error) {
tags, err := installer.Tools.GitHub.GetTags("cli", "cli")
if err != nil {
return nil, err
}
return installer.Tools.Versioning.ParseVersionsFromList(tags, versionRegex, true)
}

func (c *ghComponent) InstallVersion(version *gover.Version) error {
// Map architecture
archPart, err := installer.Tools.System.MapArchitecture(map[string]string{
installer.AMD64: "amd64",
installer.ARM64: "arm64",
})
if err != nil {
return err
}
// Download the file
fileName := fmt.Sprintf("gh_%s_linux_%s.tar.gz", version.Raw, archPart)
downloadUrl, err := installer.Tools.Http.BuildUrl(c.DownloadUrl, "v"+version.Raw, fileName)
if err != nil {
return err
}
if err := installer.Tools.Download.ToFile(downloadUrl, fileName, "GitHub CLI"); err != nil {
return err
}
defer os.Remove(fileName)
// Extract to temp directory
tempDir, err := os.MkdirTemp("", "github-cli-extract")
if err != nil {
return err
}
defer os.RemoveAll(tempDir)
if err := installer.Tools.Compression.ExtractTarGz(fileName, tempDir, true); err != nil {
return err
}
// Install binary (located at bin/gh inside the extracted folder)
if err := installer.Tools.System.InstallBinaryToUsrLocalBin(filepath.Join(tempDir, "bin", "gh"), "gh"); err != nil {
return err
}
return nil
}
7 changes: 7 additions & 0 deletions features/test/github-cli/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e

[[ -f "$(dirname "$0")/../functions.sh" ]] && source "$(dirname "$0")/../functions.sh"
[[ -f "$(dirname "$0")/functions.sh" ]] && source "$(dirname "$0")/functions.sh"

check_version "$(gh version)" "gh version 2.67.0"
15 changes: 15 additions & 0 deletions features/test/github-cli/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"install": {
"build": {
"dockerfile": "Dockerfile",
"options": [
"--add-host=host.docker.internal:host-gateway"
]
},
"features": {
"./github-cli": {
"version": "2.67.0"
}
}
}
}
6 changes: 6 additions & 0 deletions features/test/github-cli/test-images.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"mcr.microsoft.com/devcontainers/base:debian-11",
"mcr.microsoft.com/devcontainers/base:debian-12",
"mcr.microsoft.com/devcontainers/base:alpine",
"mcr.microsoft.com/devcontainers/base:ubuntu-24.04"
]
3 changes: 3 additions & 0 deletions override-all.env
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ DOTNET_NUGET_CONFIG_PATH=""
# git-lfs
GIT_LFS_DOWNLOAD_URL=""

# github-cli
GITHUB_CLI_DOWNLOAD_URL=""

# github-copilot-cli
GITHUB_COPILOT_CLI_DOWNLOAD_URL=""

Expand Down