Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce perses object in package.json and change the way the archives are created #7

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
name: archives
path: |
**/*.tar.gz
**/mf-manifest.json
!node_modules
lint:
Expand Down Expand Up @@ -67,4 +66,4 @@ jobs:
uses: actions/download-artifact@v4
with:
name: archives
- run: go run ./scripts/upload-archive/upload-archive.go -tag=${{ github.event.release.tag_name }}
- run: go run ./scripts/upload-archive/upload-archive.go -tag=${{ github.event.release.tag_name }}
5 changes: 4 additions & 1 deletion BarChart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
},
"files": [
"dist"
]
],
"perses": {
"pluginType":"panel"
}
}
5 changes: 4 additions & 1 deletion GaugeChart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
},
"files": [
"dist"
]
],
"perses": {
"pluginType":"panel"
}
}
5 changes: 4 additions & 1 deletion MarkdownChart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@
},
"files": [
"dist"
]
],
"perses": {
"pluginType":"panel"
}
}
5 changes: 4 additions & 1 deletion StatChart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
},
"files": [
"dist"
]
],
"perses": {
"pluginType":"panel"
}
}
5 changes: 4 additions & 1 deletion TimeseriesChart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
},
"files": [
"dist"
]
],
"perses": {
"pluginType":"panel"
}
}
26 changes: 14 additions & 12 deletions scripts/build-archive/build-archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,30 @@ import (
"github.com/sirupsen/logrus"
)

var pluginFiles = []string{
"dist/",
"package.json",
"README.md",
}

func createArchive(pluginName string) error {
distPath := path.Join(pluginName, "dist")
manifest, err := npm.ReadManifest(pluginName)
if err != nil {
return err
}
newArchiveFolder := path.Join(pluginName, manifest.ID)
// Let's copy the dist folder just to ensure we have the correct folder name for the archive
if execErr := exec.Command("cp", "-r", distPath, newArchiveFolder).Run(); execErr != nil {
return fmt.Errorf("unable to copy the dist folder to the path %s: %w", newArchiveFolder, execErr)
newArchiveFolder := path.Join(pluginName, "tmp")
for _, f := range pluginFiles {
if execErr := exec.Command("cp", "-r", path.Join(pluginName, f), newArchiveFolder).Run(); execErr != nil {
return fmt.Errorf("unable to copy the folder/file to the path %s: %w", f, execErr)
}
}

// Then let's create the archive with the folder previously created
archiveName := fmt.Sprintf("%s.tar.gz", manifest.ID)
if execErr := exec.Command("tar", "-czvf", path.Join(pluginName, archiveName), newArchiveFolder).Run(); execErr != nil {
archiveName := fmt.Sprintf("%s-%s.tar.gz", manifest.ID, manifest.Metadata.BuildInfo.Version)
if execErr := exec.Command("tar", "-czvf", path.Join(pluginName, archiveName), newArchiveFolder, "--transform", fmt.Sprintf("s/%s\\/tmp/%s/", pluginName, pluginName)).Run(); execErr != nil {
return execErr
}

// Finally, move the archive to the dist folder,
// so it will be straightforward to find it back during the release process.
if execErr := exec.Command("mv", path.Join(pluginName, archiveName), distPath).Run(); execErr != nil {
return execErr
}
return exec.Command("rm", "-rf", newArchiveFolder).Run()
}

Expand Down
14 changes: 12 additions & 2 deletions scripts/npm/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,19 @@ func GetWorkspaces() ([]string, error) {
return pkg.Workspaces, nil
}

type BuildInfo struct {
Version string `json:"buildVersion"`
Name string `json:"buildName"`
}

type Metadata struct {
BuildInfo BuildInfo `json:"buildInfo"`
}

type Manifest struct {
ID string `json:"id"`
Name string `json:"name"`
ID string `json:"id"`
Name string `json:"name"`
Metadata Metadata `json:"metaData"`
}

func ReadManifest(pluginPath string) (*Manifest, error) {
Expand Down
9 changes: 2 additions & 7 deletions scripts/upload-archive/upload-archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"path"
"regexp"

"github.com/perses/perses-plugins/scripts/npm"
"github.com/sirupsen/logrus"
)

Expand All @@ -34,11 +33,7 @@ func main() {
logrus.Fatalf("Invalid tag name: %s", *tag)
}
pluginName := tagSplitted[1]
manifest, err := npm.ReadManifest(pluginName)
if err != nil {
logrus.Fatal(err)
}
if execErr := exec.Command("gh", "release", "upload", *tag, path.Join(pluginName, "dist", fmt.Sprintf("%s.tar.gz", manifest.ID))).Run(); execErr != nil {
logrus.WithError(err).Fatalf("unable to upload archive %s", pluginName)
if execErr := exec.Command("gh", "release", "upload", *tag, path.Join(pluginName, fmt.Sprintf("%s.tar.gz", *tag))).Run(); execErr != nil {
logrus.WithError(execErr).Fatalf("unable to upload archive %s", pluginName)
}
}
Loading