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
49 changes: 26 additions & 23 deletions .circle/deployment
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,38 @@ fi

# TODO: figure out how to make deploy.py rebuild the index.
# python ~/packs/.circle/deploy.py pack.yaml "${CIRCLE_PROJECT_REPONAME}"

# Clean up so the script can be retries in case of failure (e.g. race)
rm -rf ~/index
git clone https://${MACHINE_USER}:${MACHINE_PASSWORD}@github.com/StackStorm-Exchange/index ~/index 2>/dev/null

echo "Processing pack ${PACK_NAME}"

# NOTE: We create tags before re-building the index to ensure latest tag is reflected in the index

# Create version tags
METADATA_CHANGES=$(git rev-list --all --no-abbrev --remove-empty -- pack.yaml)
for COMMIT in $(echo $METADATA_CHANGES)
do
git checkout ${COMMIT} pack.yaml > /dev/null
VERSION=$(~/virtualenv/bin/python ~/ci/.circle/semver.py pack.yaml 2>/dev/null || true)

# 1. Create a tag if version is specified and tag doesn't exist locally
if [[ ${VERSION} ]] && [[ -z $(git rev-parse -q --verify "refs/tags/v${VERSION}") ]]
then
echo "Creating tag ${VERSION} for commit ${COMMIT}"
git tag v${VERSION} ${COMMIT}
fi

# 2. If version is specified and tag doesn't exist on the remote, push it
if [[ ${VERSION} ]] && [[ -z $(git ls-remote origin "refs/tags/v${VERSION}") ]]
then
echo "Pushing tag v${VERSION} to origin remote"
git push origin v${VERSION}
fi
done

# Rebuild pack index directory
~/virtualenv/bin/python ~/ci/utils/pack_content.py --input . --output ~/index/v1/packs/"${PACK_NAME}"

# Rebuild the index JSON
Expand Down Expand Up @@ -57,7 +83,6 @@ git -C ~/index status

if ! git -C ~/index diff --quiet --exit-code --cached
then

echo "Updating the index repo..."
git -C ~/index commit -m "Update the ${PACK_NAME} pack."
git -C ~/index push origin 2>/dev/null
Expand All @@ -73,25 +98,3 @@ then
else
echo "No changes to pack metadata, skipping the index update."
fi

# Create version tags
METADATA_CHANGES=$(git rev-list --all --no-abbrev --remove-empty -- pack.yaml)
for COMMIT in $(echo $METADATA_CHANGES)
do
git checkout ${COMMIT} pack.yaml > /dev/null
VERSION=$(~/virtualenv/bin/python ~/ci/.circle/semver.py pack.yaml 2>/dev/null || true)

# 1. Create a tag if version is specified and tag doesn't exist locally
if [[ ${VERSION} ]] && [[ -z $(git rev-parse -q --verify "refs/tags/v${VERSION}") ]]
then
echo "Creating tag ${VERSION} for commit ${COMMIT}"
git tag v${VERSION} ${COMMIT}
fi

# 2. If version is specified and tag doesn't exist on the remote, push it
if [[ ${VERSION} ]] && [[ -z $(git ls-remote origin "refs/tags/v${VERSION}") ]]
then
echo "Pushing tag v${VERSION} to origin remote"
git push origin v${VERSION}
fi
done
39 changes: 39 additions & 0 deletions .circle/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@
from glob import glob
from collections import OrderedDict

import requests

from st2common.util.pack import get_pack_ref_from_metadata

EXCHANGE_NAME = "StackStorm-Exchange"
EXCHANGE_PREFIX = "stackstorm"

GITHUB_USERNAME = os.environ.get('MACHINE_USER')
GITHUB_PASSWORD = os.environ.get('MACHINE_PASSWORD')

SESSION = requests.Session()
SESSION.auth = (GITHUB_USERNAME, GITHUB_PASSWORD)


def build_index(path_glob, output_path):
result = OrderedDict({
Expand Down Expand Up @@ -44,6 +52,11 @@ def build_index(path_glob, output_path):
EXCHANGE_NAME, EXCHANGE_PREFIX, sanitized_pack_name
)

versions = get_available_versions_for_pack(pack_ref)

if versions is not None:
pack_meta['versions'] = versions

# Note: Key in the index dictionary is ref and not a name
result['packs'][pack_ref] = pack_meta

Expand All @@ -67,6 +80,32 @@ def build_index(path_glob, output_path):
print('Processed %s packs.' % (counter))
print('Index data written to "%s".' % (output_path))


def get_available_versions_for_pack(pack_ref):
"""
Retrieve all the available versions for a particular pack.

NOTE: This function uses Github API.
"""
url = ('https://api.github.com/repos/%s/%s-%s/tags' %
(EXCHANGE_NAME, EXCHANGE_PREFIX, pack_ref))
resp = SESSION.get(url)

if resp.status_code != 200:
print('Got non 200 response: %s' % (resp.text))
Comment thread
blag marked this conversation as resolved.
return None

versions = []
Comment thread
blag marked this conversation as resolved.

for item in resp.json():
if item.get('name', '').startswith('v'):
versions.append(item['name'].replace('v', ''))

versions = list(reversed(sorted(versions)))

return versions


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate StackStorm exchange index.json')
parser.add_argument('--glob', help='Glob which points to the pack metadatafiles',
Expand Down