Skip to content

Commit 0d546eb

Browse files
ishaankalrapramodh-ayyappan
authored andcommitted
Github actions fixes (#249)
* github actions fixes * changed the env variable name
1 parent a6d5c9a commit 0d546eb

File tree

6 files changed

+99
-2
lines changed

6 files changed

+99
-2
lines changed

.github/workflows/cleanup.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Cleanup Feature Branch Modules
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
cleanup:
11+
runs-on: iac-arc
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Create control planes JSON file
18+
id: set_control_planes
19+
run: |
20+
set -e
21+
set -o pipefail
22+
JSON_CONTENT='${{ vars.DEV_CONTROL_PLANES }}'
23+
echo "$JSON_CONTENT" > control_planes.json
24+
25+
- name: Create secrets JSON file
26+
id: set_secrets
27+
run: |
28+
echo '${{ toJson(secrets) }}' > secrets.json
29+
30+
- name: Execute cleanup script
31+
env:
32+
GITHUB_REF_NAME: ${{ github.ref }}
33+
run: python .github/workflows/innersourcing/cleanup.py
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import requests
2+
import os
3+
import json
4+
import base64
5+
from requests.auth import HTTPBasicAuth
6+
7+
def read_json_file(file_path):
8+
try:
9+
with open(file_path, "r", encoding='utf-8') as f:
10+
return json.load(f)
11+
except Exception as e:
12+
print(f"Error reading JSON file at {file_path}: {e}", flush=True)
13+
return None
14+
15+
def get(url, username, password, params):
16+
"""Makes a GET API call and returns the response data or prints an error if the response is non-200."""
17+
try:
18+
response = requests.get(url, auth=HTTPBasicAuth(username, password), params=params)
19+
20+
# Check if the response status code is not 200
21+
if response.status_code != 200:
22+
print(f"Error: Received status code {response.status_code}.")
23+
print("Response message:", response.text) # Print the error message from the response
24+
return None
25+
26+
return response.json()
27+
except requests.exceptions.RequestException as e:
28+
print(f"Error during API call: {e}")
29+
return None
30+
31+
def delete(url, username, password):
32+
"""Makes a DELETE API call and returns the response data or prints an error if the response is non-200."""
33+
try:
34+
response = requests.delete(url, auth=HTTPBasicAuth(username, password))
35+
36+
# Check if the response status code is not 200
37+
if response.status_code != 200:
38+
print(f"Error: Received status code {response.status_code}.")
39+
print("Response message:", response.text) # Print the error message from the response
40+
return None
41+
42+
return response.json()
43+
except requests.exceptions.RequestException as e:
44+
print(f"Error during API call: {e}")
45+
return None
46+
47+
if __name__ == '__main__':
48+
# Load control planes and secrets
49+
control_planes = read_json_file('control_planes.json')
50+
secrets = read_json_file('secrets.json')
51+
feature_branch_name = os.getenv('GITHUB_REF_NAME', 'refs/heads/develop')
52+
53+
for key, value in control_planes.items():
54+
cp_url = value.get('URL', "")
55+
username = value.get('Username', "")
56+
token = secrets.get(value.get('TokenRef', ""), '')
57+
# Assuming the first URL is used for API calls
58+
modules = get(cp_url + '/cc-ui/v1/modules/all', username, token, {'allowPreviewModules': 'true'})
59+
60+
for module in modules:
61+
version = module.get('version', '')
62+
if f'-{feature_branch_name}' in version:
63+
module_id = module.get('id', '')
64+
delete(cp_url + f'/cc-ui/v1/modules/{module_id}', username, token)
65+
print(f"Deleted module with ID: {module_id} from control plane {cp_url}")
File renamed without changes.
File renamed without changes.
File renamed without changes.

.github/workflows/validate-bootstrapper.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ concurrency:
1313
jobs:
1414
validate-bootstrapper:
1515
runs-on: iac-arc
16-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1716
outputs:
1817
script_output: ${{ steps.run.outputs.script_output }}
1918
exit_status: ${{ steps.run.outputs.exit_status }}
@@ -29,7 +28,7 @@ jobs:
2928
ROOT_TOKEN: ${{ secrets.ROOT_TOKEN }}
3029
run: |
3130
set +e
32-
output=$(python .github/workflows/validate-bootstrapper.py)
31+
output=$(python .github/workflows/innersourcing/validate-bootstrapper.py)
3332
exit_status=${PIPESTATUS[0]}
3433
echo "script_output<<EOF" >> $GITHUB_OUTPUT
3534
echo "$output" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)