Skip to content

Commit

Permalink
feat: bundle: only write git tags for newly packed bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Feb 17, 2023
1 parent 4dedced commit f41435d
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions gen/bundle/bundle.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"fmt"
"os"
"strconv"
"strings"
"text/template"

Expand Down Expand Up @@ -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")
Expand All @@ -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 ""
}

0 comments on commit f41435d

Please sign in to comment.