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

convert CI from CircleCI to GHA #10

Merged
merged 6 commits into from
Dec 24, 2021
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
138 changes: 5 additions & 133 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,144 +1,16 @@
---
version: 2

jobs:
build_and_test_python27:
circleci_is_disabled_job:
docker:
- image: circleci/python:2.7
- image: rabbitmq:3
- image: mongo:3.4

working_directory: ~/repo

environment:
VIRTUALENV_DIR: "~/virtualenv"
# Don't install various StackStorm dependencies which are already
# installed by CI again in the various check scripts
ST2_INSTALL_DEPS: "0"

steps:
- checkout
- restore_cache:
key: v1-dependency-cache-py27-{{ checksum "requirements.txt" }}
- run:
name: Download dependencies
command: |
git clone -b master git://github.com/stackstorm-exchange/ci.git ~/ci
~/ci/.circle/dependencies
- run:
name: Run tests (Python 2.7)
command: ~/ci/.circle/test
- save_cache:
key: v1-dependency-cache-py27-{{ checksum "requirements.txt" }}
paths:
- ~/.cache/pip
- ~/.apt-cache
# NOTE: We use virtualenv files from Python 2.7 step in "deploy" job so we
# only persist paths from this job
- persist_to_workspace:
root: /
paths:
- home/circleci/ci
- home/circleci/virtualenv
- tmp/st2
- home/circleci/repo
- home/circleci/.gitconfig

# NOTE: Until we add "python_version" metadata attribute to pack.yaml and
# explicitly call which packs work with Python 3.x, Python 3.x failures are
# not considered fatal
build_and_test_python36:
docker:
- image: circleci/python:3.6
- image: rabbitmq:3
- image: mongo:3.4

working_directory: ~/repo

environment:
VIRTUALENV_DIR: "~/virtualenv"
# Don't install various StackStorm dependencies which are already
# installed by CI again in the various check scripts
ST2_INSTALL_DEPS: "0"

- image: cimg/base:stable
steps:
- checkout
- restore_cache:
key: v1-dependency-cache-py36-{{ checksum "requirements.txt" }}
- run:
name: Download dependencies
# NOTE: We don't want to use default "-e" option because this means
# step will fail immediately on one of the commands failures and we
# can't intercept the error and cause non-fatal exit in case pack
# doesn't declare support for Python 3
shell: /bin/bash
command: |
git clone -b master git://github.com/stackstorm-exchange/ci.git ~/ci
~/ci/.circle/dependencies ; ~/ci/.circle/exit_on_py3_checks $?
- run:
name: Run tests (Python 3.6)
# NOTE: We don't want to use default "-e" option because this means
# step will fail immediately on one of the commands failures and we
# can't intercept the error and cause non-fatal exit in case pack
# doesn't declare support for Python 3
shell: /bin/bash
command: ~/ci/.circle/test ; ~/ci/.circle/exit_on_py3_checks $?
- save_cache:
key: v1-dependency-cache-py36-{{ checksum "requirements.txt" }}
paths:
- ~/.cache/pip
- ~/.apt-cache

deploy:
docker:
- image: circleci/python:2.7

working_directory: ~/repo

environment:
VIRTUALENV_DIR: "~/virtualenv"

steps:
- checkout
- restore_cache:
key: v1-dependency-cache-py27-{{ checksum "requirements.txt" }}
- attach_workspace:
at: /
- run:
name: Install dependencies
command: sudo apt -y install gmic optipng
- run:
# NOTE: We try to retry the script up to 5 times if it fails. The command could fail due
# to the race (e.g. we try to push changes to index, but index has been updated by some
# other pack in the mean time)
name: Update exchange.stackstorm.org
command: ~/ci/.circle/retry_on_failure.sh ~/ci/.circle/deployment
command: echo CircleCI disabled on StackStorm-Exchange

workflows:
version: 2
# Workflow which runs on each push
build_test_deploy_on_push:
jobs:
- build_and_test_python27
- build_and_test_python36
- deploy:
requires:
- build_and_test_python27
filters:
branches:
only: master
build_test_weekly:
circleci_is_disabled:
jobs:
- build_and_test_python27
- build_and_test_python36
# Workflow which runs nightly - note we don't perform deploy job on nightly
# build
triggers:
# Run nightly build for the pack
- schedule:
# NOTE: We run it at 1 am UTC on every Sunday
cron: "0 1 * * 0"
filters:
branches:
only:
- master
- circleci_is_disabled_job
18 changes: 18 additions & 0 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI

on:
workflow_dispatch:
pull_request:
schedule:
# NOTE: We run this weekly at 1 am UTC on every Sunday
- cron: '0 1 * * 0'

jobs:
# This is mirrored in the release workflow.
build_and_test:
name: 'Build and Test'
uses: StackStorm-Exchange/ci/.github/workflows/pack-build_and_test.yaml@master
with:
enable-common-libs: true
#apt-cache-version: v0
#py-cache-version: v0
25 changes: 25 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release

on:
push:
branches:
# the default branch
- master

