| // Copyright 2023 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| // integration_update uses jiri to find package and projects updates. |
| package main |
| |
| import ( |
| "context" |
| "encoding/json" |
| "errors" |
| "flag" |
| "fmt" |
| "log" |
| "os" |
| |
| "github.com/google/subcommands" |
| "go.fuchsia.dev/infra/cmd/submodule_update/submodule" |
| ) |
| |
| // integrationUpdateCmd is a subcommand that figure out what has changed in superpoject. |
| type integrationUpdateCmd struct { |
| baseCmd |
| updateConfig updateConfig |
| } |
| |
| // config imported from json input file. |
| type updateConfig struct { |
| SuperprojectRoot string `json:"superproject_path"` |
| JiriProjectsPath string `json:"jiri_projects_path"` |
| } |
| |
| func (*integrationUpdateCmd) Name() string { return "integration_update" } |
| func (*integrationUpdateCmd) Synopsis() string { |
| return "Check integration updates." |
| } |
| func (*integrationUpdateCmd) Usage() string { |
| return "Find what projects and packages changed" |
| } |
| |
| func (p *integrationUpdateCmd) Validate() error { |
| return p.checkSuperproject() |
| } |
| |
| func (p *integrationUpdateCmd) ParseJSON() error { |
| // Read json inputs |
| jsonInputFile, err := os.ReadFile(p.jsonInput) |
| if err != nil { |
| return err |
| } |
| if err := json.Unmarshal(jsonInputFile, &p.updateConfig); err != nil { |
| return err |
| } |
| if p.updateConfig.JiriProjectsPath == "" { |
| return errors.New("jiri projects path is required") |
| } |
| if p.updateConfig.SuperprojectRoot == "" { |
| return errors.New("super project path is required") |
| } |
| return nil |
| } |
| |
| func (p *integrationUpdateCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...any) subcommands.ExitStatus { |
| if err := p.Validate(); err != nil { |
| fmt.Printf("error: %s\n", err) |
| return subcommands.ExitFailure |
| } |
| if err := p.ParseJSON(); err != nil { |
| fmt.Printf("error: %s\n", err) |
| return subcommands.ExitFailure |
| } |
| |
| if err := submodule.UpdateSuperproject( |
| p.updateConfig.JiriProjectsPath, p.jsonOutput, p.updateConfig.SuperprojectRoot, |
| ); err != nil { |
| log.Printf("error: %s", err) |
| return subcommands.ExitFailure |
| } |
| |
| return subcommands.ExitSuccess |
| } |