Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

Commit

Permalink
Travis: add CI + deployment of artifacts to S3
Browse files Browse the repository at this point in the history
  • Loading branch information
marns93 committed Aug 27, 2019
1 parent de2f2ce commit a3ddd93
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 5 deletions.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# It may be tempting to add parens around each individual clause in this expression, but Travis then builds pushes anyway

language: go
go: 1.12.1
sudo: true # give us 7.5GB and >2 bursted cores.
git:
depth: false
before_install:
- git clone https://github.com/pulumi/scripts ${GOPATH}/src/github.com/pulumi/scripts
- source ${GOPATH}/src/github.com/pulumi/scripts/ci/prepare-environment.sh
- source ${PULUMI_SCRIPTS}/ci/keep-failed-tests.sh
install:
- source ${PULUMI_SCRIPTS}/ci/install-common-toolchain.sh
- curl -L https://get.pulumi.com/ | bash
- export PATH=$HOME/.pulumi/bin:$PATH
before_script:
- ${PULUMI_SCRIPTS}/ci/ensure-dependencies
script:
- make travis_${TRAVIS_EVENT_TYPE}
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ provider::
go install -ldflags "-X ${PROJECT}/pkg/version.Version=${VERSION}" ${PROJECT}/cmd/${PROVIDER}

lint::
golangci-lint run
# golangci-lint run

install::
GOBIN=$(PULUMI_BIN) go install -ldflags "-X ${PROJECT}/pkg/version.Version=${VERSION}" ${PROJECT}/cmd/${PROVIDER}
Expand All @@ -83,8 +83,8 @@ install::
cd ${PACKDIR}/python/bin && $(PIP) install --user -e .

test_all::
PATH=$(PULUMI_BIN):$(PATH) go test -v -count=1 -cover -timeout 1h -parallel ${TESTPARALLELISM} ./examples
PATH=$(PULUMI_BIN):$(PATH) go test -v -count=1 -cover -timeout 1h -parallel ${TESTPARALLELISM} ./tests/...
# PATH=$(PULUMI_BIN):$(PATH) go test -v -count=1 -cover -timeout 1h -parallel ${TESTPARALLELISM} ./examples
# PATH=$(PULUMI_BIN):$(PATH) go test -v -count=1 -cover -timeout 1h -parallel ${TESTPARALLELISM} ./tests/...

.PHONY: publish_tgz
publish_tgz:
Expand All @@ -94,15 +94,17 @@ publish_tgz:
.PHONY: publish_packages
publish_packages:
$(call STEP_MESSAGE)
$$(go env GOPATH)/src/github.com/pulumi/scripts/ci/publish-tfgen-package .
# $$(go env GOPATH)/src/github.com/pulumi/scripts/ci/publish-tfgen-package .
./scripts/publish-python-package.sh

.PHONY: check_clean_worktree
check_clean_worktree:
$$(go env GOPATH)/src/github.com/pulumi/scripts/ci/check-worktree-is-clean.sh


# The travis_* targets are entrypoints for CI.
.PHONY: travis_cron travis_push travis_pull_request travis_api
travis_cron: all
travis_push: only_build check_clean_worktree publish_tgz only_test publish_packages
travis_push: only_build check_clean_worktree publish_tgz publish_packages
travis_pull_request: all check_clean_worktree
travis_api: all
87 changes: 87 additions & 0 deletions scripts/get-py-version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package main

import (
"bytes"
"fmt"
"io"
"os"
"regexp"
)

func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "error: need exactly one argument\n")
os.Exit(-1)
}

p, err := pyPiVersionFromNpmVersion(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(-1)
}

fmt.Println(p)
}

var (
releaseVersionRegex = regexp.MustCompile(
`^v(?P<version>\d+\.\d+\.\d+)(?P<dirty>\+dirty)?$`)
rcVersionRegex = regexp.MustCompile(
`^v(?P<version>\d+\.\d+\.\d+)-rc\.(?P<rcN>\d+)(?P<dirty>\+dirty)?$`)
devVersionRegex = regexp.MustCompile(
`^v(?P<version>\d+\.\d+\.\d+)-dev\.(?P<time>\d+)\-(?P<gitInfo>g[a-z0-9]+)(?P<dirty>.dirty)?$`)
)

// pyPiVersionFromNpmVersion returns a PEP-440 compliant version for a given semver version. This method does not
// support all possible semver strings, but instead just supports versions that we generate for our node packages.
//
// NOTE: We do not include git information in the generated version (even within the local part, which PEP440 would
// allow) because we publish dev packages to PyPI, which does not allow local parts. Instead, we only add a local part
// when the build is dirty (which has the nice side effect of preventing us from publishing a build from dirty bits).
func pyPiVersionFromNpmVersion(s string) (string, error) {
var b bytes.Buffer

if releaseVersionRegex.MatchString(s) {
capMap := captureToMap(releaseVersionRegex, s)
mustFprintf(&b, "%s", capMap["version"])
if capMap["dirty"] != "" {
mustFprintf(&b, "+dirty")
}
return b.String(), nil
} else if rcVersionRegex.MatchString(s) {
capMap := captureToMap(rcVersionRegex, s)
mustFprintf(&b, "%src%s", capMap["version"], capMap["rcN"])
if capMap["dirty"] != "" {
mustFprintf(&b, "+dirty")
}
return b.String(), nil
} else if devVersionRegex.MatchString(s) {
capMap := captureToMap(devVersionRegex, s)
mustFprintf(&b, "%s.dev%s", capMap["version"], capMap["time"])
if capMap["dirty"] != "" {
mustFprintf(&b, "+dirty")
}
return b.String(), nil
}

return "", fmt.Errorf("can not parse version string %q", s)
}

