Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Github Actions workflows and composite actions for packs to use #121

Merged
merged 126 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
8d0aca8
Add repo to TSC team during bootstrap
cognifloyd Sep 21, 2021
ded3280
reenable CircleCI API call that enables CircleCI builds
cognifloyd Sep 21, 2021
6364be3
stub gha composite actions
cognifloyd Nov 12, 2021
f4e8164
stub deploy composit gha action
cognifloyd Nov 20, 2021
746b50d
gha actions: Added a shell field (opting to use the bash shell)
lm-ydubler Nov 22, 2021
454c0ec
gha actions: use bash shell
cognifloyd Nov 23, 2021
8347b9a
gha actions: Changed 'input' to 'inputs'
lm-ydubler Nov 22, 2021
ca9c592
gha actions: Fixing a string concatenation error by using format()
lm-ydubler Nov 22, 2021
0a40f7e
Update action.yaml
lm-ydubler Nov 23, 2021
995b891
typo fix
cognifloyd Nov 23, 2021
af4afdb
name tests task
cognifloyd Nov 23, 2021
f72b97c
apt-dependencies action: env var syntax
lm-ydubler Nov 23, 2021
a6c9f2e
gha actions: do not rely on tilde expansion for home var
cognifloyd Nov 23, 2021
b6dbe8c
gha actions: simplifiy GITHUB_ACTION_PATH usage
cognifloyd Nov 23, 2021
df88fc7
use gha env file instead of set-env command
cognifloyd Nov 25, 2021
69d8526
gha: fix apt-dependencies cache hashFiles
cognifloyd Nov 25, 2021
acf6496
gha: narrow apt cache contents and quiet apt output
cognifloyd Nov 25, 2021
964f9c8
gha: fix py cache hashFiles
cognifloyd Nov 26, 2021
8bd1ce3
create virtualenv correctly
cognifloyd Nov 26, 2021
0ea192d
gha: use env file to add path vars
cognifloyd Nov 26, 2021
f201741
gha: move requirements-ci from Makefile to gha workflow
cognifloyd Nov 26, 2021
4f6277e
gha: inline relevant Makefile section
cognifloyd Nov 26, 2021
b234e9c
gha: fix py deps print versions step
cognifloyd Nov 26, 2021
5ac9d52
gha: less verbose pip install
cognifloyd Nov 26, 2021
93fe56d
gha: use native gha output grouping/folding
cognifloyd Nov 26, 2021
481e0db
gha: update env var usage in tests action
cognifloyd Nov 26, 2021
a1f7f9d
gha: tell make where to find Makefile
cognifloyd Nov 26, 2021
9477db3
gha: lookup default branch
cognifloyd Nov 26, 2021
c34524e
gha: add GH_TOKEN env var
cognifloyd Nov 26, 2021
b640c6e
gha: set FORCE_CHECK_ALL_FILES correctly
cognifloyd Nov 26, 2021
f141e8e
gha: consolidate env var definition
cognifloyd Nov 26, 2021
6f20068
gha: save env vars correctly
cognifloyd Nov 26, 2021
0f4ca88
gha: pack clone should include all branches and tags
cognifloyd Nov 26, 2021
27133b6
gha: use virtualenv for everything in test
cognifloyd Nov 26, 2021
5f476c0
adjust Makefile to not hardcode ST2_REPO_PATH
cognifloyd Nov 26, 2021
fd8f075
adjust Makefile to not hardcode /home/circleci
cognifloyd Nov 26, 2021
8fce6ef
gha: temporarily enable FORCE_CHECK_ALL_FILES for all branches
cognifloyd Nov 26, 2021
1b08e2d
gha: define LINT_CONFIGS_PATH
cognifloyd Nov 26, 2021
9611b29
gha: simplify Makefile usage
cognifloyd Nov 26, 2021
a5e0bb7
gha: add services for tests
cognifloyd Nov 26, 2021
0b5695c
gha: add reusable pack-test workflow
cognifloyd Nov 26, 2021
741f0ef
gha: move reusable workflow to .github/workflows
cognifloyd Nov 26, 2021
82639e5
cleanup reusable workflow name
cognifloyd Nov 26, 2021
ab4e040
move gha/ to .github/actions
cognifloyd Nov 26, 2021
7da82a9
gha: drop debug comment
cognifloyd Nov 26, 2021
3db92f7
gha: allow packs to add system packages via .github/apt-packages.txt
cognifloyd Nov 26, 2021
c89b37d
gha: move py REQUIREMENTS_DIR
cognifloyd Nov 26, 2021
728ef15
gha: Makefile is no longer hard-coded to require circleci
cognifloyd Nov 26, 2021
b1f18f9
gha: fix pack/.github/apt-packages.txt conditional
cognifloyd Nov 26, 2021
c909593
gha: expose enable-common-libs input in reusable workflow
cognifloyd Nov 26, 2021
8fa382d
gha: correct doc strings about action deps
cognifloyd Nov 26, 2021
b8c6bc5
gha: update stub deploy workflow
cognifloyd Nov 26, 2021
590b851
gha: copy var from circle workflow to GHA test action
cognifloyd Nov 27, 2021
6d5f8c7
gha: add reusable index update workflow
cognifloyd Nov 27, 2021
60f0dab
gha: fix env usage in index-update workflow
cognifloyd Nov 27, 2021
8867847
gha: add inputs types
cognifloyd Nov 27, 2021
22f057e
gha: use https to clone packs
cognifloyd Nov 27, 2021
48dc99c
gha: fix inputs reference
cognifloyd Nov 27, 2021
0f73ac0
gha: workflow_call uses inputs not github.events.inputs
cognifloyd Nov 27, 2021
b1e6258
gha: add working directory to all packs task
cognifloyd Nov 28, 2021
b8bfe63
gha: better each pack test
cognifloyd Nov 28, 2021
87de8a0
gha: export -f do_it
cognifloyd Nov 28, 2021
8ffd883
gha: drop verbose
cognifloyd Nov 28, 2021
7ab5e62
gha: debug failure
cognifloyd Nov 28, 2021
2da4cdf
gha: simplify pack loop
cognifloyd Nov 28, 2021
50d8201
gha: skip incomplete packs
cognifloyd Nov 28, 2021
13bd387
gha: clean up pack loop output
cognifloyd Nov 28, 2021
0bc5871
gha: delete clone of bad pack repos
cognifloyd Nov 28, 2021
7a3ca87
gha: improve grouping/folding of per pack output
cognifloyd Nov 28, 2021
76fd055
gha: add per pack deployment steps to index regen workflow
cognifloyd Nov 28, 2021
6c72956
gha: install py-deps for index
cognifloyd Nov 28, 2021
d2d3a42
fix indentation
cognifloyd Nov 28, 2021
dd5b96c
fix GHA expression quotes
cognifloyd Nov 28, 2021
efdbe46
gha: install apt deps for index update
cognifloyd Nov 28, 2021
468282b
gha: install gmic and options for icon optimization
cognifloyd Nov 29, 2021
37f9177
gha: add commit/push index step and annotate bad assumptions in some …
cognifloyd Nov 29, 2021
2bcc2d4
gha: display git index changes
cognifloyd Nov 29, 2021
b6d508b
mark TODOs important
cognifloyd Nov 29, 2021
1aa417c
Changes to GHA Update-Index Workflow (#118)
lm-ydubler Dec 6, 2021
0017a29
gha: include the apt database in apt-dependencies cache
cognifloyd Dec 6, 2021
321e3cb
gha: use PACKS_PREFIX var and improve message
cognifloyd Dec 6, 2021
16d11ca
gha: limit concurrency for index-update workflow
cognifloyd Dec 6, 2021
912130a
Revert "gha: limit concurrency for index-update workflow"
cognifloyd Dec 6, 2021
89378cb
document how validate.py works
cognifloyd Dec 7, 2021
7ca8c93
gha: reformat bash scripts with minor indents
cognifloyd Dec 7, 2021
29c2eb6
gha: skip rebuilding index for packs with invalid pack metadata
cognifloyd Dec 7, 2021
32f99f5
gha: improve output folding to not obscure pack errors
cognifloyd Dec 7, 2021
441b6e9
gha: caching apt deps is not working. disable for now.
cognifloyd Dec 7, 2021
f799863
gha: drop superfluous set -ex
cognifloyd Dec 7, 2021
3852efd
gha: only print pack clone errors. assume valid otherwise
cognifloyd Dec 7, 2021
aac209e
gha: improve index-update output to better identify errors and to avo…
cognifloyd Dec 7, 2021
f781d20
gha: improve index-update output to better identify errors
cognifloyd Dec 7, 2021
1bf2191
gha: debug index changes
cognifloyd Dec 7, 2021
9798307
adjust index.py and validate.py to not assume CircleCI and pack repo …
cognifloyd Dec 7, 2021
3e0cbbc
gha: drop unused composite action skeleton
cognifloyd Dec 7, 2021
ad7e7ae
skeleton pack-tag_release.yaml workflow
cognifloyd Dec 7, 2021
f120b47
Updates to Tag Release Workflow (#120)
lm-ydubler Dec 9, 2021
8d576e3
gha: simplify checkout - pack is the current repo
cognifloyd Dec 9, 2021
418c94b
gha: simplify yq install
cognifloyd Dec 9, 2021
cbc013c
gha: cleanup debug lines
cognifloyd Dec 9, 2021
c8ad5f9
gha: cleanup setting env
cognifloyd Dec 9, 2021
0482d96
gha: do full clone during deploy step
cognifloyd Dec 9, 2021
786e018
gha: add tag_release workflow outputs
cognifloyd Dec 9, 2021
c161f9f
minimize required dependencies for semver.py
cognifloyd Dec 9, 2021
c9ba518
turn tag_release workflow into a composite action
cognifloyd Dec 9, 2021
699768b
turn tag_release workflow into a composite action
cognifloyd Dec 9, 2021
0122e0d
gha: use semver.py to extract semver-style version from pack.yaml
cognifloyd Dec 9, 2021
57f10be
gha: better division between workflow and composite action
cognifloyd Dec 9, 2021
86095c0
fix bug in validate.py
cognifloyd Dec 9, 2021
7eaf4ee
fix composite action syntax
cognifloyd Dec 9, 2021
a5224db
gha: install deps for semver.py
cognifloyd Dec 9, 2021
f7335bf
fix tee usage
cognifloyd Dec 9, 2021
c46da9e
gha: improve output grouping
cognifloyd Dec 9, 2021
a2f1d75
fix created_tag logic
cognifloyd Dec 9, 2021
a12e636
gha: add pack repo metadata update action
cognifloyd Dec 9, 2021
732c37b
gha: add pack-repo_meta.yaml workflow
cognifloyd Dec 9, 2021
38f7c5c
gha: correct GITHUB_ACTION_PATH var
cognifloyd Dec 9, 2021
cf2f987
switch from gha branch to master
cognifloyd Dec 9, 2021
2319b64
remove old comments
cognifloyd Dec 9, 2021
7143e1f
drop unrelated changes
cognifloyd Dec 9, 2021
ce10f59
satisfy lint
cognifloyd Dec 9, 2021
b4bb627
switch back to StackStorm-Exchange/exchange-tools instead of fork
cognifloyd Dec 9, 2021
5f5f057
gha: switch branch of checkouts to master
cognifloyd Dec 9, 2021
d26754f
silence pylint about new file
cognifloyd Dec 9, 2021
0e111b8
satisfy pylint for files used in gha
cognifloyd Dec 9, 2021
b911fde
use an f-string
cognifloyd Dec 9, 2021
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
35 changes: 18 additions & 17 deletions .circle/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ ST2_REPO_PATH ?= /tmp/st2
ST2_REPO_BRANCH ?= master
FORCE_CHECK_ALL_FILES ?= false
FORCE_CHECK_PACK ?= false
LINT_CONFIGS_PATH ?= $(CI_DIR)/lint-configs
REQUIREMENTS_DIR ?= $(CI_DIR)/.circle

export ST2_REPO_PATH ROOT_DIR FORCE_CHECK_ALL_FILES FORCE_CHECK_PACK

# All components are prefixed by st2
COMPONENTS := $(wildcard /tmp/st2/st2*)
COMPONENTS_RUNNERS := $(wildcard /tmp/st2/contrib/runners/*)
COMPONENTS := $(wildcard $(ST2_REPO_PATH)/st2*)
COMPONENTS_RUNNERS := $(wildcard $(ST2_REPO_PATH)/contrib/runners/*)

.PHONY: all
all: requirements lint packs-resource-register packs-tests
Expand Down Expand Up @@ -79,14 +81,14 @@ compile:
if [ "$${FORCE_CHECK_ALL_FILES}" = "true" ]; then \
echo "Force flake8 checks on all files"; \
find $(ROOT_DIR)/* -name "*.py" | while read py_file; do \
flake8 --config=$(CI_DIR)/lint-configs/python/.flake8 $$py_file || exit 1; \
flake8 --config=$(LINT_CONFIGS_PATH)/python/.flake8 $$py_file || exit 1; \
done; \
elif [ ${NUM_CHANGED_PY} -gt 0 ]; then \
echo "Checking ${NUM_CHANGED_PY} Python files"; \
$(CI_DIR)/utils/git-changes py >~/.git-changes-py; \
while read -r file; do \
if [ -n "$$file" ]; then \
flake8 --config=$(CI_DIR)/lint-configs/python/.flake8 $$file || exit 1; \
flake8 --config=$(LINT_CONFIGS_PATH)/python/.flake8 $$file || exit 1; \
fi; \
done < ~/.git-changes-py; \
if [ -e ~/.git-changes-py ]; then rm ~/.git-changes-py; fi; \
Expand All @@ -102,11 +104,11 @@ compile:
. $(VIRTUALENV_DIR)/bin/activate; \
if [ "${COMMON_LIBS}" = "true" ]; then \
echo "Common libs PATH selected"; \
export PYTHONPATH=/home/circleci/repo/lib:${PYTHONPATH}; \
export PYTHONPATH=$(ROOT_DIR)/lib:${PYTHONPATH}; \
fi; \
if [ "$${FORCE_CHECK_ALL_FILES}" = "true" ] || [ ${NUM_CHANGED_PY} -gt 0 ]; then \
REQUIREMENTS_DIR=$(CI_DIR)/.circle/ \
CONFIG_DIR=$(CI_DIR)/lint-configs/ \
REQUIREMENTS_DIR=$(REQUIREMENTS_DIR)/ \
CONFIG_DIR=$(LINT_CONFIGS_PATH)/ \
st2-check-pylint-pack $(ROOT_DIR) || exit 1; \
else \
echo "No files have changed, skipping run..."; \
Expand Down Expand Up @@ -237,8 +239,8 @@ compile:
echo "Missing LICENSE file in $(ROOT_DIR)"; \
exit 2;\
fi;\
if [ "$$(python -c 'import yaml; f = open("/home/circleci/repo/pack.yaml"); print(yaml.safe_load(f.read())["name"]); f.close();')" = "napalm_logs" ] || \
[ "$$(python -c 'import yaml; f = open("/home/circleci/repo/pack.yaml"); print(yaml.safe_load(f.read())["name"]); f.close();')" = "netbox" ]; then \
if [ "$$(python -c 'import yaml; f = open("$(ROOT_DIR)/pack.yaml"); print(yaml.safe_load(f.read())["name"]); f.close();')" = "napalm_logs" ] || \
[ "$$(python -c 'import yaml; f = open("$(ROOT_DIR)/pack.yaml"); print(yaml.safe_load(f.read())["name"]); f.close();')" = "netbox" ]; then \
cat $(ROOT_DIR)/LICENSE | grep -q "MIT License" || (echo "LICENSE file doesn't contain MIT license text" ; exit 2); \
cat $(ROOT_DIR)/LICENSE | grep -q "Copyright (c) 2017 John Anderson" || (echo "LICENSE file doesn't include John Anderson's name" ; exit 2); \
cat $(ROOT_DIR)/LICENSE | grep -q "Permission is hereby granted, free of charge, to any person obtaining a copy" || (echo "LICENSE file doesn't contain MIT license text" ; exit 2); \
Expand All @@ -252,13 +254,12 @@ compile:
fi

.PHONY: .clone_st2_repo
.clone_st2_repo: /tmp/st2
/tmp/st2:
.clone_st2_repo:
@echo
@echo "==================== cloning st2 repo ===================="
@echo
@rm -rf /tmp/st2
@git clone https://github.com/StackStorm/st2.git --depth 1 --single-branch --branch $(ST2_REPO_BRANCH) /tmp/st2
@rm -rf $(ST2_REPO_PATH)
@git clone https://github.com/StackStorm/st2.git --depth 1 --single-branch --branch $(ST2_REPO_BRANCH) $(ST2_REPO_PATH)

.PHONY: .install-runners
.install-runners:
Expand All @@ -284,17 +285,17 @@ requirements: virtualenv .clone_st2_repo .install-runners
@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 --cache-dir $(HOME)/.pip-cache -q -r $(CI_DIR)/.circle/requirements-dev.txt
. $(VIRTUALENV_DIR)/bin/activate && $(VIRTUALENV_DIR)/bin/pip install --cache-dir $(HOME)/.pip-cache -q -r $(CI_DIR)/.circle/requirements-pack-tests.txt
. $(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

.PHONY: requirements-ci
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 --cache-dir $(HOME)/.pip-cache -q -r $(CI_DIR)/.circle/requirements-dev.txt
. $(VIRTUALENV_DIR)/bin/activate && $(VIRTUALENV_DIR)/bin/pip install --cache-dir $(HOME)/.pip-cache -q -r $(CI_DIR)/.circle/requirements-pack-tests.txt
. $(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

.PHONY: virtualenv
virtualenv: $(VIRTUALENV_DIR)/bin/activate
Expand Down
45 changes: 39 additions & 6 deletions .circle/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@

from st2common.util.pack import get_pack_ref_from_metadata

EXCHANGE_NAME = "StackStorm-Exchange"
EXCHANGE_PREFIX = "stackstorm"
EXCHANGE_NAME = os.environ.get("PACKS_ORG", "StackStorm-Exchange")
EXCHANGE_PREFIX = os.environ.get("PACKS_PREFIX", "stackstorm")

if os.environ.get("CIRCLECI"):
CI = "CircleCI"
elif os.environ.get("GITHUB_ACTIONS"):
CI = "GHA"
else:
CI = "unknown"


# TODO: drop GITHUB_USERNAME once we drop support for CircleCI
GITHUB_USERNAME = os.environ.get('MACHINE_USER')
# TODO: drop MACHINE_PASSWORD once we drop support for CircleCI. Keep GH_TOKEN.
GITHUB_PASSWORD = os.environ.get("MACHINE_PASSWORD", os.environ.get("GH_TOKEN"))
# TODO: drop ACTIVE_PACK_NAME once we drop support for CircleCI.
# Only used for CircleCI-specific error message.
ACTIVE_PACK_NAME = os.environ.get('PACK_NAME', "unknown")

SESSION = requests.Session()
Expand Down Expand Up @@ -63,7 +75,7 @@ def build_index(path_glob, output_path):
counter = 0
failed_count = 0
for filename in generator:
with open(filename, 'r') as pack:
with open(filename, 'r', encoding="utf8") as pack:
pack_meta = yaml.safe_load(pack)

pack_name = pack_meta['name']
Expand Down Expand Up @@ -102,12 +114,13 @@ def build_index(path_glob, output_path):
result['metadata']['hash'] = data_hash.hexdigest()

output_path = os.path.expanduser(os.path.join(output_path, 'index.json'))
with open(output_path, 'w') as outfile:
with open(output_path, 'w', encoding="utf8") as outfile:
json.dump(result, outfile, indent=4, sort_keys=True,
separators=(',', ': '))

failed_message = ''
if failed_count > 0:
# TODO: drop CircleCI error message once we drop support for CircleCI
if failed_count > 0 and CI == "CircleCI":
failed_message = (
', {failed_count} packs failed to update.\n'
'The GitHub Personal Access Tokens for CircleCI for the pack may '
Expand All @@ -120,6 +133,14 @@ def build_index(path_glob, output_path):
'will need to ask a member of the StackStorm TSC to update the Personal\n'
'Access Token on your behalf.'
).format(failed_count=failed_count, exchange_name=EXCHANGE_NAME)
elif failed_count > 0:
# If an issue is reported on GitHub Actions, update this error message
# to explain common causes and how to fix them.
failed_message = (
f', {failed_count} packs failed to update.\n'
'Please investigate why this failed and report an issue on:\n'
f' https://github.com/{EXCHANGE_NAME}/ci\n'
)

print('')
print('Processed %s packs%s.' % (counter, failed_message))
Expand Down Expand Up @@ -152,13 +173,20 @@ def get_available_versions():
proc.kill()
outs, _ = proc.communicate()
result = outs.decode().strip()
if proc.returncode != 0:
# TODO: drop CircleCI error message once we drop support for CircleCI
if proc.returncode != 0 and CI == "CircleCI":
sys.exit(
"Error retrieving data with github graphql API.\n"
"The GitHub PAT might need to be regenerated:\n"
"https://github.com/settings/tokens/new?scopes=public_repo"
"&description=CircleCI%3A%20stackstorm-" + ACTIVE_PACK_NAME
)
elif proc.returncode != 0:
# If an issue is reported on GitHub Actions, update this error message
# to explain common causes and how to fix them.
sys.exit(
"Error retrieving data with github graphql API.\n"
)

# https://stackoverflow.com/a/43807246/1134951
decoder = json.JSONDecoder()
Expand Down Expand Up @@ -194,7 +222,12 @@ def get_available_versions_for_pack(pack_ref):
NOTE: This function uses Github API.
"""
# TODO: remove this if block once we discontinue CircleCI support. Keep the else block.
if pack_ref not in PACK_VERSIONS:
# This will fail in GitHub Actions because the GITHUB_TOKEN there must be
# provided as bearer auth instead of basic auth. But using graphql is better
# anyway, so this is only needed as a backup on CircleCI if graphql doesn't work.
# graphql should always work on GHA.
url = ('https://api.github.com/repos/%s/%s-%s/tags' %
(EXCHANGE_NAME, EXCHANGE_PREFIX, pack_ref))
resp = SESSION.get(url)
Expand Down
12 changes: 9 additions & 3 deletions .circle/semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

import sys
import re

import validate
import yaml

SEMVER_REGEX = re.compile(r"""^(?:0|[1-9]\d*)
\.
Expand All @@ -31,6 +30,13 @@
DOUBLE_VERSION_REGEX = re.compile(r"^\d+\.\d+$")


def load_yaml_file(path):
with open(path, 'r', encoding="utf8") as stream:
text = yaml.safe_load(stream)

return text


def get_semver_string(version):
if SINGLE_VERSION_REGEX.match(str(version)):
semver = "%s.0.0" % version
Expand All @@ -44,5 +50,5 @@ def get_semver_string(version):


if __name__ == '__main__':
pack = validate.load_yaml_file(sys.argv[1])
pack = load_yaml_file(sys.argv[1])
print(get_semver_string(pack['version']))
20 changes: 17 additions & 3 deletions .circle/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
from __future__ import print_function

import os
import sys

import yaml
Expand All @@ -22,18 +23,21 @@
from st2common.util import schema as util_schema
from st2common.util.pack import get_pack_ref_from_metadata

PREFIX = 'stackstorm'
PREFIX = os.environ.get("PACKS_PREFIX", "stackstorm")
PACK_SCHEMA = PackAPI.schema


def load_yaml_file(path):
with open(path, 'r') as stream:
with open(path, 'r', encoding="utf8") as stream:
text = yaml.safe_load(stream)

return text


def validate_schema(instance, schema):
# validate() returns a cleaned instance with default values assigned.
# and it calls jsonschema.validate(instance, schema) so this will
# raise ValidationError if instance is not valid according to schema
return util_schema.validate(instance=instance, schema=schema,
cls=util_schema.CustomValidator,
use_default=True,
Expand All @@ -51,12 +55,22 @@ def validate_repo_name(instance, repo_name):


if __name__ == '__main__':
# If an exception is raised, python basically does sys.exit(1)
# Without an exception, the return code is 0.

repo_name = sys.argv[1]
# raises if yaml is invalid
pack_meta = load_yaml_file(sys.argv[2])

# TODO: Figure out why this wasn't previously executed, and execute it
# stackstorm-test-content-version repo is test_content_version pack
# stackstorm-test2 repo is test pack
# validate_repo_name(pack_meta, repo_name)
validate_schema(pack_meta, PACK_SCHEMA)

# raises ValidationError if pack_meta doesn't validate against PACK_SCHEMA
cleaned_pack_meta = validate_schema(pack_meta, PACK_SCHEMA)

# raises ValueError if pack ref not defined and pack name is not a valid ref
pack_ref = validate_pack_contains_valid_ref_or_name(pack_meta)

print(pack_ref)
72 changes: 72 additions & 0 deletions .github/actions/apt-dependencies/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
name: Install APT Dependencies
description: |
Install debian dependencies required for StackStorm-Exchange pack tests.
Before using this, make sure to run
StackStorm-Exchange/ci/.github/actions/checkout.
author: StackStorm

inputs:
cache-version:
required: false
default: "v0"
extra-apt-packages-file:
required: false
default: pack/.github/apt-packages.txt

runs:
using: "composite"
steps:

# TODO: not working on GHA. Need to revisit caching.
#- name: Create a directory for debian packages so we can cache it
# # this is what we did on CircleCI. Not sure if it'll work on GHA
# shell: bash
# run: >
# sudo rm -rf /var/cache/apt/archives /var/lib/apt/lists
# && sudo ln -s ~/apt_cache/archives /var/cache/apt/archives
# && sudo ln -s ~/apt_cache/lists /var/lib/apt/lists
# && mkdir -p ~/apt_cache/archives/partial ~/apt_cache/lists

# hashFiles only reads files relative to GITHUB_WORKSPACE
- name: Construct apt-packages.txt
shell: bash
run: |
cp ${{ github.action_path }}/apt-packages.txt ${GITHUB_WORKSPACE}/
if [[ -f ${{ inputs.extra-apt-packages-file }} ]]; then
cat ${{ inputs.extra-apt-packages-file }} >> ${GITHUB_WORKSPACE}/apt-packages.txt
fi

#- name: Cache APT Dependencies
# id: cache-apt-deps
# uses: actions/cache@v2
# with:
# path: |
# ~/apt_cache/*.deb
# key: ${{ inputs.cache-version }}-apt-archives-and-lists-${{ hashFiles('apt-packages.txt') }}
# restore-keys: |
# ${{ inputs.cache-version }}-apt-archives-and-lists-

- name: Install APT Dependencies
shell: bash
env:
# CACHE_HIT: ${{steps.cache-apt-deps.outputs.cache-hit}}
CACHE_HIT: "false"
APT_PACKAGES_FILE_PATH: apt-packages.txt
DEBIAN_FRONTEND: noninteractive
run: |
echo "::group::Install APT Dependencies"
if [[ "${CACHE_HIT}" != 'true' ]]; then
sudo apt-get -o=Dpkg::Use-Pty=0 -yq update
fi
APT_PACKAGES=$(grep -v '^#' "${APT_PACKAGES_FILE_PATH}" | xargs echo -n)
sudo apt-get -o=Dpkg::Use-Pty=0 -yq install ${APT_PACKAGES}
echo "::endgroup::"

- name: Print versions
shell: bash
run: |
echo "::group::Print Versions"
jq --version
gh --version
echo "::endgroup::"
10 changes: 10 additions & 0 deletions .github/actions/apt-dependencies/apt-packages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# pre-installed on GHA
#jq
#gh # github cli
#imagemagick

# for st2 pip build
libldap2-dev
libsasl2-dev
# st2 also installs
#libssl-dev libyaml-dev ldap-utils
5 changes: 5 additions & 0 deletions .github/actions/apt-dependencies/index-apt-packages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# In CircleCI, we couldn't directly install imagemagick, so
# we used a workaround from https://discuss.circleci.com/t/error-installing-imagemagick/2963
# TODO: determine if we should go back to using imagemagick instead of gmic and optipng
gmic
optipng
Loading