Skip to content

Commit 66ef126

Browse files
authored
Feat/repo readme (#3)
* add readme and stk validate action to pipe
1 parent d24114c commit 66ef126

File tree

19 files changed

+690
-167
lines changed

19 files changed

+690
-167
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Quality Check
2+
on:
3+
workflow_call:
4+
secrets:
5+
git-org-token:
6+
required: true
7+
pull_request:
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
jobs:
12+
static_tests:
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
20+
- uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Install linters
25+
run: |
26+
pip install black
27+
28+
- name: Perform lint
29+
run: |
30+
black . --check
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: STK actions quality-check
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
validate-actions:
8+
name: StackSpot Runtime (v2)
9+
runs-on: ubuntu-latest
10+
env:
11+
LANG: C.UTF-8
12+
LANGUAGE: C.UTF-8
13+
LC_ALL: C.UTF-8
14+
PYTHONIOENCODING: utf-8
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
20+
- run: sudo apt update && sudo apt install -y curl unzip git jq
21+
name: install dependencies
22+
23+
- name: Setup STK CLI
24+
run: |
25+
curl \
26+
--fail \
27+
--http2-prior-knowledge \
28+
--location \
29+
--output /tmp/stk.deb \
30+
--silent \
31+
--show-error \
32+
--tlsv1.3 \
33+
https://stk.stackspot.com/installer/linux/stk.deb
34+
sudo dpkg --install /tmp/stk.deb || echo installed
35+
rm --force /tmp/stk.deb
36+
37+
- name: Show STK CLI version
38+
run: $HOME/.stk/bin/stk --version
39+
40+
- name: Login StackSpot
41+
run: |
42+
$HOME/.stk/bin/stk login -id ${{ secrets.STK_CLIENT_ID }} -key ${{ secrets.STK_CLIENT_SECRET }} -r ${{ secrets.STK_REALM }}
43+
44+
- name: Validate main action
45+
run: |
46+
$HOME/.stk/bin/stk validate action
47+
48+
- name: Validate runtime-cancel-run-action action
49+
run: |
50+
cd runtime-cancel-run-action
51+
$HOME/.stk/bin/stk validate action
52+
53+
- name: Validate runtime-create-manifest-action action
54+
run: |
55+
cd runtime-create-manifest-action
56+
$HOME/.stk/bin/stk validate action
57+
58+
- name: Validate runtime-deploy-action action
59+
run: |
60+
cd runtime-deploy-action
61+
$HOME/.stk/bin/stk validate action
62+
63+
- name: Validate runtime-destroy-action action
64+
run: |
65+
cd runtime-destroy-action
66+
$HOME/.stk/bin/stk validate action
67+
68+
- name: Validate runtime-iac-action action
69+
run: |
70+
cd runtime-iac-action
71+
$HOME/.stk/bin/stk validate action
72+
73+
- name: Validate runtime-manager-action action
74+
run: |
75+
cd runtime-manager-action
76+
$HOME/.stk/bin/stk validate action
77+
78+
- name: Validate runtime-rollback-action action
79+
run: |
80+
cd runtime-rollback-action
81+
$HOME/.stk/bin/stk validate action
82+
83+
- name: Validate runtime-matrix action
84+
run: |
85+
cd runtime-matrix
86+
$HOME/.stk/bin/stk validate action
87+
88+

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,43 @@
1-
# workflow-stackspot-actions-runtime-selfhosted
2-
workflow-stackspot-actions-runtime-selfhosted
1+
# StackSpot actions runtimes repository
2+
3+
This repository contains various StackSpot Actions that can be used to automate processes in CI/CD pipelines. Additionally, there is a main action that orchestrates the execution of the other actions, simplifying the integration and management of multiple tasks in a single workflow.
4+
5+
## Repository Structure
6+
7+
8+
## Requirements
9+
10+
Before using the actions in this repository, ensure that you have the following requirements:
11+
12+
* StackSpot CLI installed and configured.
13+
14+
## How to Use
15+
16+
### Deploy
17+
18+
```bash
19+
stk run action <path-where-u-cloned-the-repository> \
20+
--workflow_type deploy \
21+
--environment "<environment>" \
22+
--version_tag "<version-tag>" \
23+
--repository_name "<repository-name>" \
24+
--client_id "<stackspot-client-id>" \
25+
--client_key "<stackspot-client-key>" \
26+
--client_realm "<stackspot-client-realm>" \
27+
--aws_access_key_id "<aws-access-key-id>" \
28+
--aws_secret_access_key "<aws-secret-access-key>" \
29+
--aws_session_token "<aws-session-token>" \
30+
--tf_state_bucket_name "<tf_state_bucket>" \
31+
--iac_bucket_name "<iac_bucket_name>" \
32+
--tf_state_region "<aws-region>" \
33+
--iac_region "<aws-region>" \
34+
--aws_region "<aws-region>"
35+
```
36+
37+
### Cancel
38+
39+
```bash
40+
stk run action <path-where-u-cloned-the-repository> \
41+
--workflow_type cancel \
42+
--run_id "<run_id>"
43+
```

action.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ spec:
1313
inputs:
1414
- label: Workflow type
1515
name: workflow_type
16-
type: text
16+
type: select
17+
items:
18+
- deploy
19+
- cancel
1720
required: true
1821
python:
1922
workdir: .

docs/en-us/docs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#

runtime-cancel-run-action/script.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from oscli.core.http import post_with_authorization
33

44

5-
STK_RUNTIME_MANAGER_DOMAIN = os.getenv("STK_RUNTIME_MANAGER_DOMAIN", "https://runtime-manager.v1.stackspot.com")
5+
STK_RUNTIME_MANAGER_DOMAIN = os.getenv(
6+
"STK_RUNTIME_MANAGER_DOMAIN", "https://runtime-manager.v1.stackspot.com"
7+
)
68

79

810
def run(metadata):
@@ -40,17 +42,17 @@ def run(metadata):
4042
print the error details and exit the program.
4143
4244
"""
43-
45+
4446
# Extract the RUN_ID from the metadata inputs
45-
RUN_ID = metadata.inputs['run_id']
47+
RUN_ID = metadata.inputs["run_id"]
4648
print(f"> Requesting Run {RUN_ID} to be cancelled")
47-
49+
4850
# Send a POST request to cancel the run
4951
cancel_request = post_with_authorization(
50-
url=f"{STK_RUNTIME_MANAGER_DOMAIN}/v1/run/cancel/{RUN_ID}?force=true",
51-
headers={'Content-Type': 'application/json'},
52+
url=f"{STK_RUNTIME_MANAGER_DOMAIN}/v1/run/cancel/{RUN_ID}?force=true",
53+
headers={"Content-Type": "application/json"},
5254
body=None,
53-
timeout=20
55+
timeout=20,
5456
)
5557

5658
# Handle the response based on the status code
@@ -66,4 +68,4 @@ def run(metadata):
6668
print("- Status:", cancel_request.status_code)
6769
print("- Error:", cancel_request.reason)
6870
print("- Response:", cancel_request.text)
69-
exit(1)
71+
exit(1)

runtime-create-manifest-action/script.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
from typing import List, Optional
55

66
# Configure logging
7-
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
7+
logging.basicConfig(
8+
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
9+
)
810

911

1012
def check(result: subprocess.Popen) -> None:
1113
"""
12-
Checks the result of a subprocess execution. If the return code is non-zero,
14+
Checks the result of a subprocess execution. If the return code is non-zero,
1315
it logs an error message and exits the program.
1416
1517
Args:
@@ -35,12 +37,14 @@ def run_command(command: List[str]) -> subprocess.Popen:
3537
try:
3638
logging.info(f"Running command: {' '.join(command)}")
3739
# Start the process
38-
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
39-
40+
process = subprocess.Popen(
41+
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
42+
)
43+
4044
# Read and print output in real-time
4145
for line in process.stdout:
4246
print(line, end="") # Print each line as it is produced
43-
47+
4448
# Check the result after the process completes
4549
check(process)
4650
return process
@@ -49,7 +53,7 @@ def run_command(command: List[str]) -> subprocess.Popen:
4953
logging.error(str(e))
5054
sys.exit(1)
5155

52-
56+
5357
def run(metadata) -> None:
5458
"""
5559
Executes a cmd of StackSpot CLI to deploy a plan.
@@ -58,10 +62,10 @@ def run(metadata) -> None:
5862
metadata (object): An object containing the inputs required for the execution.
5963
"""
6064
stk = sys.argv[0]
61-
environment = metadata.inputs['environment']
62-
version_tag = metadata.inputs['version_tag']
63-
open_api_path: Optional[str] = metadata.inputs.get('open_api_path')
64-
dynamic_inputs: Optional[str] = metadata.inputs.get('dynamic_inputs')
65+
environment = metadata.inputs["environment"]
66+
version_tag = metadata.inputs["version_tag"]
67+
open_api_path: Optional[str] = metadata.inputs.get("open_api_path")
68+
dynamic_inputs: Optional[str] = metadata.inputs.get("dynamic_inputs")
6569

6670
# Prepare optional parameters for the deploy command
6771
optional_params = []
@@ -71,7 +75,15 @@ def run(metadata) -> None:
7175
optional_params += dynamic_inputs.split()
7276

7377
# Prepare the StackSpot CLI commands
74-
stk_deploy_plan = [stk, "deploy", "plan", "--env", environment, "--version", version_tag] + optional_params
78+
stk_deploy_plan = [
79+
stk,
80+
"deploy",
81+
"plan",
82+
"--env",
83+
environment,
84+
"--version",
85+
version_tag,
86+
] + optional_params
7587

7688
# Execute the commands
77-
run_command(stk_deploy_plan)
89+
run_command(stk_deploy_plan)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#

0 commit comments

Comments
 (0)