Skip to content
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
75 changes: 75 additions & 0 deletions build/manifest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package main
import (
"encoding/json"
"fmt"
"net/url"
"os"
"strings"

"github.com/mattermost/mattermost/server/public/model"
"github.com/pkg/errors"
Expand Down Expand Up @@ -34,6 +36,30 @@ func init() {
}
`

const pluginIDJSFileTemplate = `// Copyright (c) 2020-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

// This file is automatically generated. Do not modify it manually.
// We cannot import plugin.json directly because this manifest is generated at build time
// with values injected from the build (e.g. version from git tags, release notes URL).
// See build/manifest/main.go for the generator.

const manifest = JSON.parse(` + "`" + `
%s
` + "`" + `)

export default manifest
export const id = manifest.id
export const version = manifest.version
`

// These build-time vars are read from shell commands and populated in ../setup.mk
var (
BuildHashShort string
BuildTagLatest string
BuildTagCurrent string
)

func main() {
if len(os.Args) <= 1 {
panic("no cmd specified")
Expand Down Expand Up @@ -92,6 +118,32 @@ func findManifest() (*model.Manifest, error) {
return nil, errors.Wrap(err, "failed to parse manifest")
}

if manifest.Version == "" {
var version string
tags := strings.Fields(BuildTagCurrent)
for _, t := range tags {
if strings.HasPrefix(t, "v") {
version = t
break
}
}
if version == "" {
if BuildTagLatest != "" {
version = BuildTagLatest
} else {
version = "v0.0.0+" + BuildHashShort
}
}
manifest.Version = strings.TrimPrefix(version, "v")
}

if manifest.ReleaseNotesURL == "" && BuildTagLatest != "" {
manifest.ReleaseNotesURL, err = url.JoinPath(manifest.HomepageURL, "releases", "tag", BuildTagLatest)
if err != nil {
return nil, errors.Wrap(err, "failed to generate release notes URL")
}
}

return &manifest, nil
}

Expand Down Expand Up @@ -125,5 +177,28 @@ func applyManifest(manifest *model.Manifest) error {
}
}

if manifest.HasWebapp() {
// generate JSON representation of Manifest.
// JSON is very similar and compatible with JS's object literals. so, what we do here
// is actually JS code generation.
manifestBytes, err := json.MarshalIndent(manifest, "", " ")
if err != nil {
return err
}
manifestStr := string(manifestBytes)

// Escape newlines
manifestStr = strings.ReplaceAll(manifestStr, `\n`, `\\n`)

// write generated code to file by using JS file template.
if err := os.WriteFile(
"webapp/src/manifest.ts",
[]byte(fmt.Sprintf(pluginIDJSFileTemplate, manifestStr)),
0600,
); err != nil {
return errors.Wrap(err, "failed to write webapp/src/manifest.ts")
}
}

return nil
}
7 changes: 6 additions & 1 deletion build/setup.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ ifeq ($(GO),)
$(error "go is not available: see https://golang.org/doc/install")
endif

# Gather build variables to inject into the manifest tool
BUILD_HASH_SHORT = $(shell git rev-parse --short HEAD)
BUILD_TAG_LATEST = $(shell git describe --tags --match 'v*' --abbrev=0 2>/dev/null)
BUILD_TAG_CURRENT = $(shell git tag --points-at HEAD)

# Ensure that the build tools are compiled. Go's caching makes this quick.
$(shell cd build/manifest && $(GO) build -o ../bin/manifest)
$(shell cd build/manifest && $(GO) build -ldflags '-X "main.BuildHashShort=$(BUILD_HASH_SHORT)" -X "main.BuildTagLatest=$(BUILD_TAG_LATEST)" -X "main.BuildTagCurrent=$(BUILD_TAG_CURRENT)"' -o ../bin/manifest)

# Ensure that the deployment tools are compiled. Go's caching makes this quick.
$(shell cd build/pluginctl && $(GO) build -o ../bin/pluginctl)
Expand Down
2 changes: 0 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"description": "The Mattermost Boards plugin",
"homepage_url": "https://github.com/mattermost/mattermost-plugin-boards",
"support_url": "https://github.com/mattermost/mattermost-plugin-boards/issues",
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-boards/releases",
"icon_path": "assets/starter-template-icon.svg",
"version": "9.2.2",
"min_server_version": "10.7.0",
"server": {
"executables": {
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// See LICENSE.txt for license information.


import {version} from './manifest'

import {TelemetryActions} from './telemetry/telemetryClient'

enum Permission {
Expand Down Expand Up @@ -38,7 +40,7 @@ class Constants {
static readonly titleColumnId = '__title'
static readonly badgesColumnId = '__badges'

static readonly versionString = '9.2.2'
static readonly versionString = version

static readonly archiveHelpPage = 'https://docs.mattermost.com/boards/migrate-to-boards.html'
static readonly imports = [
Expand Down
47 changes: 46 additions & 1 deletion webapp/src/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
// Copyright (c) 2020-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import manifest from '../../plugin.json'
// This file is automatically generated. Do not modify it manually.
// We cannot import plugin.json directly because this manifest is generated at build time
// with values injected from the build (e.g. version from git tags, release notes URL).
// See build/manifest/main.go for the generator.

const manifest = JSON.parse(`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whats the reason behind this change. Can you add code comment explaining why we cannot import plugin.json as I think someone will be confused in the future as well.

Copy link
Contributor Author

@Rajat-Dabade Rajat-Dabade Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the comments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it. It's an autogenerated file.

{
"id": "focalboard",
"name": "Mattermost Boards",
"description": "The Mattermost Boards plugin",
"homepage_url": "https://github.com/mattermost/mattermost-plugin-boards",
"support_url": "https://github.com/mattermost/mattermost-plugin-boards/issues",
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-boards/releases/tag/v9.2.2",
"icon_path": "assets/starter-template-icon.svg",
"version": "0.0.0",
"min_server_version": "10.7.0",
"server": {
"executables": {
"darwin-amd64": "server/dist/plugin-darwin-amd64",
"darwin-arm64": "server/dist/plugin-darwin-arm64",
"linux-amd64": "server/dist/plugin-linux-amd64",
"linux-arm64": "server/dist/plugin-linux-arm64",
"windows-amd64": "server/dist/plugin-windows-amd64.exe"
},
"executable": ""
},
"webapp": {
"bundle_path": "webapp/dist/main.js"
},
"settings_schema": {
"header": "",
"footer": "",
"settings": [
{
"key": "EnablePublicSharedBoards",
"display_name": "Enable Publicly-Shared Boards:",
"type": "bool",
"help_text": "This allows board editors to share boards that can be accessed by anyone with the link.",
"placeholder": "",
"default": false,
"hosting": ""
}
]
}
}
`)

export default manifest
export const id = manifest.id
Expand Down
Loading