Deploy project environments and honor explicit project selection - #279
Deploy project environments and honor explicit project selection#279nathanyoung wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
})| if state != "no repository" { | ||
| output, err := exec.Command("git", "init", "-q").CombinedOutput() | ||
| require.NoError(t, err, string(output)) |
There was a problem hiding this comment.
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))There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
})
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Deploy project environments and honor explicit project selection
Summary
An explicit
hx deploy --project web --env productioncan select the project saved in.hxinstead ofweb. Give the flag precedence over local configuration and bind it to the shared project flag, including-p.hx deployfor the configured project's environment of type development,--envfor explicit selection, and--projectto override the project. Keep positional deployment IDs/alternate IDs supported for existing scripts.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/envpassed.deploy --help, including--project/-p, examples, and positional compatibility guidance.