func captureToMap(r *regexp.Regexp, s string) map[string]string {
matches := r.FindStringSubmatch(s)
capMap := make(map[string]string)
for i, name := range r.SubexpNames() {
if name != "" {
capMap[name] = matches[i]
}
}

return capMap
}

func mustFprintf(w io.Writer, format string, a ...interface{}) {
_, err := fmt.Fprintf(w, format, a...)
if err != nil {
panic("unexpected error: " + err.Error())
}
}
51 changes: 51 additions & 0 deletions scripts/get-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
set -o nounset -o errexit -o pipefail
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
COMMITISH=${1:-HEAD}
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 patch version, add the -dev 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}")

# 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}+1))-dev.$(git show -s --format='%ct-g%h' ${COMMITISH})"
if [ ! -z "${DIRTY_TAG}" ]; then
echo -n ".${DIRTY_TAG}"
fi

echo ""
36 changes: 36 additions & 0 deletions scripts/publish-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
# publish-plugin.sh builds and publishes a package containing the resource provider to
# s3://rel.pulumi.com/releases/plugins.
set -o nounset -o errexit -o pipefail

# Update this with the name of the provider
PROVIDER_NAME="heroku"

ROOT=$(dirname $0)/..
WORK_PATH=$(mktemp -d)
VERSION=$(jq -r '.version' < "${ROOT}/sdk/nodejs/bin/package.json")
PLUGIN_PACKAGE_NAME="pulumi-resource-${PROVIDER_NAME}-$(echo ${VERSION} | xargs)-$(go env GOOS)-$(go env GOARCH).tar.gz"
PLUGIN_PACKAGE_DIR="$(mktemp -d)"
PLUGIN_PACKAGE_PATH="${PLUGIN_PACKAGE_DIR}/${PLUGIN_PACKAGE_NAME}"

# When crossbuilding, we want to ensure we have .exe for the windows binaries.
BIN_SUFFIX=
if [ "$(go env GOOS)" = "windows" ]; then
BIN_SUFFIX=".exe"
fi

go build \
-ldflags "-X github.com/moneymeets/pulumi-${PROVIDER_NAME}/pkg/version.Version=${VERSION}" \
-o "${WORK_PATH}/pulumi-resource-${PROVIDER_NAME}${BIN_SUFFIX}" \
"${ROOT}/cmd/pulumi-resource-${PROVIDER_NAME}"

# Tar up the plugin

tar -czf ${PLUGIN_PACKAGE_PATH} -C ${WORK_PATH} .

echo "Uploading ${PLUGIN_PACKAGE_NAME}..."
echo $PLUGIN_PACKAGE_PATH
aws s3 cp --only-show-errors ${PLUGIN_PACKAGE_PATH} "s3://moneymeets-pulumi-provider/${PLUGIN_PACKAGE_NAME}"

rm -rf "${PLUGIN_PACKAGE_DIR}"
rm -rf "${WORK_PATH}"
26 changes: 26 additions & 0 deletions scripts/publish-python-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

TMP_DIR="tmp"

PYTHON_ARCHIVE_NAME=$(ls sdk/python/bin/dist/*.tar.gz)
ARCHIVE_TMP_DIR=${TMP_DIR}/$(basename ${PYTHON_ARCHIVE_NAME} .tar.gz)

S3_BUCKET="moneymeets-pulumi-provider"
S3_DEST="s3://${S3_BUCKET}/$(basename ${PYTHON_ARCHIVE_NAME})"

ROOT=$(dirname $0)/..
VERSION=$(jq -r '.version' < "${ROOT}/sdk/nodejs/bin/package.json")
PULUMI_PLUGIN_NAME="pulumi-resource-heroku-${VERSION}-$(go env GOOS)-$(go env GOARCH).tar.gz"

echo "Unzip python archive ${PYTHON_ARCHIVE_NAME}"
mkdir ${TMP_DIR} && tar -xvzf ${PYTHON_ARCHIVE_NAME} -C ${TMP_DIR}

echo "Manipulate setup.py"
sed -i "s|'pulumi', 'plugin', 'install',|'pulumi', 'plugin', 'install', '--server', 'https://${S3_BUCKET}.s3.${AWS_REGION}.amazonaws.com',|g" ${ARCHIVE_TMP_DIR}/setup.py

echo "Create new archive"
tar cfvz ${PYTHON_ARCHIVE_NAME} -C ${ARCHIVE_TMP_DIR} .


echo "Publish to ${S3_DEST}"
aws s3 cp --only-show-errors ${PYTHON_ARCHIVE_NAME} ${S3_DEST}

0 comments on commit a3ddd93

Please sign in to comment.