Skip to content

Commit

Permalink
Add github workflow
Browse files Browse the repository at this point in the history
* Migrate from Zuul Pipelines to GitHub Workflow
* Add tox.ini

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde committed Nov 11, 2023
1 parent 142e374 commit 09a93f2
Show file tree
Hide file tree
Showing 55 changed files with 370 additions and 202 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/all_green_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: all_green

concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true

on: # yamllint disable-line rule:truthy
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- main
- 'stable-*'
tags:
- '*'

jobs:
linters:
uses: ./.github/workflows/linters.yml # use the callable linters job to run tests
sanity:
uses: ./.github/workflows/sanity.yml # use the callable sanity job to run tests
all_green:
if: ${{ always() }}
needs:
- linters
- sanity
runs-on: ubuntu-latest
steps:
- run: >-
python -c "assert set([
'${{ needs.linters.result }}',
'${{ needs.sanity.result }}'
]) == {'success'}"
11 changes: 11 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: changelog and linters

on: [workflow_call] # allow this workflow to be called from other workflows

jobs:
linters:
uses: ansible-network/github_actions/.github/workflows/tox.yml@main
with:
envname: ""
labelname: "lint"
96 changes: 96 additions & 0 deletions .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
name: sanity tests

on: [workflow_call] # allow this workflow to be called from other workflows

jobs:
sanity:
uses: ansible-network/github_actions/.github/workflows/sanity.yml@main
with:
matrix_include: "[]"
matrix_exclude: >-
[
{
"ansible-version": "stable-2.9"
},
{
"ansible-version": "stable-2.12",
"python-version": "3.7"
},
{
"ansible-version": "stable-2.12",
"python-version": "3.11"
},
{
"ansible-version": "stable-2.13",
"python-version": "3.7"
},
{
"ansible-version": "stable-2.13",
"python-version": "3.11"
},
{
"ansible-version": "stable-2.14",
"python-version": "3.7"
},
{
"ansible-version": "stable-2.14",
"python-version": "3.8"
},
{
"ansible-version": "stable-2.14",
"python-version": "3.12"
},
{
"ansible-version": "stable-2.15",
"python-version": "3.7"
},
{
"ansible-version": "stable-2.15",
"python-version": "3.8"
},
{
"ansible-version": "stable-2.15",
"python-version": "3.12"
},
{
"ansible-version": "stable-2.16",
"python-version": "3.7"
},
{
"ansible-version": "stable-2.16",
"python-version": "3.8"
},
{
"ansible-version": "stable-2.16",
"python-version": "3.9"
},
{
"ansible-version": "milestone",
"python-version": "3.7"
},
{
"ansible-version": "milestone",
"python-version": "3.8"
},
{
"ansible-version": "milestone",
"python-version": "3.9"
},
{
"ansible-version": "milestone",
"python-version": "3.12"
},
{
"ansible-version": "devel",
"python-version": "3.7"
},
{
"ansible-version": "devel",
"python-version": "3.8"
},
{
"ansible-version": "devel",
"python-version": "3.9"
}
]
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ __pycache__
# integration_config.yml contains connection info for the
# developer instance, including credentials
/tests/integration/integration_config.yml
.coverage*
htmlcov
13 changes: 6 additions & 7 deletions plugins/action/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@

import copy
from contextlib import contextmanager

import yaml
from yaml import Loader
from ansible.errors import (
AnsibleAction,
AnsibleActionFail,
AnsibleError,
AnsibleFileNotFound,
AnsibleAction,
)
from ansible.module_utils._text import to_text, to_bytes
from ansible.module_utils._text import to_bytes, to_text
from ansible.module_utils.common.validation import check_mutually_exclusive
from ansible.module_utils.six import iteritems
from ansible.plugins.action import ActionBase
from ..module_utils.api import (
FIELD_TEMPLATE,
FIELD_DATA,
)
from yaml import Loader

from ..module_utils.api import FIELD_DATA, FIELD_TEMPLATE


def get_template_args(template):
Expand Down
1 change: 0 additions & 1 deletion plugins/action/configuration_item_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from ansible.plugins.action import ActionBase
from ansible.utils.vars import merge_hash

from jinja2 import Environment


Expand Down
2 changes: 1 addition & 1 deletion plugins/inventory/now.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@
from ..module_utils.client import Client
from ..module_utils.errors import ServiceNowError
from ..module_utils.query import parse_query, serialize_query
from ..module_utils.table import TableClient
from ..module_utils.relations import (
REL_FIELDS,
REL_QUERY,
REL_TABLE,
enhance_records_with_rel_groups,
)
from ..module_utils.table import TableClient


