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

releaseCmd: define additional variables #228

Merged
merged 1 commit into from
Feb 26, 2019
Merged
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
32 changes: 21 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,34 +174,35 @@ number. This is a soft requirement and can be skipped by specifying the
}
}

return doPublish(pkg)
_, err = doPublish(pkg)
return err
},
}

func doPublish(pkg *gx.Package) error {
func doPublish(pkg *gx.Package) (string, error) {
if !pm.ShellOnline() {
return fmt.Errorf("ipfs daemon isn't running")
return "", fmt.Errorf("ipfs daemon isn't running")
}

err := gx.TryRunHook("pre-publish", pkg.Language, pkg.SubtoolRequired)
if err != nil {
return err
return "", err
}

hash, err := pm.PublishPackage(cwd, &pkg.PackageBase)
if err != nil {
return fmt.Errorf("publishing: %s", err)
return hash, fmt.Errorf("publishing: %s", err)
}
log.Log("package %s published with hash: %s", pkg.Name, hash)

// write out version hash
err = writeLastPub(pkg.Version, hash)
if err != nil {
return err
return hash, err
}

err = gx.TryRunHook("post-publish", pkg.Language, pkg.SubtoolRequired, hash)
return err
return hash, err
}

func writeLastPub(vers string, hash string) error {
Expand Down Expand Up @@ -1310,12 +1311,12 @@ var ReleaseCommand = cli.Command{
}

fmt.Printf("publishing package...\r")
err = doPublish(pkg)
hash, err := doPublish(pkg)
if err != nil {
return err
}

return runRelease(pkg)
return runRelease(pkg, hash)
},
}

Expand Down Expand Up @@ -1351,13 +1352,22 @@ var TestCommand = cli.Command{
},
}

func runRelease(pkg *gx.Package) error {
func runRelease(pkg *gx.Package, hash string) error {
if pkg.ReleaseCmd == "" {
return nil
}

cmd := exec.Command("sh", "-c", pkg.ReleaseCmd)
cmd.Env = append(os.Environ(), "VERSION="+pkg.Version)
cmd.Env = append(
os.Environ(),
"VERSION="+pkg.Version, // deprecated.
"GX_VERSION="+pkg.Version,
"GX_NAME="+pkg.Name,
"GX_LANGUAGE="+pkg.Language,
"GX_LICENSE="+pkg.License,
"GX_AUTHOR="+pkg.Author,
"GX_HASH="+hash,
)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
Expand Down