From f41435d2858a00bf465252aa7f003c74b731bd0e Mon Sep 17 00:00:00 2001 From: Aayush Date: Fri, 17 Feb 2023 14:17:30 -0500 Subject: [PATCH] feat: bundle: only write git tags for newly packed bundles --- gen/bundle/bundle.go | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/gen/bundle/bundle.go b/gen/bundle/bundle.go index d3e5ebf6b..f57ced15b 100644 --- a/gen/bundle/bundle.go +++ b/gen/bundle/bundle.go @@ -1,8 +1,8 @@ package main import ( - "fmt" "os" + "strconv" "strings" "text/template" @@ -40,38 +40,42 @@ func splitOverride(override string) (string, string) { } func main() { + // read metadata from the embedded bundle, includes all info except git tags metadata, err := build.ReadEmbeddedBuiltinActorsMetadata() if err != nil { panic(err) } - var metadataSpecificVersion []*build.BuiltinActorsMetadata - // see ./build/actors/pack.sh - // expected args are: - // $(GOCC) run ./gen/bundle $(VERSION) $(RELEASE) $(RELEASE_OVERRIDES) - // overrides are in the format network_name=override - + // IF args have been provided, extract git tag info from them, otherwise + // rely on previously embedded metadata for git tags. if len(os.Args) > 1 { - version := os.Args[1] + // see ./build/actors/pack.sh + // (optional) expected args are: + // $(GOCC) run ./gen/bundle $(VERSION) $(RELEASE) $(RELEASE_OVERRIDES) + // overrides are in the format network_name=override + gitTag := os.Args[2] + packedActorsVersion, err := strconv.Atoi(os.Args[1][1:]) + if err != nil { + panic(err) + } + overrides := map[string]string{} for _, override := range os.Args[3:] { k, v := splitOverride(override) overrides[k] = v } for _, m := range metadata { - if strings.HasPrefix(version, fmt.Sprintf("v%d", m.Version)) { - // correct version + if int(m.Version) == packedActorsVersion { override, ok := overrides[m.Network] if ok { m.BundleGitTag = override } else { - m.BundleGitTag = os.Args[2] + m.BundleGitTag = gitTag } - metadataSpecificVersion = append(metadataSpecificVersion, m) + } else { + m.BundleGitTag = getOldGitTagFromEmbeddedMetadata(m) } } - metadata = metadataSpecificVersion - } fi, err := os.Create("./build/builtin_actors_gen.go") @@ -85,3 +89,14 @@ func main() { panic(err) } } + +func getOldGitTagFromEmbeddedMetadata(m *build.BuiltinActorsMetadata) string { + for _, v := range build.EmbeddedBuiltinActorsMetadata { + // if we agree on the manifestCid for the previously embedded metadata, use the previously set tag + if m.Version == v.Version && m.Network == v.Network && m.ManifestCid == v.ManifestCid { + return m.BundleGitTag + } + } + + return "" +}