Skip to content

Commit

Permalink
update the way to release to be compliant with golang and submodules (#…
Browse files Browse the repository at this point in the history
…54)

Signed-off-by: Augustin Husson <augustin.husson@amadeus.com>
  • Loading branch information
Nexucis authored Feb 13, 2025
1 parent 18043fe commit 8b643b6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
name: archives
path: |
**/*.tar.gz
**/dist/mf-manifest.json
!node_modules
lint:
Expand Down
10 changes: 5 additions & 5 deletions scripts/build-archive/build-archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"

"github.com/perses/plugins/scripts/npm"
Expand All @@ -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" {
Expand All @@ -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
}
}
Expand Down
3 changes: 1 addition & 2 deletions scripts/npm/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package npm
import (
"encoding/json"
"os"
"path"
"path/filepath"
)

Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions scripts/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
19 changes: 14 additions & 5 deletions scripts/upload-archive/upload-archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 8b643b6

Please sign in to comment.