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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ All notable changes to `src-cli` are documented in this file.

### Added

- Extension publishing will now add a `gitHead` property to the extension's manifest. [#500](https://github.com/sourcegraph/src-cli/pull/500)

### Changed

### Fixed
Expand Down
35 changes: 31 additions & 4 deletions cmd/src/extensions_publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Notes:
var (
extensionIDFlag = flagSet.String("extension-id", "", `Override the extension ID in the manifest. (default: read from -manifest file)`)
urlFlag = flagSet.String("url", "", `Override the URL for the bundle. (example: set to http://localhost:1234/myext.js for local dev with parcel)`)
gitHeadFlag = flagSet.String("git-head", "", "Override the current git commit for the bundle. (default: uses `git rev-parse head`")
manifestFlag = flagSet.String("manifest", "package.json", `The extension manifest file.`)
forceFlag = flagSet.Bool("force", false, `Force publish the extension, even if there are validation problems or other warnings.`)
apiFlags = api.NewFlags(flagSet)
Expand All @@ -59,7 +60,13 @@ Notes:
return err
}

manifest, err := ioutil.ReadFile(*manifestFlag)
manifestPath, err := filepath.Abs(*manifestFlag)
if err != nil {
return err
}
manifestDir := filepath.Dir(manifestPath)

manifest, err := ioutil.ReadFile(manifestPath)
if err != nil {
return fmt.Errorf("%s\n\nRun this command in a directory with a %s file for an extension.\n\nSee 'src extensions %s -h' for help", err, *manifestFlag, flagSet.Name())
}
Expand All @@ -74,7 +81,7 @@ Notes:
if err != nil {
return err
}
manifest, err = addReadmeToManifest(manifest, filepath.Dir(*manifestFlag))
manifest, err = addReadmeToManifest(manifest, manifestDir)
if err != nil {
return err
}
Expand All @@ -87,15 +94,35 @@ Notes:
}
} else {
// Prepare and upload bundle.
if err := runManifestPrepublishScript(manifest, filepath.Dir(*manifestFlag)); err != nil {
if err := runManifestPrepublishScript(manifest, manifestDir); err != nil {
return err
}

var err error
bundle, sourceMap, err = readExtensionArtifacts(manifest, filepath.Dir(*manifestFlag))
bundle, sourceMap, err = readExtensionArtifacts(manifest, manifestDir)
if err != nil {
return err
}
}

if *gitHeadFlag != "" {
manifest, err = updatePropertyInManifest(manifest, "gitHead", *gitHeadFlag)
if err != nil {
return err
}
} else {
command := exec.Command("git", "rev-parse", "head")
command.Dir = manifestDir

out, err := command.CombinedOutput()
if err != nil {
fmt.Printf("failed to determine git head: %q\n", err)
} else {
manifest, err = updatePropertyInManifest(manifest, "gitHead", strings.TrimSpace(string(out)))
if err != nil {
return err
}
}
}

client := cfg.apiClient(apiFlags, flagSet.Output())
Expand Down