Skip to content

Commit 306c588

Browse files
committed
fix(GithubAction): workflow altered
1 parent 8e27165 commit 306c588

File tree

9 files changed

+167
-40
lines changed

9 files changed

+167
-40
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ If applicable, add screenshots to help explain your problem.
2727

2828
**Additional context**
2929
Add any other context about the problem here.
30-
Were you able to avoid the problem by changing your application code slightly?
30+
Were you able to avoid the problem by changing your application code slightly?

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ A clear and concise description of what you want to happen.
1717
A clear and concise description of any alternative solutions or features you've considered.
1818

1919
**Additional context**
20-
Add any other context or screenshots about the feature request here.
20+
Add any other context or screenshots about the feature request here.

.github/pull_request_template.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
## PR summary
22
<!-- please include a brief summary of the changes in this PR -->
33

4-
**Fixes:** <! -- link to issue -->
54

65
## PR Checklist
76
Please make sure that your PR fulfills the following requirements:
87
- [ ] The commit message follows the [Angular Commit Message Guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines).
98
- [ ] Tests for the changes have been added (for bug fixes / features)
109
- [ ] Docs have been added / updated (for bug fixes / features)
1110

12-
## PR Type
13-
<!-- Please check the one that applies to this PR using "x". -->
14-
- [ ] Bugfix
15-
- [ ] Feature
16-
- [ ] Code style update (formatting, local variables)
17-
- [ ] Refactoring (no functional changes, no api changes)
18-
- [ ] New tests
19-
- [ ] Build/CI related changes
20-
- [ ] Documentation content changes
21-
- [ ] Other (please describe)
22-
23-
## What is the current behavior?
24-
<!-- Please describe the current behavior that you are modifying. -->
25-
26-
## What is the new behavior?
27-
<!-- Please describe the new behavior after your change. -->
11+
## Current vs new behavior
12+
<!-- Please describe the current behavior that you are modifying and the new behavior. -->
2813

2914
## Does this PR introduce a breaking change?
3015
- [ ] Yes

