2026-07-24 12:52:01 -04:00
|
|
|
package main
|
2026-03-18 12:19:54 -04:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ReleaseExecutor handles dangerous write/mutating operations
|
|
|
|
|
// that should be skipped in dry-run mode. Only actions that
|
|
|
|
|
// modify the git repo or trigger external side effects belong
|
|
|
|
|
// here. Safe operations (file writes, fetches, editor) are
|
|
|
|
|
// called directly.
|
|
|
|
|
type ReleaseExecutor interface {
|
|
|
|
|
// TriggerWorkflow dispatches the release.yaml GitHub Actions
|
2026-11-15 19:54:29 -05:00
|
|
|
// workflow on branch with the given inputs. The workflow creates
|
|
|
|
|
// the release tag at commit once its release environment is
|
|
|
|
|
// approved: only the release GitHub App may create tags.
|
|
|
|
|
TriggerWorkflow(ctx context.Context, branch, version, commit, channel, releaseNotes string) error
|
2026-03-18 12:19:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// liveExecutor performs real operations.
|
|
|
|
|
type liveExecutor struct{}
|
|
|
|
|
|
2026-11-15 19:54:29 -05:00
|
|
|
func (*liveExecutor) TriggerWorkflow(_ context.Context, branch, version, commit, channel, releaseNotes string) error {
|
2026-03-18 12:19:54 -04:00
|
|
|
payload := map[string]string{
|
|
|
|
|
"dry_run": "false",
|
|
|
|
|
"release_channel": channel,
|
|
|
|
|
"release_notes": releaseNotes,
|
2026-11-15 19:54:29 -05:00
|
|
|
"version": version,
|
|
|
|
|
"commit": commit,
|
2026-03-18 12:19:54 -04:00
|
|
|
}
|
|
|
|
|
payloadJSON, err := json.Marshal(payload)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return xerrors.Errorf("marshaling workflow payload: %w", err)
|
|
|
|
|
}
|
|
|
|
|
cmd := exec.Command("gh", "workflow", "run", "release.yaml",
|
|
|
|
|
"--repo", owner+"/"+repo,
|
2026-11-15 19:54:29 -05:00
|
|
|
"--ref", branch,
|
2026-03-18 12:19:54 -04:00
|
|
|
"--json",
|
|
|
|
|
)
|
|
|
|
|
cmd.Stdin = strings.NewReader(string(payloadJSON))
|
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
return cmd.Run()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// dryRunExecutor prints what would happen without doing it.
|
|
|
|
|
type dryRunExecutor struct {
|
|
|
|
|
w io.Writer
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-15 19:54:29 -05:00
|
|
|
func (e *dryRunExecutor) TriggerWorkflow(_ context.Context, branch, version, commit, channel, _ string) error {
|
|
|
|
|
_, _ = fmt.Fprintf(e.w, "[DRYRUN] would trigger release.yaml workflow (ref=%s, version=%s, commit=%s, channel=%s)\n", branch, version, commit, channel)
|
2026-03-18 12:19:54 -04:00
|
|
|
return nil
|
|
|
|
|
}
|