diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f1ce00c..fc5ee64 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,6 +57,7 @@ jobs: name: archives path: | **/*.tar.gz + **/dist/mf-manifest.json !node_modules lint: diff --git a/scripts/build-archive/build-archive.go b/scripts/build-archive/build-archive.go index 5bad6a4..c8d7398 100644 --- a/scripts/build-archive/build-archive.go +++ b/scripts/build-archive/build-archive.go @@ -17,7 +17,7 @@ import ( "fmt" "os" "os/exec" - "path" + "path/filepath" "runtime" "github.com/perses/plugins/scripts/npm" @@ -37,16 +37,16 @@ func createArchive(pluginName string, createGroupArchive bool) error { if err != nil { return err } - newArchiveFolder := path.Join(pluginName, pluginName) + newArchiveFolder := filepath.Join(pluginName, pluginName) for _, f := range pluginFiles { - if execErr := exec.Command("cp", "-r", path.Join(pluginName, f), newArchiveFolder).Run(); execErr != nil { + if execErr := exec.Command("cp", "-r", filepath.Join(pluginName, f), newArchiveFolder).Run(); execErr != nil { return fmt.Errorf("unable to copy the file or folder %s: %w", f, execErr) } } // Then let's create the archive with the folder previously created archiveName := fmt.Sprintf("%s-%s.tar.gz", manifest.ID, manifest.Metadata.BuildInfo.Version) - args := []string{"-czvf", path.Join(pluginName, archiveName), "-C", pluginName, pluginName} + args := []string{"-czvf", filepath.Join(pluginName, archiveName), "-C", pluginName, pluginName} // Remove the copyfile metadata on macos if runtime.GOOS == "darwin" { @@ -58,7 +58,7 @@ func createArchive(pluginName string, createGroupArchive bool) error { } if createGroupArchive { - if execErr := exec.Command("cp", path.Join(pluginName, archiveName), path.Join("./plugins-archive", archiveName)).Run(); execErr != nil { + if execErr := exec.Command("cp", filepath.Join(pluginName, archiveName), filepath.Join("./plugins-archive", archiveName)).Run(); execErr != nil { return execErr } } diff --git a/scripts/npm/npm.go b/scripts/npm/npm.go index 3455704..0fb1d36 100644 --- a/scripts/npm/npm.go +++ b/scripts/npm/npm.go @@ -16,7 +16,6 @@ package npm import ( "encoding/json" "os" - "path" "path/filepath" ) @@ -65,7 +64,7 @@ type Manifest struct { } func ReadManifest(pluginPath string) (*Manifest, error) { - manifestFilePath := path.Join(pluginPath, "dist", "mf-manifest.json") + manifestFilePath := filepath.Join(pluginPath, "dist", "mf-manifest.json") data, err := os.ReadFile(manifestFilePath) if err != nil { return nil, err diff --git a/scripts/release/release.go b/scripts/release/release.go index 214c54b..e13eebc 100644 --- a/scripts/release/release.go +++ b/scripts/release/release.go @@ -27,7 +27,8 @@ func release(pluginName string, optionalReleaseMessage string) { if err != nil { logrus.WithError(err).Fatalf("unable to get the version of the plugin %s", pluginName) } - releaseName := fmt.Sprintf("%s-%s", pluginName, version) + // To be compliant with Golang, the tag must be in the format `folder/vX.Y.Z` + releaseName := fmt.Sprintf("%s/v%s", pluginName, version) // ensure the tag does not already exist if execErr := exec.Command("git", "rev-parse", "--verify", releaseName).Run(); execErr == nil { logrus.Infof("release %s already exists", releaseName) @@ -41,22 +42,22 @@ func release(pluginName string, optionalReleaseMessage string) { // Prerequisites for running this script: // - Install the GitHub CLI (gh): https://github.com/cli/cli#installation -// - Use it to login to GitHub: `gh auth login` +// - Use it to log in to GitHub: `gh auth login` // // Usage: -// This will release every plugins that are not yet released +// This will release every plugin not yet released // // go run ./scripts/release/release.go --all // -// This will release only the Tempo plugin +// This will release only the tempo plugin. Note that the `--name` flag is set with the folder name not the plugin name. // -// go run ./scripts/release/release.go --name=Tempo +// go run ./scripts/release/release.go --name=tempo // // Add a release message that will appear in every release // // go run ./scripts/release/release.go --all --message="Release message" // -// NB: this script doesn't handle the plugin archive creation, this is achieved by a CI task. +// NB: this script doesn't handle the plugin archive creation, a CI task achieves this. func main() { releaseAll := flag.Bool("all", false, "release all the plugins") releaseSingleName := flag.String("name", "", "release a single plugin") diff --git a/scripts/upload-archive/upload-archive.go b/scripts/upload-archive/upload-archive.go index 5f87ec3..a93fac1 100644 --- a/scripts/upload-archive/upload-archive.go +++ b/scripts/upload-archive/upload-archive.go @@ -17,23 +17,32 @@ import ( "flag" "fmt" "os/exec" - "path" + "path/filepath" "regexp" + "github.com/perses/plugins/scripts/npm" "github.com/sirupsen/logrus" ) -var tagNamePattern = regexp.MustCompile(`(?m)(.*)-\d.\d.\d`) +var tagNamePattern = regexp.MustCompile(`(?m)(.+)/v(\d.\d.\d)`) func main() { tag := flag.String("tag", "", "Name of the tag") flag.Parse() tagSplitted := tagNamePattern.FindStringSubmatch(*tag) - if len(tagSplitted) != 2 { + if len(tagSplitted) != 3 { logrus.Fatalf("Invalid tag name: %s", *tag) } - pluginName := tagSplitted[1] - if execErr := exec.Command("gh", "release", "upload", *tag, path.Join(pluginName, fmt.Sprintf("%s.tar.gz", *tag))).Run(); execErr != nil { + pluginFolderName := tagSplitted[1] + version := tagSplitted[2] + // The manifest is hopefully uploaded by a previous task in the CI + // It should be available in the plugin folder + manifest, err := npm.ReadManifest(pluginFolderName) + if err != nil { + logrus.WithError(err).Fatalf("unable to read manifest file for plugin %s", pluginFolderName) + } + pluginName := manifest.Name + if execErr := exec.Command("gh", "release", "upload", *tag, filepath.Join(pluginName, fmt.Sprintf("%s-%s.tar.gz", pluginName, version))).Run(); execErr != nil { logrus.WithError(execErr).Fatalf("unable to upload archive %s", pluginName) } }