.github/workflows/main.yaml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: CI/CD Pipeline
2+
on: [push, pull_request, workflow_dispatch]
3+
4+
jobs:
5+
verify:
6+
runs-on: ubuntu-latest
7+
if: "!startsWith(github.event.head_commit.message, 'chore') && !startsWith(github.ref, 'refs/tags/v')"
8+
strategy:
9+
matrix:
10+
python-version: [3.6, 3.7, 3.8, 3.9]
11+
steps:
12+
- uses: actions/checkout@v1
13+
14+
- name: setting up python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
19+
- name: install dependencies
20+
run: make setup
21+
22+
- name: linting
23+
run: make lint
24+
25+
test:
26+
runs-on: ubuntu-latest
27+
if: "!startsWith(github.event.head_commit.message, 'chore') && !startsWith(github.ref, 'refs/tags/v')"
28+
strategy:
29+
matrix:
30+
python-version: [3.6, 3.7, 3.8, 3.9]
31+
steps:
32+
- name: setup extensions
33+
uses: actions/checkout@v1
34+
35+
- name: setting up python ${{ matrix.python-version }}
36+
uses: actions/setup-python@v2
37+
with:
38+
python-version: ${{ matrix.python-version }}
39+
40+
- name: install dependencies
41+
run: make setup
42+
43+
- name: running unit tests
44+
run: make test-unit
45+
46+
- name: running integration tests
47+
env:
48+
ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
49+
FINDINGS_ENV: ${{ secrets.FINDINGS_ENV }}
50+
NOTIFICATIONS_ENV: ${{ secrets.NOTIFICATIONS_ENV }}
51+
CONFIGURATION_GOVERNANCE_ENV: ${{ secrets.CONFIGURATION_GOVERNANCE_ENV }}
52+
RESOURCE_GROUP_ID: ${{ secrets.RESOURCE_GROUP_ID }}
53+
run: build/testScript.sh
54+
55+
release:
56+
runs-on: ubuntu-latest
57+
needs: [verify, test]
58+
if: "github.event_name == 'push' && github.ref == 'refs/heads/main' && !startsWith(github.event.head_commit.message, 'chore')"
59+
steps:
60+
- name: setup extensions
61+
uses: actions/checkout@v1
62+
63+
- name: setup nodejs
64+
uses: actions/setup-node@v2
65+
with:
66+
node-version: '12'
67+
68+
- name: release using semantic-release
69+
env:
70+
PYPI_USER: ${{ secrets.PYPI_USER }}
71+
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
72+
GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }}
73+
GIT_AUTHOR_NAME: scccomm
74+
GIT_AUTHOR_EMAIL: [email protected]
75+
GIT_COMMITTER_NAME: scccomm
76+
GIT_COMMITTER_EMAIL: [email protected]
77+
run: |
78+
sudo apt-get update
79+
sudo apt-get install python
80+
pip install --user bumpversion
81+
npm install @semantic-release/changelog
82+
npm install @semantic-release/exec
83+
npm install @semantic-release/git
84+
npm install @semantic-release/github
85+
npx semantic-release
86+
87+
publish:
88+
runs-on: ubuntu-latest
89+
if: "github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')"
90+
steps:
91+
- name: setup extensions
92+
uses: actions/checkout@v1
93+
94+
- name: publish to pypi
95+
uses: pypa/gh-action-pypi-publish@release/v1
96+
with:
97+
user: ${{ secrets.PYPI_USER }}
98+
password: ${{ secrets.PYPI_PASSWORD }}
99+
repository_url: https://upload.pypi.org/legacy
100+
101+
documentation:
102+
runs-on: ubuntu-latest
103+
if: "github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')"
104+
steps:
105+
- name: setup extensions
106+
uses: actions/checkout@v1
107+
108+
- name: install pdoc
109+
run: pip install pdoc
110+
111+
- name: generate pydoc
112+
run: pdoc --html ibm_scc
113+
114+
- name: deploy gopages to gh-pages
115+
uses: crazy-max/ghaction-github-pages@v1
116+
with:
117+
target_branch: gh-pages
118+
build_dir: html/ibm_scc
119+
env:
120+
GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
[![Build Status](https://travis-ci.com/IBM/scc-python-sdk.svg?branch=main)](https://travis-ci.com/github/IBM/scc-python-sdk)
1+
[![CI/CD Pipeline](https://github.com/IBM/scc-python-sdk/actions/workflows/main.yaml/badge.svg)](https://github.com/IBM/scc-python-sdk/actions/workflows/main.yaml)
2+
[![PyDoc](https://img.shields.io/static/v1?label=pydoc&message=latest&color=blue)](http://IBM.github.io/scc-python-sdk)
23
[![Release](https://img.shields.io/github/v/release/IBM/scc-python-sdk)](https://img.shields.io/github/v/release/IBM/scc-python-sdk)
34
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ibm-platform-services)](https://pypi.org/project/ibm-scc/)
45
[![PyPi](https://pypip.in/v/ibm-scc/badge.svg)](https://pypi.python.org/pypi/ibm-scc/)

build/testScript.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
set -euo pipefail
44

5-
if [[ $TRAVIS_BRANCH == "main" && $TRAVIS_PULL_REQUEST == "false" ]]; then
6-
curl https://us-south.functions.appdomain.cloud/api/v1/web/e6b54af6-ab44-4149-a8e4-e906dcc58136/default/secadvstg-location-shift.json
7-
echo "${FINDINGS_ENV}" | base64 -d >> findings_v1.env
8-
echo "${NOTIFICATIONS_ENV}" | base64 -d >> notifications_v1.env
9-
echo "${CONFIGURATION_GOVERNANCE_ENV}" | base64 -d >> configuration_governance_v1.env
10-
pytest test/integration
11-
fi
5+
curl https://us-south.functions.appdomain.cloud/api/v1/web/e6b54af6-ab44-4149-a8e4-e906dcc58136/default/secadvstg-location-shift.json
6+
echo "${FINDINGS_ENV}" | base64 -d >> findings_v1.env
7+
echo "${NOTIFICATIONS_ENV}" | base64 -d >> notifications_v1.env
8+
echo "${CONFIGURATION_GOVERNANCE_ENV}" | base64 -d >> configuration_governance_v1.env
9+
python -m pytest test/integration

test/integration/test_configuration_governance_v1.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import os
2121
import pytest
22+
import time
2223
from ibm_cloud_sdk_core import *
2324
from ibm_scc.configuration_governance_v1 import *
2425

@@ -29,6 +30,7 @@
2930
account_id = os.getenv("ACCOUNT_ID")
3031
rule_label = os.getenv("RULE_LABEL") or "sdk-it"
3132
resource_group_id = os.getenv("RESOURCE_GROUP_ID")
33+
identifier = "py-{0}".format(str(time.time()).split(".")[0])
3234

3335
rule_attachment_id_link = None
3436
rule_id_link = None
@@ -56,6 +58,31 @@ def setup_class(cls):
5658

5759
print('Setup complete.')
5860

61+
@classmethod
62+
def teardown_class(cls):
63+
if os.path.exists(config_file):
64+
os.environ['IBM_CREDENTIALS_FILE'] = config_file
65+
66+
cls.configuration_governance_service = ConfigurationGovernanceV1.new_instance(
67+
)
68+
assert cls.configuration_governance_service is not None
69+
70+
cls.config = read_external_sources(
71+
ConfigurationGovernanceV1.DEFAULT_SERVICE_NAME)
72+
assert cls.config is not None
73+
74+
print('Setup complete.')
75+
print(f'cleaning up account: {account_id} with rules labelled {rule_label}-{identifier}\n')
76+
list_rules_response = cls.configuration_governance_service.list_rules(
77+
account_id=account_id,
78+
labels=[f"{rule_label}-{identifier}"],
79+
)
80+
for rule in list_rules_response.get_result()['rules']:
81+
cls.configuration_governance_service.delete_rule(
82+
rule_id=rule['rule_id']
83+
)
84+
print("cleanup was successful\n")
85+
5986
needscredentials = pytest.mark.skipif(
6087
not os.path.exists(config_file), reason="External configuration not available, skipping..."
6188
)
@@ -91,7 +118,7 @@ def test_create_rules(self):
91118
'target': target_resource_model,
92119
'required_config': rule_required_config_model,
93120
'enforcement_actions': [enforcement_action_model],
94-
'labels': [rule_label],
121+
'labels': [f"{rule_label}-{identifier}"],
95122
}
96123

97124
# Construct a dict representation of a CreateRuleRequest model
@@ -157,7 +184,7 @@ def test_list_rules(self):
157184
account_id=account_id,
158185
transaction_id='testString',
159186
attached=True,
160-
labels=[rule_label],
187+
labels=[f"{rule_label}-{identifier}"],
161188
scopes='scope_id',
162189
limit=1000,
163190
offset=38
@@ -214,7 +241,7 @@ def test_update_rule(self):
214241
enforcement_actions=[enforcement_action_model],
215242
account_id=account_id,
216243
rule_type='user_defined',
217-
labels=[rule_label],
244+
labels=[f"{rule_label}-{identifier}"],
218245
transaction_id='testString'
219246
)
220247

test/integration/test_findings_v1.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
account_id = os.getenv("ACCOUNT_ID")
3030
provider_id = os.getenv("PROVIDER_ID", "sdk-it")
3131
testString = "testString"
32-
identifier = os.getenv("TRAVIS_JOB_ID") or time.time()
32+
identifier = "py-{0}".format(str(time.time()).split(".")[0])
3333

34-
class FindingsV1IntegrationTests():
34+
class TestFindingsV1():
3535
"""
3636
Integration Test Class for FindingsV1
3737
"""
@@ -58,6 +58,7 @@ def teardown_class(cls):
5858
os.environ['IBM_CREDENTIALS_FILE'] = config_file
5959

6060
cls.findings_service = FindingsV1.new_instance(
61+
account_id=account_id,
6162
)
6263
assert cls.findings_service is not None
6364

@@ -68,33 +69,28 @@ def teardown_class(cls):
6869
print('Setup complete.')
6970
print(f"cleaning up account: {account_id} with provider: {provider_id}\n")
7071
list_notes_response = cls.findings_service.list_notes(
71-
account_id=account_id,
7272
provider_id=provider_id,
7373
)
7474
for note in list_notes_response.get_result()["notes"]:
7575
parts = note["id"].split("-")
76-
if parts[-1]==identifier:
76+
if f"{parts[len(parts)-2]}-{parts[len(parts)-1]}" == identifier:
7777
cls.findings_service.delete_note(
78-
account_id=account_id,
7978
provider_id=provider_id,
8079
note_id=note["id"],
8180
)
8281
list_occurrences_response = cls.findings_service.list_occurrences(
83-
account_id=account_id,
8482
provider_id=provider_id,
8583
)
8684
for occurrence in list_occurrences_response.get_result()["occurrences"]:
8785
parts = occurrence["id"].split("-")
88-
if parts[-1]==identifier:
86+
if f"{parts[len(parts)-2]}-{parts[len(parts)-1]}" == identifier:
8987
cls.findings_service.delete_occurrence(
90-
account_id=account_id,
9188
provider_id=provider_id,
9289
occurrence_id=occurrence["id"],
9390
)
9491
print("cleanup was successful\n")
9592

9693
list_providers_response = cls.findings_service.list_providers(
97-
account_id=account_id,
9894
)
9995
for provider in list_providers_response.get_result()["providers"]:
10096
if provider["id"] == provider_id:

test/integration/test_notifications_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
account_id = os.getenv("ACCOUNT_ID")
2929
testString = "testString"
3030
channel_id = ""
31-
identifier = os.getenv("TRAVIS_JOB_ID") or time.time()
31+
identifier = "py-{0}".format(str(time.time()).split(".")[0])
3232

3333
class TestNotificationsV1():
3434
"""

0 commit comments

Comments
 (0)