Skip to content

Commit 17370fe

Browse files
authored
fix: don't rely on an environment when self updating (#511)
This was a regression I introduced in #507.
1 parent 2fe0cd2 commit 17370fe

File tree

6 files changed

+28
-17
lines changed

6 files changed

+28
-17
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
on:
22
push:
33
paths-ignore:
4-
- 'docs/**'
4+
- "docs/**"
55
tags:
6-
- 'v*'
6+
- "v*"
77
name: Release
88
jobs:
99
deployable:
@@ -14,7 +14,7 @@ jobs:
1414
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
1515
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
1616
with:
17-
go-version: '^1.16.3'
17+
go-version: "^1.16.3"
1818
- name: Build Hermit
1919
run: |
2020
make GOOS=linux GOARCH=amd64 CHANNEL=stable build

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test-integration: ## run integration tests
2323
./bin/go test -count=1 -tags integration -v ./integration
2424

2525
build: build-binary ## builds binary and gzips it
26-
gzip -9 $(BIN)
26+
gzip -f9 $(BIN)
2727

2828
build-binary: ## builds binary
2929
mkdir -p $(BUILD_DIR)

app/exec_cmd.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (e *execCmd) Run(
5656
if err != nil {
5757
return errors.WithStack(err)
5858
}
59-
err = maybeUpdateHermit(l, env, cli.getSelfUpdate(), false)
59+
err = maybeUpdateHermit(l, sta, cli.getSelfUpdate(), false)
6060
if err != nil {
6161
return errors.WithStack(err)
6262
}
@@ -103,7 +103,9 @@ func (e *execCmd) Run(
103103

104104
// Upgrade hermit if necessary. We do this to ensure we can read the latest versions of manifests, otherwise they
105105
// might have configuration that is unavailable in older versions.
106-
func maybeUpdateHermit(l *ui.UI, env *hermit.Env, selfUpdate bool, force bool) error {
106+
//
107+
// If "selfUpdate" is false this will be a no-op under all circumstances.
108+
func maybeUpdateHermit(l *ui.UI, state *state.State, selfUpdate bool, force bool) error {
107109
if !selfUpdate {
108110
return nil
109111
}
@@ -118,7 +120,7 @@ func maybeUpdateHermit(l *ui.UI, env *hermit.Env, selfUpdate bool, force bool) e
118120
}
119121

120122
l.Tracef("Checking if %s needs to be updated", pkgRef)
121-
pkg, err := env.Resolve(l, manifest.ExactSelector(manifest.ParseReference(pkgRef)), false)
123+
pkg, err := state.Resolve(l, manifest.ExactSelector(manifest.ParseReference(pkgRef)))
122124
if err != nil {
123125
return errors.WithStack(err)
124126
}
@@ -128,7 +130,7 @@ func maybeUpdateHermit(l *ui.UI, env *hermit.Env, selfUpdate bool, force bool) e
128130
} else if pkg.UpdatedAt.IsZero() {
129131
pkg.UpdatedAt = time.Now()
130132
}
131-
err = env.UpdateUsage(pkg)
133+
err = state.WritePackageState(pkg)
132134
if err != nil {
133135
return errors.WithStack(err)
134136
}
@@ -137,5 +139,5 @@ func maybeUpdateHermit(l *ui.UI, env *hermit.Env, selfUpdate bool, force bool) e
137139
// set the update time to 0 to force an update check
138140
pkg.UpdatedAt = time.Time{}
139141
}
140-
return errors.WithStack(env.EnsureChannelIsUpToDate(l, pkg))
142+
return errors.WithStack(state.EnsureChannelIsUpToDate(l, pkg))
141143
}

app/update_cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (s *updateCmd) Run(l *ui.UI, env *hermit.Env, state *state.State, cli cliIn
2424
return errors.WithStack(err)
2525
}
2626
// Upgrade hermit if necessary
27-
err = maybeUpdateHermit(l, env, cli.getSelfUpdate(), true)
27+
err = maybeUpdateHermit(l, state, cli.getSelfUpdate(), true)
2828
if err != nil {
2929
return errors.WithStack(err)
3030
}

env.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,13 +1170,7 @@ func (e *Env) Search(l *ui.UI, pattern string) (manifest.Packages, error) {
11701170
//
11711171
// This should only be called for packages that have already been installed
11721172
func (e *Env) EnsureChannelIsUpToDate(l *ui.UI, pkg *manifest.Package) error {
1173-
task := l.Task(pkg.Reference.String())
1174-
if pkg.UpdateInterval == 0 || pkg.UpdatedAt.After(time.Now().Add(-1*pkg.UpdateInterval)) {
1175-
task.Tracef("No updated required")
1176-
// No updates needed for this package
1177-
return nil
1178-
}
1179-
return errors.WithStack(e.state.UpgradeChannel(task, pkg))
1173+
return errors.WithStack(e.state.EnsureChannelIsUpToDate(l, pkg))
11801174
}
11811175

11821176
// AddSource adds a new source bundle and refreshes the packages from it

state/state.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,21 @@ func (s *State) CleanCache(b ui.Logger) error {
505505
return os.RemoveAll(s.cacheDir)
506506
}
507507

508+
// EnsureChannelIsUpToDate updates the package if it has an update interval,
509+
// the required time since the last update check has passed,
510+
// and the etag in the source has changed from the last check.
511+
//
512+
// This should only be called for packages that have already been installed
513+
func (s *State) EnsureChannelIsUpToDate(l *ui.UI, pkg *manifest.Package) error {
514+
task := l.Task(pkg.Reference.String())
515+
if pkg.UpdateInterval == 0 || pkg.UpdatedAt.After(time.Now().Add(-1*pkg.UpdateInterval)) {
516+
task.Tracef("No updated required")
517+
// No updates needed for this package
518+
return nil
519+
}
520+
return errors.WithStack(s.UpgradeChannel(task, pkg))
521+
}
522+
508523
// UpgradeChannel checks if the given binary has changed in its channel, and if so, downloads it.
509524
//
510525
// If the channel is upgraded this will return a clone of the updated manifest.

0 commit comments

Comments
 (0)