permissions:
contents: write

jobs:
# This mirrors build_and_test workflow
build_and_test:
name: 'Build and Test'
uses: StackStorm-Exchange/ci/.github/workflows/pack-build_and_test.yaml@master
with:
enable-common-libs: true
#apt-cache-version: v0
#py-cache-version: v0

tag_release:
needs: build_and_test
name: Tag Release
uses: StackStorm-Exchange/ci/.github/workflows/pack-tag_release.yaml@master
23 changes: 9 additions & 14 deletions actions/assemble_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
from st2common.runners.base_action import Action


__all__ = [
'AssembleMessageAction'
]
__all__ = ["AssembleMessageAction"]

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -36,29 +34,26 @@ def run(self, forum_posts, github_data, template_path):
Build and return rendered text.
"""

template_path = os.path.join(BASE_DIR, '../', template_path)
template_path = os.path.join(BASE_DIR, "../", template_path)
template_path = os.path.abspath(template_path)

with codecs.open(template_path, encoding='utf-8') as fp:
with codecs.open(template_path, encoding="utf-8") as fp:
template_data = fp.read()

template_context = {
'github_data': github_data,
'forum_posts': forum_posts
}
template_context = {"github_data": github_data, "forum_posts": forum_posts}

# Add all information to the template context and render the template
env = Environment(trim_blocks=True, lstrip_blocks=True)
rendered = env.from_string(template_data).render(template_context)

# Remove any Jinja and YAQL expressions to prevent them from trying to be rendered inside
# the workflow
rendered = rendered.replace('{%', '').replace('%}', '')
rendered = rendered.replace('{{', '').replace('}}', '')
rendered = rendered.replace('<%', '').replace('%>', '')
rendered = rendered.replace('\\"', '"').replace("\'", "'")
rendered = rendered.replace("{%", "").replace("%}", "")
rendered = rendered.replace("{{", "").replace("}}", "")
rendered = rendered.replace("<%", "").replace("%>", "")
rendered = rendered.replace('\\"', '"').replace("'", "'")

# Also escape no-valid unicode escape sequences
rendered = rendered.replace('\\', '')
rendered = rendered.replace("\\", "")

return rendered
4 changes: 1 addition & 3 deletions actions/get_forum_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
from lib.utils import get_timedelta_object_from_delta_arg
from lib.forum_posts import get_forum_posts

__all__ = [
'GetForumPostsAction'
]
__all__ = ["GetForumPostsAction"]


class GetForumPostsAction(Action):
Expand Down
12 changes: 6 additions & 6 deletions actions/get_github_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@
from lib.utils import get_timedelta_object_from_delta_arg
from lib.github_issues import get_issues_and_prs_for_user

__all__ = [
'GetGithubIssuesAction'
]
__all__ = ["GetGithubIssuesAction"]


class GetGithubIssuesAction(Action):
#def run(self, token, username, delta):
# def run(self, token, username, delta):
def run(self, username, delta, token=None):
time_delta = get_timedelta_object_from_delta_arg(delta)
token = self.config['github_token']
token = self.config["github_token"]
github = Github(token)

# NOTE: We try to retrieve organization first, it that doesnt' work, we fall back to a user
Expand All @@ -41,5 +39,7 @@ def run(self, username, delta, token=None):
except UnknownObjectException:
github_user = github.get_user(username)

result = get_issues_and_prs_for_user(github_user=github_user, time_delta=time_delta)
result = get_issues_and_prs_for_user(
github_user=github_user, time_delta=time_delta
)
return result
16 changes: 7 additions & 9 deletions actions/lib/forum_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

import feedparser

__all__ = [
'get_forum_posts'
]
__all__ = ["get_forum_posts"]


def get_forum_posts(feed_url, delta=timedelta(days=1, minutes=10)):
Expand All @@ -16,27 +14,27 @@ def get_forum_posts(feed_url, delta=timedelta(days=1, minutes=10)):
"""
feed = feedparser.parse(feed_url)

filter_date = (datetime.utcnow() - delta)
filter_date = datetime.utcnow() - delta

result = []
for item in feed['items']:
published_parsed = item.get('published_parsed', None)
for item in feed["items"]:
published_parsed = item.get("published_parsed", None)

if published_parsed:
published_dt = datetime.fromtimestamp(time.mktime(published_parsed))
else:
published_dt = None

if published_dt and (published_dt > filter_date):
item['published_dt'] = published_dt
item["published_dt"] = published_dt
result.append(item)

# Items are sorted in the oldest to newest order
result = sorted(result, key=lambda x: x['published_dt'])
result = sorted(result, key=lambda x: x["published_dt"])

# Remove complex types (datetime, etc)
# TODO: Add escape Jinja filter which is available to Orquesta workflows
keys_to_remove = ['published_dt', 'published_parsed', 'summary', 'summary_detail']
keys_to_remove = ["published_dt", "published_parsed", "summary", "summary_detail"]
for item in result:
for key in keys_to_remove:
if key in item:
Expand Down
Loading