|
|
|
@ -941,9 +941,8 @@ func (pkg *pkgContext) genConfig(w io.Writer, variables []*schema.Property) erro
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (pkg *pkgContext) genPackageRegistration(w io.Writer) {
|
|
|
|
|
fmt.Fprintf(w, "func init() {\n")
|
|
|
|
|
fmt.Fprintf(w, "\tpulumi.RegisterPackage(pulumi.PackageInfo{Name:\"%s\", Version:\"%s\"})\n", pkg.pkg.Name, pkg.pkg.Version.String())
|
|
|
|
|
fmt.Fprintf(w, "}\n")
|
|
|
|
|
fmt.Fprintf(w, pulumiManifest, pkg.pkg.Name)
|
|
|
|
|
fmt.Fprint(w, getVersionBash)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (pkg *pkgContext) getPkg(mod string) *pkgContext {
|
|
|
|
@ -1199,7 +1198,16 @@ func GeneratePackage(tool string, pkg *schema.Package) (map[string][]byte, error
|
|
|
|
|
if registerPackage {
|
|
|
|
|
buffer := &bytes.Buffer{}
|
|
|
|
|
|
|
|
|
|
pkg.genHeader(buffer, []string{"github.com/pulumi/pulumi/sdk/go/pulumi"}, nil)
|
|
|
|
|
pkg.genHeader(buffer, []string{
|
|
|
|
|
"errors",
|
|
|
|
|
"io/ioutil",
|
|
|
|
|
"os",
|
|
|
|
|
"os/exec",
|
|
|
|
|
"path/filepath",
|
|
|
|
|
"runtime",
|
|
|
|
|
"",
|
|
|
|
|
"github.com/pulumi/pulumi/sdk/go/pulumi",
|
|
|
|
|
}, nil)
|
|
|
|
|
pkg.genPackageRegistration(buffer)
|
|
|
|
|
|
|
|
|
|
setFile(path.Join(mod, "pulumiManifest.go"), buffer.String())
|
|
|
|
@ -1258,3 +1266,131 @@ func getEnvOrDefault(def interface{}, parser envParser, vars ...string) interfac
|
|
|
|
|
return def
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
const pulumiManifest = `
|
|
|
|
|
func init() {
|
|
|
|
|
version, err := getVersion()
|
|
|
|
|
if err != nil || version == "" {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
pulumi.RegisterPackage(pulumi.PackageInfo{Name: "%s", Version: version})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getVersion() (string, error) {
|
|
|
|
|
// TODO support windows plugin acquisition
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
return "", errors.New("automatic windows plugin acquisition is unsupported at this time")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// write out get version script to a tmp file, execute it to acquire version
|
|
|
|
|
f, err := ioutil.TempFile("", "get-version")
|
|
|
|
|
defer f.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
_, err = f.WriteString(getVersionBash)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// determine location of this file
|
|
|
|
|
_, filename, _, ok := runtime.Caller(1)
|
|
|
|
|
if !ok {
|
|
|
|
|
return "", errors.New("cannot determine location of pulumiManifest.go")
|
|
|
|
|
}
|
|
|
|
|
execDir := filepath.Join(filename, "..")
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command("/bin/bash", f.Name(), "HEAD")
|
|
|
|
|
cmd.Dir = execDir
|
|
|
|
|
cmd.Env = os.Environ()
|
|
|
|
|
|
|
|
|
|
stdout, err := cmd.Output()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
return string(stdout), nil
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
const getVersionBash = `
|
|
|
|
|
const getVersionBash = ` + "`" + `
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
set -o nounset -o errexit -o pipefail
|
|
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
|
echo "No arguments provided. Pass appropriate git commit-ish value get version of (i.e. 'HEAD')"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
COMMITISH=$1
|
|
|
|
|
DIRTY_TAG=""
|
|
|
|
|
|
|
|
|
|
# Figure out if the worktree is dirty, we run update-index first
|
|
|
|
|
# as we've seen cases in Travis where not doing so causes git to
|
|
|
|
|
# treat the worktree as dirty when it is not.
|
|
|
|
|
git update-index -q --refresh
|
|
|
|
|
if ! git diff-files --quiet; then
|
|
|
|
|
DIRTY_TAG="dirty"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# If we have an exact tag, just use it.
|
|
|
|
|
if git describe --tags --exact-match "${COMMITISH}" >/dev/null 2>&1; then
|
|
|
|
|
echo -n "$(git describe --tags --exact-match "${COMMITISH}")"
|
|
|
|
|
if [ ! -z "${DIRTY_TAG}" ]; then
|
|
|
|
|
echo -n "+${DIRTY_TAG}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Otherwise, increment the minor version version (if the package is 1.X or later) or the
|
|
|
|
|
# patch version (if the package is pre 1.0), add the -alpha tag and some
|
|
|
|
|
# commit metadata. If there's no existing tag, pretend a v0.0.0 was
|
|
|
|
|
# there so we'll produce v0.0.1-dev builds.
|
|
|
|
|
if git describe --tags --abbrev=0 "${COMMITISH}" > /dev/null 2>&1; then
|
|
|
|
|
TAG=$(git describe --tags --abbrev=0 "${COMMITISH}")
|
|
|
|
|
else
|
|
|
|
|
TAG="v0.0.0"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Strip off any pre-release tag we might have (e.g. from doing a -rc build)
|
|
|
|
|
TAG=${TAG%%-*}
|
|
|
|
|
|
|
|
|
|
MAJOR=$(cut -d. -f1 <<< "${TAG}")
|
|
|
|
|
MINOR=$(cut -d. -f2 <<< "${TAG}")
|
|
|
|
|
PATCH=$(cut -d. -f3 <<< "${TAG}")
|
|
|
|
|
|
|
|
|
|
if [ "${MAJOR}" = "v0" ]; then
|
|
|
|
|
PATCH=$((${PATCH}+1))
|
|
|
|
|
else
|
|
|
|
|
MINOR=$((${MINOR}+1))
|
|
|
|
|
PATCH=0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# if we're in a features/xxx branch and caller passed --embed-feature-branch then append "-xxx" to
|
|
|
|
|
# the version as well.
|
|
|
|
|
FEATURE_TAG=""
|
|
|
|
|
for arg in "$@"
|
|
|
|
|
do
|
|
|
|
|
if [[ "$arg" == "--embed-feature-branch" ]]; then
|
|
|
|
|
if [[ "${TRAVIS_BRANCH:-}" == features/* ]]; then
|
|
|
|
|
FEATURE_TAG=$(echo "${TRAVIS_BRANCH}" | sed -e 's|^features/|-|g')
|
|
|
|
|
fi
|
|
|
|
|
if [[ "${TRAVIS_BRANCH:-}" == feature-* ]]; then
|
|
|
|
|
FEATURE_TAG=$(echo "${TRAVIS_BRANCH}")
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# We want to include some additional information. To the base tag we
|
|
|
|
|
# add a timestamp and commit hash. We use the timestamp of the commit
|
|
|
|
|
# itself, not the date it was authored (so it will change when someone
|
|
|
|
|
# rebases a PR into master, for example).
|
|
|
|
|
echo -n "${MAJOR}.${MINOR}.${PATCH}-alpha${FEATURE_TAG}.$(git show -s --format='%ct+g%h' ${COMMITISH})"
|
|
|
|
|
if [ ! -z "${DIRTY_TAG}" ]; then
|
|
|
|
|
echo -n ".${DIRTY_TAG}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
` + "`" + `
|
|
|
|
|
`
|
|
|
|
|