Skip to content

Commit 437688f

Browse files
authored
Merge pull request #72 from StackStorm-Exchange/include_pack_tags
Include available versions for all the packs in the index
2 parents f035e42 + 8831bbf commit 437688f

2 files changed

Lines changed: 65 additions & 23 deletions

File tree

.circle/deployment

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,38 @@ fi
2020

2121
# TODO: figure out how to make deploy.py rebuild the index.
2222
# python ~/packs/.circle/deploy.py pack.yaml "${CIRCLE_PROJECT_REPONAME}"
23+
2324
# Clean up so the script can be retries in case of failure (e.g. race)
2425
rm -rf ~/index
2526
git clone https://${MACHINE_USER}:${MACHINE_PASSWORD}@github.com/StackStorm-Exchange/index ~/index 2>/dev/null
2627

2728
echo "Processing pack ${PACK_NAME}"
2829

30+
# NOTE: We create tags before re-building the index to ensure latest tag is reflected in the index
31+
32+
# Create version tags
33+
METADATA_CHANGES=$(git rev-list --all --no-abbrev --remove-empty -- pack.yaml)
34+
for COMMIT in $(echo $METADATA_CHANGES)
35+
do
36+
git checkout ${COMMIT} pack.yaml > /dev/null
37+
VERSION=$(~/virtualenv/bin/python ~/ci/.circle/semver.py pack.yaml 2>/dev/null || true)
38+
39+
# 1. Create a tag if version is specified and tag doesn't exist locally
40+
if [[ ${VERSION} ]] && [[ -z $(git rev-parse -q --verify "refs/tags/v${VERSION}") ]]
41+
then
42+
echo "Creating tag ${VERSION} for commit ${COMMIT}"
43+
git tag v${VERSION} ${COMMIT}
44+
fi
45+
46+
# 2. If version is specified and tag doesn't exist on the remote, push it
47+
if [[ ${VERSION} ]] && [[ -z $(git ls-remote origin "refs/tags/v${VERSION}") ]]
48+
then
49+
echo "Pushing tag v${VERSION} to origin remote"
50+
git push origin v${VERSION}
51+
fi
52+
done
53+
54+
# Rebuild pack index directory
2955
~/virtualenv/bin/python ~/ci/utils/pack_content.py --input . --output ~/index/v1/packs/"${PACK_NAME}"
3056

3157
# Rebuild the index JSON
@@ -57,7 +83,6 @@ git -C ~/index status
5783

5884
if ! git -C ~/index diff --quiet --exit-code --cached
5985
then
60-
6186
echo "Updating the index repo..."
6287
git -C ~/index commit -m "Update the ${PACK_NAME} pack."
6388
git -C ~/index push origin 2>/dev/null
@@ -73,25 +98,3 @@ then
7398
else
7499
echo "No changes to pack metadata, skipping the index update."
75100
fi
76-
77-
# Create version tags
78-
METADATA_CHANGES=$(git rev-list --all --no-abbrev --remove-empty -- pack.yaml)
79-
for COMMIT in $(echo $METADATA_CHANGES)
80-
do
81-
git checkout ${COMMIT} pack.yaml > /dev/null
82-
VERSION=$(~/virtualenv/bin/python ~/ci/.circle/semver.py pack.yaml 2>/dev/null || true)
83-
84-
# 1. Create a tag if version is specified and tag doesn't exist locally
85-
if [[ ${VERSION} ]] && [[ -z $(git rev-parse -q --verify "refs/tags/v${VERSION}") ]]
86-
then
87-
echo "Creating tag ${VERSION} for commit ${COMMIT}"
88-
git tag v${VERSION} ${COMMIT}
89-
fi
90-
91-
# 2. If version is specified and tag doesn't exist on the remote, push it
92-
if [[ ${VERSION} ]] && [[ -z $(git ls-remote origin "refs/tags/v${VERSION}") ]]
93-
then
94-
echo "Pushing tag v${VERSION} to origin remote"
95-
git push origin v${VERSION}
96-
fi
97-
done

.circle/index.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@
99
from glob import glob
1010
from collections import OrderedDict
1111

12+
import requests
13+
1214
from st2common.util.pack import get_pack_ref_from_metadata
1315

1416
EXCHANGE_NAME = "StackStorm-Exchange"
1517
EXCHANGE_PREFIX = "stackstorm"
1618

19+
GITHUB_USERNAME = os.environ.get('MACHINE_USER')
20+
GITHUB_PASSWORD = os.environ.get('MACHINE_PASSWORD')
21+
22+
SESSION = requests.Session()
23+
SESSION.auth = (GITHUB_USERNAME, GITHUB_PASSWORD)
24+
1725

1826
def build_index(path_glob, output_path):
1927
result = OrderedDict({
@@ -44,6 +52,11 @@ def build_index(path_glob, output_path):
4452
EXCHANGE_NAME, EXCHANGE_PREFIX, sanitized_pack_name
4553
)
4654

55+
versions = get_available_versions_for_pack(pack_ref)
56+
57+
if versions is not None:
58+
pack_meta['versions'] = versions
59+
4760
# Note: Key in the index dictionary is ref and not a name
4861
result['packs'][pack_ref] = pack_meta
4962

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

83+
84+
def get_available_versions_for_pack(pack_ref):
85+
"""
86+
Retrieve all the available versions for a particular pack.
87+
88+
NOTE: This function uses Github API.
89+
"""
90+
url = ('https://api.github.com/repos/%s/%s-%s/tags' %
91+
(EXCHANGE_NAME, EXCHANGE_PREFIX, pack_ref))
92+
resp = SESSION.get(url)
93+
94+
if resp.status_code != 200:
95+
print('Got non 200 response: %s' % (resp.text))
96+
return None
97+
98+
versions = []
99+
100+
for item in resp.json():
101+
if item.get('name', '').startswith('v'):
102+
versions.append(item['name'].replace('v', ''))
103+
104+
versions = list(reversed(sorted(versions)))
105+
106+
return versions
107+
108+
70109
if __name__ == '__main__':
71110
parser = argparse.ArgumentParser(description='Generate StackStorm exchange index.json')
72111
parser.add_argument('--glob', help='Glob which points to the pack metadatafiles',

0 commit comments

Comments
 (0)