Skip to content

Commit

Permalink
Merge pull request #151 from nzlosh/pin_pip_etc
Browse files Browse the repository at this point in the history
Pin pip, setuptools and virtualenv modules to st2 project.
  • Loading branch information
nzlosh authored Oct 15, 2024
2 parents a072b6a + 379aced commit b6a8f22
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 242 deletions.
8 changes: 6 additions & 2 deletions .circle/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ REQUIREMENTS_DIR ?= $(CI_DIR)/.circle

export ST2_REPO_PATH ROOT_DIR FORCE_CHECK_ALL_FILES FORCE_CHECK_PACK

# This should track the pinned version of pip in st2's Makefile
# Please sync this version with .circle/dependencies .circle/Makefile and .circleci/config.yml
PIP_VERSION := 24.1

# All components are prefixed by st2
COMPONENTS := $(wildcard $(ST2_REPO_PATH)/st2*)
COMPONENTS_RUNNERS := $(wildcard $(ST2_REPO_PATH)/contrib/runners/*)
Expand Down Expand Up @@ -284,7 +288,7 @@ requirements: virtualenv .clone_st2_repo .install-runners
@echo
@echo "==================== requirements ===================="
@echo
. $(VIRTUALENV_DIR)/bin/activate && $(VIRTUALENV_DIR)/bin/pip install --upgrade "pip==20.3.3"
. $(VIRTUALENV_DIR)/bin/activate && $(VIRTUALENV_DIR)/bin/pip install --upgrade "pip==${PIP_VERSION}"
. $(VIRTUALENV_DIR)/bin/activate && $(VIRTUALENV_DIR)/bin/pip install --cache-dir $(HOME)/.pip-cache -q -r $(REQUIREMENTS_DIR)/requirements-dev.txt
. $(VIRTUALENV_DIR)/bin/activate && $(VIRTUALENV_DIR)/bin/pip install --cache-dir $(HOME)/.pip-cache -q -r $(REQUIREMENTS_DIR)/requirements-pack-tests.txt

Expand All @@ -293,7 +297,7 @@ requirements-ci:
@echo
@echo "==================== requirements-ci ===================="
@echo
. $(VIRTUALENV_DIR)/bin/activate && $(VIRTUALENV_DIR)/bin/pip install --upgrade "pip==20.3.3"
. $(VIRTUALENV_DIR)/bin/activate && $(VIRTUALENV_DIR)/bin/pip install --upgrade "pip==${PIP_VERSION}"
. $(VIRTUALENV_DIR)/bin/activate && $(VIRTUALENV_DIR)/bin/pip install --cache-dir $(HOME)/.pip-cache -q -r $(REQUIREMENTS_DIR)/requirements-dev.txt
. $(VIRTUALENV_DIR)/bin/activate && $(VIRTUALENV_DIR)/bin/pip install --cache-dir $(HOME)/.pip-cache -q -r $(REQUIREMENTS_DIR)/requirements-pack-tests.txt

Expand Down
8 changes: 5 additions & 3 deletions .circle/dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ sudo apt-get -y install libldap2-dev libsasl2-dev
(GH_TOKEN=${MACHINE_PASSWORD} gh repo view | head -n2) || true

# This should track the pinned version of pip in st2's Makefile
# Please sync this version with .circle/Makefile and .circleci/config.yml
PIP_VERSION="20.3.3"
# Please sync this version with .circle/dependencies .circle/Makefile and .circleci/config.yml
PIP_VERSION="24.1"
SETUPTOOLS_VERSION="70.1.0"
VIRTUALENV_VERSION="20.26.3"

sudo pip install -U "pip==${PIP_VERSION}" setuptools virtualenv
sudo pip install -U "pip==${PIP_VERSION}" "setuptools==${SETUPTOOLS_VERSION}" "virtualenv==${VIRTUALENV_VERSION}"
virtualenv --pip "${PIP_VERSION}" ~/virtualenv
source ~/virtualenv/bin/activate

Expand Down
42 changes: 21 additions & 21 deletions .circle/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,58 @@

import requests

EXCHANGE_ORG = 'StackStorm-Exchange'
INDEX_REPO = 'index'
AUTH = (os.environ['MACHINE_USER'], os.environ['MACHINE_PASSWORD'])
EXCHANGE_ORG = "StackStorm-Exchange"
INDEX_REPO = "index"
AUTH = (os.environ["MACHINE_USER"], os.environ["MACHINE_PASSWORD"])


def get_file(pack_name):
url = 'https://api.github.com/repos/{}/{}/contents/index/v1/packs/{}.yaml'.format(
EXCHANGE_ORG, INDEX_REPO, pack_name
url = (
f"https://api.github.com/repos/{EXCHANGE_ORG}/"
f"{INDEX_REPO}/contents/index/v1/packs/{pack_name}.yaml"
)

return requests.get(url)
return requests.get(url, timeout=30)


def put_file(pack_name, content, sha=None):
url = 'https://api.github.com/repos/{}/{}/contents/index/v1/packs/{}.yaml'.format(
EXCHANGE_ORG, INDEX_REPO, pack_name
url = (
f"https://api.github.com/repos/{EXCHANGE_ORG}/"
f"{INDEX_REPO}/contents/index/v1/packs/{pack_name}.yaml"
)

payload = {
'message': 'Update {} pack metadata'.format(pack_name),
'content': base64.b64encode(content),
"message": f"Update {pack_name} pack metadata",
"content": base64.b64encode(content),
}

if sha:
payload['sha'] = sha
payload["sha"] = sha

return requests.put(url, json=payload, auth=AUTH)
return requests.put(url, json=payload, timeout=30, auth=AUTH)


def calculate_git_sha(content):
sha = hashlib.sha1()
sha.update('blob {}\0{}'.format(len(content), content))
sha.update(f"blob {len(content)}\0{content}")
return sha.hexdigest()


if __name__ == '__main__':
if __name__ == "__main__":
local_path = sys.argv[1]
pack_name = sys.argv[2]

with open(local_path) as f:
with open(local_path, encoding="utf8") as f:
content = f.read()

current_pack_meta = get_file(pack_name)

if current_pack_meta.status_code == 200:
sha = current_pack_meta.json()['sha']
sha = current_pack_meta.json()["sha"]

if sha != calculate_git_sha(content):
r = put_file(pack_name, content, sha)
print('Pack index has been updated with new version of the pack.')
print("Pack index has been updated with new version of the pack.")
else:
print('File is already up to date, skipping...')
print("File is already up to date, skipping...")
else:
r = put_file(pack_name, content)
print('Pack index has been updated with new pack.')
print("Pack index has been updated with new pack.")
Loading

0 comments on commit b6a8f22

Please sign in to comment.