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
18 changes: 10 additions & 8 deletions pkg/workflow/action_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ func (m ActionMode) UsesExternalActions() bool {
}

// DetectActionMode determines the appropriate action mode based on the release flag.
// Returns ActionModeRelease if this binary was built as a release (controlled by the
// isReleaseBuild flag set via -X linker flag at build time), otherwise returns ActionModeDev.
// Can be overridden with GH_AW_ACTION_MODE environment variable or GitHub Actions context.
// Returns ActionModeAction if this binary was built as a release (controlled by the
// isReleaseBuild flag set via -X linker flag at build time), or when running in a
// GitHub Actions release context (release tags, release branches, or release events).
// Returns ActionModeDev for all other cases (PRs, feature branches, local development).
// Can be overridden with GH_AW_ACTION_MODE environment variable.
// The version parameter is kept for backward compatibility but is no longer used for detection.
func DetectActionMode(version string) ActionMode {
actionModeLog.Printf("Detecting action mode: version=%s, isRelease=%v", version, IsRelease())
Expand All @@ -82,24 +84,24 @@ func DetectActionMode(version string) ActionMode {
// Check if this binary was built as a release using the release flag
// This flag is set at build time via -X linker flag and does not rely on version string heuristics
if IsRelease() {
actionModeLog.Printf("Detected release mode from build flag (isReleaseBuild=true)")
return ActionModeRelease
actionModeLog.Printf("Detected action mode from build flag (isReleaseBuild=true)")
return ActionModeAction
}

// Check GitHub Actions context for additional hints
githubRef := os.Getenv("GITHUB_REF")
githubEventName := os.Getenv("GITHUB_EVENT_NAME")
actionModeLog.Printf("GitHub context: ref=%s, event=%s", githubRef, githubEventName)

// Release mode conditions from GitHub Actions context:
// Conditions that return ActionModeAction from GitHub Actions context:
// 1. Running on a release branch (refs/heads/release*)
// 2. Running on a release tag (refs/tags/*)
// 3. Running on a release event
if strings.HasPrefix(githubRef, "refs/heads/release") ||
strings.HasPrefix(githubRef, "refs/tags/") ||
githubEventName == "release" {
actionModeLog.Printf("Detected release mode from GitHub context: ref=%s, event=%s", githubRef, githubEventName)
return ActionModeRelease
actionModeLog.Printf("Detected action mode from GitHub context: ref=%s, event=%s", githubRef, githubEventName)
return ActionModeAction
}

// Default to dev mode for all other cases:
Expand Down
20 changes: 10 additions & 10 deletions pkg/workflow/compiler_action_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ func TestActionModeDetection(t *testing.T) {
name: "release tag",
githubRef: "refs/tags/v1.0.0",
githubEvent: "push",
expectedMode: ActionModeRelease,
description: "Release tags should use release mode",
expectedMode: ActionModeAction,
description: "Release tags should use action mode",
},
{
name: "release branch",
githubRef: "refs/heads/release-1.0",
githubEvent: "push",
expectedMode: ActionModeRelease,
description: "Release branches should use release mode",
expectedMode: ActionModeAction,
description: "Release branches should use action mode",
},
{
name: "release event",
githubRef: "refs/heads/main",
githubEvent: "release",
expectedMode: ActionModeRelease,
description: "Release events should use release mode",
expectedMode: ActionModeAction,
description: "Release events should use action mode",
},
{
name: "pull request",
Expand Down Expand Up @@ -173,8 +173,8 @@ func TestActionModeDetectionWithReleaseFlag(t *testing.T) {
isRelease: true,
githubRef: "",
githubEvent: "",
expectedMode: ActionModeRelease,
description: "Release flag set to true should use release mode",
expectedMode: ActionModeAction,
description: "Release flag set to true should use action mode",
},
{
name: "release flag false",
Expand All @@ -189,15 +189,15 @@ func TestActionModeDetectionWithReleaseFlag(t *testing.T) {
isRelease: true,
githubRef: "refs/heads/main",
githubEvent: "push",
expectedMode: ActionModeRelease,
expectedMode: ActionModeAction,
description: "Release flag should take precedence over branch",
},
{
name: "release flag false with release tag",
isRelease: false,
githubRef: "refs/tags/v1.0.0",
githubEvent: "push",
expectedMode: ActionModeRelease,
expectedMode: ActionModeAction,
description: "GitHub release tag should still work when release flag is false",
},
{
Expand Down
Loading