Skip to content

Deploy project environments and honor explicit project selection - #279

Closed
nathanyoung wants to merge 2 commits into
mainfrom
fix/first-deployment-instructions
Closed

Deploy project environments and honor explicit project selection#279
nathanyoung wants to merge 2 commits into
mainfrom
fix/first-deployment-instructions

Conversation

@nathanyoung

@nathanyoung nathanyoung commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Deploy project environments and honor explicit project selection

Summary

An explicit hx deploy --project web --env production can select the project saved in .hx instead of web. Give the flag precedence over local configuration and bind it to the shared project flag, including -p.

  • Lead deployment help and examples with hx deploy for the configured project's environment of type development, --env for explicit selection, and --project to override the project. Keep positional deployment IDs/alternate IDs supported for existing scripts.
  • Clarify registry/workspace prerequisites, local builds versus uploaded builds, optional Git history for local builds, and explicit preview selection.
  • Add nine selector cases and three local-build cases covering no repository, no commits, and a local commit without a remote. Builder tests use temporary folders, a fake Docker executable, and HTTP mocks.

Rollout

Release this CLI fix before hyphen-app #1553 and public-website #673 start copying and recommending explicit project/environment commands. The previous v0.29.0 baseline is insufficient for the project-override fix. Coordinate the help's Copy CLI command reference with the app action. No engine or nfabric changes; separate registry-selection work is excluded.

Validation

  • go test ./cmd/deploy ./internal/build ./cmd/initialize ./cmd/initapp ./cmd/autoinit ./internal/projects ./internal/deployment ./internal/env passed.
  • CLI build passed; inspected compiled deploy --help, including --project/-p, examples, and positional compatibility guidance.
  • Selector tests verify explicit project precedence, explicit environment IDs/alternate IDs, development type independent of environment name, and legacy positional selection.
  • No real Docker images were built or uploaded. Live cloud acceptance remains pending a disposable non-production target.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the deploy command documentation and examples to clarify deployment selection by ID, alternate ID, or environment, and adds comprehensive unit tests for deployment selection and local builds without GitHub. The feedback highlights two compatibility improvements in the new tests: replacing t.Chdir (introduced in Go 1.24) with os.Chdir to support older Go versions, and checking for the presence of the git binary before executing git commands to prevent test failures in minimal environments.

for _, state := range []string{"no repository", "no commits", "local commit without remote"} {
t.Run(state, func(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

t.Chdir was introduced in Go 1.24. If this project supports or is built with older Go versions (e.g., Go 1.21, 1.22, or 1.23), this will cause compilation errors.

To maintain backward compatibility with older Go versions, you can use os.Chdir combined with t.Cleanup to restore the original working directory.

			oldWd, err := os.Getwd()
			require.NoError(t, err)
			require.NoError(t, os.Chdir(dir))
			t.Cleanup(func() {
				_ = os.Chdir(oldWd)
			})

Comment on lines +35 to +37
if state != "no repository" {
output, err := exec.Command("git", "init", "-q").CombinedOutput()
require.NoError(t, err, string(output))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Running external commands like git directly in tests assumes that the git binary is installed and available in the system's PATH. If git is missing (e.g., in a minimal CI container or some developer environments), the test will fail.

It is safer to check if git is available using exec.LookPath and skip the test state if it is not found.

			if state != "no repository" {
				if _, err := exec.LookPath("git"); err != nil {
					t.Skip("git binary not found, skipping test state")
				}
				output, err := exec.Command("git", "init", "-q").CombinedOutput()
				require.NoError(t, err, string(output))

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the CLI documentation and examples for the deploy command to clarify deployment selection using IDs, alternate IDs, and environment flags. It also introduces unit tests for deployment selection and local builds without GitHub. Feedback was provided regarding the use of t.Chdir in the new build test, which was introduced in Go 1.24 and may cause compilation failures on older Go versions; a backward-compatible alternative using os.Chdir was suggested.

for _, state := range []string{"no repository", "no commits", "local commit without remote"} {
t.Run(state, func(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The t.Chdir method was introduced in Go 1.24. Using it will cause compilation failures on environments running older Go versions (such as Go 1.22 or 1.23), which are still widely used. To ensure backward compatibility and prevent build failures, use os.Chdir combined with a cleanup function to restore the original working directory.

oldWd, err := os.Getwd()
			require.NoError(t, err)
			require.NoError(t, os.Chdir(dir))
			t.Cleanup(func() {
				_ = os.Chdir(oldWd)
			})

@nathanyoung nathanyoung changed the title Clarify deployment selection and local build requirements Deploy project environments and honor explicit project selection Sep 10, 2026
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@3f4d419). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #279   +/-   ##
=======================================
  Coverage        ?   29.59%           
=======================================
  Files           ?       53           
  Lines           ?     5031           
  Branches        ?        0           
=======================================
  Hits            ?     1489           
  Misses          ?     3315           
  Partials        ?      227           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant