Files
lpm/workflow/update.go
zeekay 7d7127a687 deps: update to latest luxfi packages
- Update node v1.16.15 → v1.19.8
- Update crypto v1.17.0 → v1.17.4
- Update database v1.2.0 → v1.2.1
- Update geth v1.16.34 → v1.16.35
- Update ids v1.1.0 → v1.1.1
- Update Go 1.25 → 1.25.1
- Update copyright year to 2025
2025-09-30 00:05:18 +00:00

90 lines
2.1 KiB
Go

// Copyright (C) 2019-2025, Lux Partners Limited. All rights reserved.
// See the file LICENSE for licensing terms.
package workflow
import (
"fmt"
"path/filepath"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/spf13/afero"
"github.com/luxfi/lpm/git"
"github.com/luxfi/lpm/state"
"github.com/luxfi/lpm/util"
)
var _ Workflow = &Update{}
type UpdateConfig struct {
Executor Executor
TmpPath string
PluginPath string
Installer Installer
RepositoriesPath string
Auth http.BasicAuth
RepoFactory state.RepositoryFactory
Fs afero.Fs
StateFile state.File
Git git.Factory
}
func NewUpdate(config UpdateConfig) *Update {
return &Update{
executor: config.Executor,
tmpPath: config.TmpPath,
pluginPath: config.PluginPath,
installer: config.Installer,
repositoriesPath: config.RepositoriesPath,
auth: config.Auth,
repoFactory: config.RepoFactory,
fs: config.Fs,
stateFile: config.StateFile,
git: config.Git,
}
}
type Update struct {
executor Executor
installer Installer
auth http.BasicAuth
tmpPath string
pluginPath string
repositoriesPath string
repoFactory state.RepositoryFactory
fs afero.Fs
git git.Factory
stateFile state.File
}
func (u Update) Execute() error {
updated := 0
fmt.Printf("Checking for updates...\n")
for alias, sourceInfo := range u.stateFile.Sources {
organization, repo := util.ParseAlias(alias)
previousCommit := sourceInfo.Commit
repositoryPath := filepath.Join(u.repositoriesPath, organization, repo)
latestCommit, err := u.git.GetRepository(sourceInfo.URL, repositoryPath, sourceInfo.Branch, &u.auth)
if err != nil {
return err
}
if latestCommit != previousCommit {
fmt.Printf("Updated definitions for %s@%s.\n", alias, latestCommit)
updated++
}
u.stateFile.Sources[alias].Commit = latestCommit
}
if updated == 0 {
fmt.Printf("All repositories are already up-to-date.\n")
}
return nil
}