Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e230791b4 | ||
|
|
61eacd00a4 | ||
|
|
62016d9189 | ||
|
|
47f0290652 | ||
|
|
1e41904491 | ||
|
|
b983e601e8 | ||
|
|
04847ebebc | ||
|
|
b60295a7f1 |
@@ -5,70 +5,63 @@ on:
|
||||
tags:
|
||||
- "v*"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag_name:
|
||||
description: 'Tag name for the release (e.g., v1.0.0)'
|
||||
required: true
|
||||
type: string
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE26: 'true'
|
||||
RELEASE_TAG: ${{ github.event.inputs.tag_name || github.ref_name }}
|
||||
|
||||
jobs:
|
||||
build-debian:
|
||||
name: Build Debian 13
|
||||
build-linux-amd64:
|
||||
name: Build Linux amd64
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: debian:13-slim
|
||||
steps:
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
apt-get update && apt-get install -y git golang-go ca-certificates
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.26.3'
|
||||
- name: Build
|
||||
run: go build -v -o gh-repo-bootstrap-linux-debian13-amd64 main.go
|
||||
env:
|
||||
CGO_ENABLED: '0'
|
||||
GOOS: linux
|
||||
GOARCH: amd64
|
||||
run: go build -v -o gh-repo-bootstrap-linux-amd64 main.go
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: gh-repo-bootstrap-linux-debian13-amd64
|
||||
path: gh-repo-bootstrap-linux-debian13-amd64
|
||||
name: gh-repo-bootstrap-linux-amd64
|
||||
path: gh-repo-bootstrap-linux-amd64
|
||||
|
||||
build-arch:
|
||||
name: Build Arch Linux
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: archlinux:latest
|
||||
build-linux-arm64:
|
||||
name: Build Linux arm64
|
||||
runs-on: ubuntu-24.04-arm
|
||||
steps:
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pacman -Syu --noconfirm git go ca-certificates
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.26.3'
|
||||
- name: Build
|
||||
run: go build -v -o gh-repo-bootstrap-linux-arch-amd64 main.go
|
||||
env:
|
||||
CGO_ENABLED: '0'
|
||||
GOOS: linux
|
||||
GOARCH: arm64
|
||||
run: go build -v -o gh-repo-bootstrap-linux-arm64 main.go
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: gh-repo-bootstrap-linux-arch-amd64
|
||||
path: gh-repo-bootstrap-linux-arch-amd64
|
||||
|
||||
build-fedora:
|
||||
name: Build Fedora 44
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: fedora:44
|
||||
steps:
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
dnf install -y git golang ca-certificates
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
- name: Build
|
||||
run: go build -v -o gh-repo-bootstrap-linux-fedora44-amd64 main.go
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: gh-repo-bootstrap-linux-fedora44-amd64
|
||||
path: gh-repo-bootstrap-linux-fedora44-amd64
|
||||
name: gh-repo-bootstrap-linux-arm64
|
||||
path: gh-repo-bootstrap-linux-arm64
|
||||
|
||||
build-windows:
|
||||
name: Build Windows
|
||||
@@ -108,7 +101,11 @@ jobs:
|
||||
|
||||
release:
|
||||
name: Create Release
|
||||
needs: [build-debian, build-arch, build-fedora, build-windows, build-macos]
|
||||
needs:
|
||||
- build-linux-amd64
|
||||
- build-linux-arm64
|
||||
- build-windows
|
||||
- build-macos
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
@@ -125,7 +122,7 @@ jobs:
|
||||
run: |
|
||||
mkdir release-assets
|
||||
find bin-artifacts -type f -exec cp {} release-assets/ \;
|
||||
|
||||
|
||||
cd release-assets
|
||||
echo "## SHA256 Checksums" > ../release_notes.txt
|
||||
echo "" >> ../release_notes.txt
|
||||
@@ -135,14 +132,14 @@ jobs:
|
||||
sha=$(sha256sum "$file" | cut -d' ' -f1)
|
||||
echo "| \`$file\` | \`$sha\` |" >> ../release_notes.txt
|
||||
done
|
||||
|
||||
|
||||
cat ../release_notes.txt
|
||||
|
||||
- name: Create GitHub Release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh release create "${{ github.ref_name }}" \
|
||||
--title "${{ github.ref_name }}" \
|
||||
gh release create "${{ env.RELEASE_TAG }}" \
|
||||
--title "${{ env.RELEASE_TAG }}" \
|
||||
--notes-file release_notes.txt \
|
||||
release-assets/*
|
||||
|
||||
@@ -29,7 +29,9 @@ gh extension install JMR-dev/gh-repo-bootstrap
|
||||
release. You also need:
|
||||
|
||||
- [`pulumi`](https://www.pulumi.com/docs/iac/download-install/) on `PATH`
|
||||
- `gh` already authenticated (`gh auth login`)
|
||||
- `gh` already authenticated (`gh auth login`), or a `GITHUB_TOKEN`
|
||||
exported in the environment — the extension uses `GITHUB_TOKEN`
|
||||
when it is set and otherwise falls back to `gh auth token`
|
||||
|
||||
## Use
|
||||
|
||||
@@ -112,9 +114,11 @@ A single `--config FILE` can describe everything. When `--config`
|
||||
is used, **no other flags are allowed**:
|
||||
|
||||
```toml
|
||||
owner = "JMR-dev"
|
||||
name = "my-new-app"
|
||||
mode = "create" # or "manage", or "data" (default)
|
||||
owner = "JMR-dev"
|
||||
name = "my-new-app"
|
||||
mode = "create" # or "manage", or "data" (default)
|
||||
action = "apply" # or "plan", or "destroy" (default: apply)
|
||||
state_dir = "./state" # optional; overrides the default per-repo state dir
|
||||
|
||||
[repo]
|
||||
visibility = "private"
|
||||
|
||||
@@ -82,6 +82,11 @@ func Run(ctx context.Context, opts *cli.Options) error {
|
||||
if err := os.MkdirAll(stateDir, 0o700); err != nil {
|
||||
return fmt.Errorf("creating state dir: %w", err)
|
||||
}
|
||||
absStateDir, err := filepath.Abs(stateDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("resolving state dir: %w", err)
|
||||
}
|
||||
stateDir = absStateDir
|
||||
|
||||
// --- Auth: prefer caller-supplied GITHUB_TOKEN, else borrow from gh ---
|
||||
if os.Getenv("GITHUB_TOKEN") == "" {
|
||||
@@ -203,7 +208,44 @@ func Run(ctx context.Context, opts *cli.Options) error {
|
||||
default:
|
||||
return fmt.Errorf("unknown action: %s", opts.Action)
|
||||
}
|
||||
return err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if opts.RepoMode == cli.RepoModeCreate && opts.Action == cli.ActionApply {
|
||||
if err := setGitRemoteAndPush(opts.Owner, opts.Repo); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// setGitRemoteAndPush wires the newly created GitHub repo as the "origin"
|
||||
// remote of the current git working tree and pushes all local commits.
|
||||
// If the working directory is not inside a git repo the step is skipped.
|
||||
func setGitRemoteAndPush(owner, repo string) error {
|
||||
if err := execCommand("git", "rev-parse", "--is-inside-work-tree").Run(); err != nil {
|
||||
fmt.Println(">>> Not inside a git repository; skipping remote setup.")
|
||||
return nil
|
||||
}
|
||||
|
||||
remoteURL := fmt.Sprintf("https://github.com/%s/%s.git", owner, repo)
|
||||
fmt.Printf(">>> Setting git remote origin → %s\n", remoteURL)
|
||||
|
||||
if execCommand("git", "remote", "get-url", "origin").Run() == nil {
|
||||
if out, err := execCommand("git", "remote", "set-url", "origin", remoteURL).CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("updating git remote: %s: %w", strings.TrimSpace(string(out)), err)
|
||||
}
|
||||
} else {
|
||||
if out, err := execCommand("git", "remote", "add", "origin", remoteURL).CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("adding git remote: %s: %w", strings.TrimSpace(string(out)), err)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(">>> Pushing local commits to origin...")
|
||||
if out, err := execCommand("git", "push", "-u", "origin", "HEAD").CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("pushing to remote: %s: %w", strings.TrimSpace(string(out)), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// runCreatePrompts asks the user for any missing required --create values
|
||||
|
||||
+235
-25
@@ -40,35 +40,59 @@ func TestHelperProcess(t *testing.T) {
|
||||
}
|
||||
|
||||
command := args[0]
|
||||
if command != "gh" {
|
||||
fmt.Fprintf(os.Stderr, "expected 'gh', got: %s\n", command)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
subCmd := args[1]
|
||||
switch subCmd {
|
||||
case "auth":
|
||||
if len(args) >= 3 && args[2] == "token" {
|
||||
fmt.Print("gh_mock_token\n")
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "unknown auth subcommand\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
case "api":
|
||||
if len(args) >= 3 {
|
||||
path := args[2]
|
||||
switch {
|
||||
case path == "users/octocat":
|
||||
fmt.Print(`{"id":583234}`)
|
||||
case path == "orgs/JMR-dev/teams/release":
|
||||
fmt.Print(`{"id":98765}`)
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "unknown path: %s\n", path)
|
||||
switch command {
|
||||
case "gh":
|
||||
subCmd := args[1]
|
||||
switch subCmd {
|
||||
case "auth":
|
||||
if len(args) >= 3 && args[2] == "token" {
|
||||
fmt.Print("gh_mock_token\n")
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "unknown auth subcommand\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
case "api":
|
||||
if len(args) >= 3 {
|
||||
path := args[2]
|
||||
switch {
|
||||
case path == "users/octocat":
|
||||
fmt.Print(`{"id":583234}`)
|
||||
case path == "orgs/JMR-dev/teams/release":
|
||||
fmt.Print(`{"id":98765}`)
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "unknown path: %s\n", path)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "unknown gh command: %s\n", subCmd)
|
||||
os.Exit(2)
|
||||
}
|
||||
case "git":
|
||||
if os.Getenv("MOCK_GIT_ENABLED") != "1" {
|
||||
fmt.Fprintf(os.Stderr, "git not mocked in this test\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
subCmd := args[1]
|
||||
switch subCmd {
|
||||
case "rev-parse":
|
||||
// success — we're in a mock git repo
|
||||
case "remote":
|
||||
if len(args) >= 3 && args[2] == "get-url" {
|
||||
// Simulate "no origin" by default; set MOCK_GIT_ORIGIN_EXISTS=1 to override.
|
||||
if os.Getenv("MOCK_GIT_ORIGIN_EXISTS") != "1" {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
// add / set-url: exit 0 (success)
|
||||
case "push":
|
||||
// success
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "unknown git subcommand: %s\n", subCmd)
|
||||
os.Exit(2)
|
||||
}
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "unknown command: %s\n", subCmd)
|
||||
fmt.Fprintf(os.Stderr, "unknown command: %s\n", command)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
@@ -81,6 +105,24 @@ func mockExec(command string, args ...string) *exec.Cmd {
|
||||
return cmd
|
||||
}
|
||||
|
||||
// mockExecWithGit is like mockExec but also enables the git mock.
|
||||
func mockExecWithGit(command string, args ...string) *exec.Cmd {
|
||||
cs := []string{"-test.run=TestHelperProcess", "--", command}
|
||||
cs = append(cs, args...)
|
||||
cmd := exec.Command(os.Args[0], cs...)
|
||||
cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1", "MOCK_GIT_ENABLED=1")
|
||||
return cmd
|
||||
}
|
||||
|
||||
// makeRecordingExec wraps a delegate exec function and records every call.
|
||||
func makeRecordingExec(delegate func(string, ...string) *exec.Cmd) (func(string, ...string) *exec.Cmd, *[][]string) {
|
||||
calls := &[][]string{}
|
||||
return func(name string, args ...string) *exec.Cmd {
|
||||
*calls = append(*calls, append([]string{name}, args...))
|
||||
return delegate(name, args...)
|
||||
}, calls
|
||||
}
|
||||
|
||||
// mockStack implements stackInterface.
|
||||
type mockStack struct {
|
||||
setConfigCalls map[string]string
|
||||
@@ -117,6 +159,63 @@ func (m *mockStack) Destroy(ctx context.Context, opts ...optdestroy.Option) (aut
|
||||
return auto.DestroyResult{}, nil
|
||||
}
|
||||
|
||||
// TestRun_RelativeStateDir verifies that a relative state_dir (e.g. "./state"
|
||||
// from a TOML config) does not cause a "state/state" double-path in the
|
||||
// file:// backend URL. Before the fix, upsertStack was called with a relative
|
||||
// file:// URL that Pulumi resolved against its WorkDir, producing the wrong path.
|
||||
func TestRun_RelativeStateDir(t *testing.T) {
|
||||
oldExec := execCommand
|
||||
oldGithubExec := githubapi.ExecCommand
|
||||
oldUpsert := upsertStack
|
||||
execCommand = mockExec
|
||||
githubapi.ExecCommand = mockExec
|
||||
defer func() {
|
||||
execCommand = oldExec
|
||||
githubapi.ExecCommand = oldGithubExec
|
||||
upsertStack = oldUpsert
|
||||
}()
|
||||
|
||||
// Capture the PULUMI_BACKEND_URL env var passed to upsertStack.
|
||||
var capturedBackendURL string
|
||||
mStack := &mockStack{setConfigCalls: make(map[string]string)}
|
||||
upsertStack = func(ctx context.Context, stackName, projectName string, program pulumi.RunFunc, opts ...auto.LocalWorkspaceOption) (stackInterface, error) {
|
||||
// Apply options to a scratch workspace to extract env vars.
|
||||
ws, err := auto.NewLocalWorkspace(ctx, opts...)
|
||||
if err == nil {
|
||||
env := ws.GetEnvVars()
|
||||
capturedBackendURL = env["PULUMI_BACKEND_URL"]
|
||||
}
|
||||
return mStack, nil
|
||||
}
|
||||
|
||||
parent := t.TempDir()
|
||||
oldWd, _ := os.Getwd()
|
||||
_ = os.Chdir(parent)
|
||||
defer os.Chdir(oldWd)
|
||||
|
||||
opts := &cli.Options{
|
||||
Owner: "JMR-dev",
|
||||
Repo: "test-repo",
|
||||
Branch: "main",
|
||||
Action: cli.ActionApply,
|
||||
StateDir: "./state",
|
||||
Environments: []*cli.EnvSpec{{Name: "production"}},
|
||||
}
|
||||
|
||||
oldToken := os.Getenv("GITHUB_TOKEN")
|
||||
os.Setenv("GITHUB_TOKEN", "test-token")
|
||||
defer os.Setenv("GITHUB_TOKEN", oldToken)
|
||||
|
||||
if err := Run(context.Background(), opts); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
want := "file://" + filepath.Join(parent, "state")
|
||||
if capturedBackendURL != want {
|
||||
t.Errorf("PULUMI_BACKEND_URL = %q, want %q", capturedBackendURL, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRun_Apply(t *testing.T) {
|
||||
oldExec := execCommand
|
||||
oldGithubExec := githubapi.ExecCommand
|
||||
@@ -392,3 +491,114 @@ func TestRun_CreateModeInteractive(t *testing.T) {
|
||||
t.Errorf("expected Description to be 'my repo description', got: %v", opts.RepoSettings.Description)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRun_CreateMode_SetsRemoteAndPushes(t *testing.T) {
|
||||
oldExec := execCommand
|
||||
oldGithubExec := githubapi.ExecCommand
|
||||
oldUpsert := upsertStack
|
||||
defer func() {
|
||||
execCommand = oldExec
|
||||
githubapi.ExecCommand = oldGithubExec
|
||||
upsertStack = oldUpsert
|
||||
}()
|
||||
|
||||
githubapi.ExecCommand = mockExec
|
||||
|
||||
recorder, calls := makeRecordingExec(mockExecWithGit)
|
||||
execCommand = recorder
|
||||
|
||||
mStack := &mockStack{setConfigCalls: make(map[string]string)}
|
||||
upsertStack = func(ctx context.Context, stackName, projectName string, program pulumi.RunFunc, opts ...auto.LocalWorkspaceOption) (stackInterface, error) {
|
||||
return mStack, nil
|
||||
}
|
||||
|
||||
stateDir := t.TempDir()
|
||||
oldToken := os.Getenv("GITHUB_TOKEN")
|
||||
os.Setenv("GITHUB_TOKEN", "test-token")
|
||||
defer os.Setenv("GITHUB_TOKEN", oldToken)
|
||||
|
||||
desc := "test repo"
|
||||
opts := &cli.Options{
|
||||
Owner: "JMR-dev",
|
||||
Repo: "new-repo",
|
||||
Branch: "main",
|
||||
Action: cli.ActionApply,
|
||||
RepoMode: cli.RepoModeCreate,
|
||||
StateDir: stateDir,
|
||||
RepoSettings: cli.RepoSettings{
|
||||
Visibility: "private",
|
||||
Description: &desc,
|
||||
},
|
||||
}
|
||||
|
||||
if err := Run(context.Background(), opts); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
// Verify the expected git command sequence was issued.
|
||||
wantRemoteURL := "https://github.com/JMR-dev/new-repo.git"
|
||||
checkCmd := func(want []string) {
|
||||
t.Helper()
|
||||
for _, c := range *calls {
|
||||
if len(c) == len(want) {
|
||||
match := true
|
||||
for i := range want {
|
||||
if c[i] != want[i] {
|
||||
match = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if match {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Errorf("expected command %v not found in recorded calls: %v", want, *calls)
|
||||
}
|
||||
|
||||
checkCmd([]string{"git", "rev-parse", "--is-inside-work-tree"})
|
||||
checkCmd([]string{"git", "remote", "get-url", "origin"})
|
||||
checkCmd([]string{"git", "remote", "add", "origin", wantRemoteURL})
|
||||
checkCmd([]string{"git", "push", "-u", "origin", "HEAD"})
|
||||
}
|
||||
|
||||
func TestRun_NonCreateMode_NoRemoteSetup(t *testing.T) {
|
||||
oldExec := execCommand
|
||||
oldUpsert := upsertStack
|
||||
defer func() {
|
||||
execCommand = oldExec
|
||||
upsertStack = oldUpsert
|
||||
}()
|
||||
|
||||
recorder, calls := makeRecordingExec(mockExec)
|
||||
execCommand = recorder
|
||||
|
||||
mStack := &mockStack{setConfigCalls: make(map[string]string)}
|
||||
upsertStack = func(ctx context.Context, stackName, projectName string, program pulumi.RunFunc, opts ...auto.LocalWorkspaceOption) (stackInterface, error) {
|
||||
return mStack, nil
|
||||
}
|
||||
|
||||
stateDir := t.TempDir()
|
||||
oldToken := os.Getenv("GITHUB_TOKEN")
|
||||
os.Setenv("GITHUB_TOKEN", "test-token")
|
||||
defer os.Setenv("GITHUB_TOKEN", oldToken)
|
||||
|
||||
opts := &cli.Options{
|
||||
Owner: "JMR-dev",
|
||||
Repo: "existing-repo",
|
||||
Branch: "main",
|
||||
Action: cli.ActionApply,
|
||||
RepoMode: cli.RepoModeData,
|
||||
StateDir: stateDir,
|
||||
}
|
||||
|
||||
if err := Run(context.Background(), opts); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
for _, c := range *calls {
|
||||
if len(c) > 0 && c[0] == "git" {
|
||||
t.Errorf("expected no git commands for non-create mode, got: %v", c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user