fix(34): WR-01 keep summer build working for frameworks before party.Describe
summer build always emitted party.Describe and []party.Info, so an application whose framework requirement predates v0.6.0 stopped compiling once the CLI was updated. The build now checks the party package go list resolves in the application (a static look for Describe and Info, not a version compare, since a local checkout reports the previous tag until it is tagged) and, when they are missing, writes main.go and plugins.gen.go exactly as before, with a warning to move the framework to v0.6.0. An unresolvable party package keeps the current sources.
This commit is contained in:
@@ -6,6 +6,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -20,8 +23,16 @@ import (
|
||||
type buildMeta struct {
|
||||
Plugins []party.Info
|
||||
Framework string
|
||||
// Legacy is set when the framework the application builds against has
|
||||
// no party.Describe (before v0.6.0): the generated sources then leave
|
||||
// the metadata out, as they did before, so the application still
|
||||
// compiles (WR-01).
|
||||
Legacy bool
|
||||
}
|
||||
|
||||
// partyPackage is the framework package that holds party.Describe.
|
||||
const partyPackage = frameworkModule + "/modules/party"
|
||||
|
||||
// listedPackage is the part of `go list -json` output the metadata step
|
||||
// reads for one plugin package.
|
||||
type listedPackage struct {
|
||||
@@ -84,6 +95,12 @@ func idOnlyMeta(m Manifest) buildMeta {
|
||||
// framework version. It never fails: what it cannot resolve stays empty
|
||||
// and comes back as a warning, so metadata never breaks a build.
|
||||
func resolveBuildMeta(ctx context.Context, appDir string, m Manifest) (buildMeta, []string) {
|
||||
if !frameworkDescribes(ctx, appDir) {
|
||||
fw, _ := EffectiveFramework(ctx, appDir)
|
||||
return buildMeta{Framework: fw, Legacy: true}, []string{fmt.Sprintf(
|
||||
"framework %s has no party.Describe (added in v0.6.0); the generated sources carry no plugin metadata, so the admin's Plugins screen lists plugin IDs only. Update the framework requirement to v0.6.0 or newer to get it.",
|
||||
displayVersion(fw))}
|
||||
}
|
||||
infos, warnings := resolvePluginInfo(ctx, appDir, m)
|
||||
fw, err := EffectiveFramework(ctx, appDir)
|
||||
if err != nil {
|
||||
@@ -92,6 +109,64 @@ func resolveBuildMeta(ctx context.Context, appDir string, m Manifest) (buildMeta
|
||||
return buildMeta{Plugins: infos, Framework: fw}, warnings
|
||||
}
|
||||
|
||||
// frameworkDescribes reports whether the framework the application builds
|
||||
// against provides party.Describe and party.Info: the party package that
|
||||
// go list resolves in appDir (go.mod, its replaces and go.work alike)
|
||||
// declares both. The check is static, not by version, because a local
|
||||
// framework checkout reports the previous tag until it is tagged. When
|
||||
// the package cannot be resolved it answers true: the sources stay the
|
||||
// current ones and go build reports the real problem.
|
||||
func frameworkDescribes(ctx context.Context, appDir string) bool {
|
||||
pkgs, err := listPackages(ctx, appDir, []string{partyPackage})
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
for _, p := range pkgs {
|
||||
if p.ImportPath != partyPackage || p.Dir == "" || p.Error != nil {
|
||||
continue
|
||||
}
|
||||
return declaresDescribe(p.Dir)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// declaresDescribe reports whether the Go package in dir declares the
|
||||
// function Describe and the type Info; a directory it cannot read
|
||||
// answers true.
|
||||
func declaresDescribe(dir string) bool {
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
describe, info := false, false
|
||||
fset := token.NewFileSet()
|
||||
for _, e := range entries {
|
||||
name := e.Name()
|
||||
if e.IsDir() || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
|
||||
continue
|
||||
}
|
||||
f, err := parser.ParseFile(fset, filepath.Join(dir, name), nil, parser.SkipObjectResolution)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, d := range f.Decls {
|
||||
switch d := d.(type) {
|
||||
case *ast.FuncDecl:
|
||||
if d.Recv == nil && d.Name.Name == "Describe" {
|
||||
describe = true
|
||||
}
|
||||
case *ast.GenDecl:
|
||||
for _, spec := range d.Specs {
|
||||
if ts, ok := spec.(*ast.TypeSpec); ok && ts.Name.Name == "Info" {
|
||||
info = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return describe && info
|
||||
}
|
||||
|
||||
// resolvePluginInfo returns one party.Info per summer.yaml plugin, in
|
||||
// manifest order: module and package from go list, name and description
|
||||
// from the plugin's plugin.yaml, and the version per D-07. No filesystem
|
||||
|
||||
Reference in New Issue
Block a user