Skip to content

Commit

Permalink
feat: remove username input
Browse files Browse the repository at this point in the history
Logging into ghcr.io does not require that the username match the owner of the token.
  • Loading branch information
joshdk committed Feb 27, 2024
1 parent 5dce1ef commit a690e91
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
9 changes: 4 additions & 5 deletions docker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import (
"syscall"
)

// Login executes a docker login to ghcr.io with the given username and
// password.
func Login(username, password string) error {
cmd := exec.Command("/usr/bin/docker", "login", "ghcr.io", "--username", username, "--password-stdin")
cmd.Stdin = strings.NewReader(password + "\n")
// Login executes a docker login to ghcr.io with the given GitHub token.
func Login(token string) error {
cmd := exec.Command("/usr/bin/docker", "login", "ghcr.io", "--username", "-", "--password-stdin")
cmd.Stdin = strings.NewReader(token + "\n")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

Expand Down
8 changes: 1 addition & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ func mainCmd() error {
flag.StringVar(&image, "image", "", "ghcr.io image to run")
var tokenEnv string
flag.StringVar(&tokenEnv, "token-env", "", "env var to use for github token")
var username string
flag.StringVar(&username, "username", "", "username for github token")
flag.Parse()

if image == "" {
Expand All @@ -53,12 +51,8 @@ func mainCmd() error {
token = value
}

if username == "" {
username = os.Getenv("GITHUB_ACTOR")
}

fmt.Printf("::group::%s\n", "Docker login")
err := docker.Login(username, token)
err := docker.Login(token)
fmt.Println("::endgroup::")
if err != nil {
return err
Expand Down

0 comments on commit a690e91

Please sign in to comment.