Skip to content

Commit 1bdc8a9

Browse files
authored
Add gitHead to extension manifest (#500)
1 parent 251374e commit 1bdc8a9

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ All notable changes to `src-cli` are documented in this file.
1313

1414
### Added
1515

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

1820
### Fixed

cmd/src/extensions_publish.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Notes:
4949
var (
5050
extensionIDFlag = flagSet.String("extension-id", "", `Override the extension ID in the manifest. (default: read from -manifest file)`)
5151
urlFlag = flagSet.String("url", "", `Override the URL for the bundle. (example: set to http://localhost:1234/myext.js for local dev with parcel)`)
52+
gitHeadFlag = flagSet.String("git-head", "", "Override the current git commit for the bundle. (default: uses `git rev-parse head`")
5253
manifestFlag = flagSet.String("manifest", "package.json", `The extension manifest file.`)
5354
forceFlag = flagSet.Bool("force", false, `Force publish the extension, even if there are validation problems or other warnings.`)
5455
apiFlags = api.NewFlags(flagSet)
@@ -59,7 +60,13 @@ Notes:
5960
return err
6061
}
6162

62-
manifest, err := ioutil.ReadFile(*manifestFlag)
63+
manifestPath, err := filepath.Abs(*manifestFlag)
64+
if err != nil {
65+
return err
66+
}
67+
manifestDir := filepath.Dir(manifestPath)
68+
69+
manifest, err := ioutil.ReadFile(manifestPath)
6370
if err != nil {
6471
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())
6572
}
@@ -74,7 +81,7 @@ Notes:
7481
if err != nil {
7582
return err
7683
}
77-
manifest, err = addReadmeToManifest(manifest, filepath.Dir(*manifestFlag))
84+
manifest, err = addReadmeToManifest(manifest, manifestDir)
7885
if err != nil {
7986
return err
8087
}
@@ -87,15 +94,35 @@ Notes:
8794
}
8895
} else {
8996
// Prepare and upload bundle.
90-
if err := runManifestPrepublishScript(manifest, filepath.Dir(*manifestFlag)); err != nil {
97+
if err := runManifestPrepublishScript(manifest, manifestDir); err != nil {
9198
return err
9299
}
93100

94101
var err error
95-
bundle, sourceMap, err = readExtensionArtifacts(manifest, filepath.Dir(*manifestFlag))
102+
bundle, sourceMap, err = readExtensionArtifacts(manifest, manifestDir)
103+
if err != nil {
104+
return err
105+
}
106+
}
107+
108+
if *gitHeadFlag != "" {
109+
manifest, err = updatePropertyInManifest(manifest, "gitHead", *gitHeadFlag)
96110
if err != nil {
97111
return err
98112
}
113+
} else {
114+
command := exec.Command("git", "rev-parse", "head")
115+
command.Dir = manifestDir
116+
117+
out, err := command.CombinedOutput()
118+
if err != nil {
119+
fmt.Printf("failed to determine git head: %q\n", err)
120+
} else {
121+
manifest, err = updatePropertyInManifest(manifest, "gitHead", strings.TrimSpace(string(out)))
122+
if err != nil {
123+
return err
124+
}
125+
}
99126
}
100127

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

0 commit comments

Comments
 (0)