def construct_sysparm_query(query, is_encoded_query):
Expand Down
4 changes: 1 addition & 3 deletions plugins/module_utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@
no_log=True,
fallback=(env_fallback, ["SN_CLIENT_SECRET"]),
),
custom_headers=dict(
type="dict"
),
custom_headers=dict(type="dict"),
refresh_token=dict(
type="str",
no_log=True,
Expand Down
9 changes: 3 additions & 6 deletions plugins/module_utils/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@


def _path(api_path, *subpaths):
return "/".join(
api_path
+ ("attachment",)
+ subpaths
)
return "/".join(api_path + ("attachment",) + subpaths)


class AttachmentClient:
Expand All @@ -38,7 +34,8 @@ def list_records(self, query=None):

while offset < total:
response = self.client.get(
_path(self.client.api_path), query=dict(base_query, sysparm_offset=offset)
_path(self.client.api_path),
query=dict(base_query, sysparm_offset=offset),
)

result.extend(response.json["result"])
Expand Down
5 changes: 2 additions & 3 deletions plugins/module_utils/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@

from ansible.module_utils.six import PY2
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError
from ansible.module_utils.six.moves.urllib.parse import urlencode, quote
from ansible.module_utils.six.moves.urllib.parse import quote, urlencode
from ansible.module_utils.urls import Request, basic_auth_header

from .errors import ServiceNowError, AuthError, UnexpectedAPIResponse

from .errors import AuthError, ServiceNowError, UnexpectedAPIResponse

DEFAULT_HEADERS = dict(Accept="application/json")

Expand Down
1 change: 0 additions & 1 deletion plugins/module_utils/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import re


REL_TABLE = "cmdb_rel_ci"
# sysparm_fields to be used when querying REL_TABLE. Uses dot-walking
# notation to extract fields from linked tables in a single REST API call.
Expand Down
17 changes: 9 additions & 8 deletions plugins/module_utils/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def list_records(self, table, query=None):

while offset < total:
response = self.client.get(
_path(self.client.api_path, table), query=dict(base_query, sysparm_offset=offset)
_path(self.client.api_path, table),
query=dict(base_query, sysparm_offset=offset),
)

result.extend(response.json["result"])
Expand All @@ -64,9 +65,7 @@ def get_record(self, table, query, must_exist=False):
return records[0] if records else None

def get_record_by_sys_id(self, table, sys_id):
response = self.client.get(
_path(self.client.api_path, table, sys_id)
)
response = self.client.get(_path(self.client.api_path, table, sys_id))
record = response.json["result"]

return record
Expand All @@ -76,17 +75,19 @@ def create_record(self, table, payload, check_mode, query=None):
# Approximate the result using the payload.
return payload

return self.client.post(_path(self.client.api_path, table), payload, query=_query(query)).json[
"result"
]
return self.client.post(
_path(self.client.api_path, table), payload, query=_query(query)
).json["result"]

def update_record(self, table, record, payload, check_mode, query=None):
if check_mode:
# Approximate the result by manually patching the existing state.
return dict(record, **payload)

return self.client.patch(
_path(self.client.api_path, table, record["sys_id"]), payload, query=_query(query)
_path(self.client.api_path, table, record["sys_id"]),
payload,
query=_query(query),
).json["result"]

def delete_record(self, table, record, check_mode):
Expand Down
14 changes: 7 additions & 7 deletions plugins/modules/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,16 @@

from ..module_utils import arguments, client, errors, table
from ..module_utils.api import (
table_name,
get_query_by_sys_id,
ACTION_POST,
ACTION_PATCH,
ACTION_DELETE,
field_present,
FIELD_SYS_ID,
ACTION_PATCH,
ACTION_POST,
FIELD_DATA,
FIELD_TEMPLATE,
FIELD_QUERY_PARAMS,
FIELD_SYS_ID,
FIELD_TEMPLATE,
field_present,
get_query_by_sys_id,
table_name,
)


Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/api_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@

from ..module_utils import arguments, client, errors, table, utils
from ..module_utils.api import (
transform_query_to_servicenow_query,
FIELD_COLUMNS_NAME,
POSSIBLE_FILTER_PARAMETERS,
table_name,
FIELD_COLUMNS_NAME,
transform_query_to_servicenow_query,
)


Expand Down
9 changes: 2 additions & 7 deletions plugins/modules/attachment_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,13 @@
"""


import time
import json
import os
import time

from ansible.module_utils.basic import AnsibleModule

from ..module_utils import (
arguments,
client,
attachment,
errors,
)
from ..module_utils import arguments, attachment, client, errors


def run(module, attachment_client):
Expand Down
7 changes: 1 addition & 6 deletions plugins/modules/attachment_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@

from ansible.module_utils.basic import AnsibleModule

from ..module_utils import (
arguments,
attachment,
client,
errors,
)
from ..module_utils import arguments, attachment, client, errors


def run(module, attachment_client):
Expand Down
6 changes: 2 additions & 4 deletions plugins/modules/change_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,18 @@

from ansible.module_utils.basic import AnsibleModule


from ..module_utils import (
arguments,
client,
table,
attachment,
client,
errors,
table,
utils,
validation,
)
from ..module_utils.change_request import PAYLOAD_FIELDS_MAPPING
from ..module_utils.utils import get_mapper


DIRECT_PAYLOAD_FIELDS = (
"state",
"type",
Expand Down
Loading

0 comments on commit 09a93f2

Please sign in to comment.