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
7 changes: 7 additions & 0 deletions action.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,6 +45,13 @@ inputs:
description: 'GitHub token for authenticated registry access'
required: false
default: ${{ github.token }}
registry:
description: >
OCI artifact store used to fetch PHP and extension bundles.
Defaults to ghcr.io/buildrush. Set to oci-layout:<path> to
fetch from a local OCI-layout directory (used by local CI).
required: false
default: ""
outputs:
php-version:
description: 'The installed PHP version'
Expand Down
25 changes: 24 additions & 1 deletion cmd/phpup/main.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ package main
import (
"context"
_ "embed"
"flag"
"fmt"
"log"
"os"
Expand All@@ -29,12 +30,34 @@ import (
//go:embed bundles.lock
var embeddedLockfile []byte

// resolveRegistry picks the registry URI with precedence:
// 1. --registry flag (cliFlag, passed in)
// 2. INPUT_REGISTRY env var (GitHub Actions input convention)
// 3. PHPUP_REGISTRY env var (local/CLI convention)
// 4. default "ghcr.io/buildrush"
func resolveRegistry(cliFlag string) string {
if cliFlag != "" {
return cliFlag
}
if v := os.Getenv("INPUT_REGISTRY"); v != "" {
return v
}
if v := os.Getenv("PHPUP_REGISTRY"); v != "" {
return v
}
return "ghcr.io/buildrush"
}

func main() {
if len(os.Args) > 1 && os.Args[1] == "--version" {
fmt.Printf("phpup %s (%s) built %s\n", version.Version, version.Commit, version.BuildDate)
return
}

registryFlag := flag.String("registry", "",
"OCI artifact store (e.g., ghcr.io/buildrush or oci-layout:./out/oci-layout). Overrides INPUT_REGISTRY / PHPUP_REGISTRY; defaults to ghcr.io/buildrush.")
flag.Parse()

ctx := context.Background()

// 1. Parse inputs
Expand DownExpand Up@@ -136,7 +159,7 @@ func main() {
if token == "" {
token = os.Getenv("GITHUB_TOKEN")
}
registry := "ghcr.io/buildrush"
registry := resolveRegistry(*registryFlag)
client, err := oci.NewClient(registry, token)
if err != nil {
log.Fatalf("create OCI client: %v", err)
Expand Down
39 changes: 39 additions & 0 deletions cmd/phpup/registry_flag_test.go
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
package main

import "testing"

func TestResolveRegistry_FlagBeatsEnv(t *testing.T) {
t.Setenv("INPUT_REGISTRY", "env-input")
t.Setenv("PHPUP_REGISTRY", "env-phpup")
got := resolveRegistry("flag-value")
if got != "flag-value" {
t.Errorf("resolveRegistry flag = %q, want flag-value", got)
}
}

func TestResolveRegistry_InputEnvBeatsPhpupEnv(t *testing.T) {
t.Setenv("INPUT_REGISTRY", "env-input")
t.Setenv("PHPUP_REGISTRY", "env-phpup")
got := resolveRegistry("")
if got != "env-input" {
t.Errorf("resolveRegistry = %q, want env-input", got)
}
}

func TestResolveRegistry_PhpupEnvUsedWhenInputEmpty(t *testing.T) {
t.Setenv("INPUT_REGISTRY", "")
t.Setenv("PHPUP_REGISTRY", "env-phpup")
got := resolveRegistry("")
if got != "env-phpup" {
t.Errorf("resolveRegistry = %q, want env-phpup", got)
}
}

func TestResolveRegistry_DefaultsToGHCR(t *testing.T) {
t.Setenv("INPUT_REGISTRY", "")
t.Setenv("PHPUP_REGISTRY", "")
got := resolveRegistry("")
if got != "ghcr.io/buildrush" {
t.Errorf("resolveRegistry = %q, want ghcr.io/buildrush", got)
}
}
Loading
Loading