Skip to content

Commit dfa93f0

Browse files
authored
Innersourcing cleanup workflow fixes (#250)
* Cleanup workflow fixes * cleanup workflow fixes * updated the if condition * added a print statement * added a print statement * updated branch in preview * updated branch in preview * updated the delete api to not return JSON * removed print statement * updated the delete print statement
1 parent cc90ee3 commit dfa93f0

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

.github/workflows/cleanup.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
name: Cleanup Feature Branch Modules
1+
name: Cleanup Preview Modules
22

33
on:
44
workflow_dispatch:
5-
push:
6-
branches:
7-
- master
5+
pull_request:
6+
types: [ closed ]
7+
branches: [ 'master' ]
88

99
jobs:
1010
cleanup:
11+
if: (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch'
1112
runs-on: iac-arc
1213

1314
steps:
@@ -29,5 +30,5 @@ jobs:
2930
3031
- name: Execute cleanup script
3132
env:
32-
GITHUB_REF_NAME: ${{ github.ref }}
33+
GITHUB_REF_NAME: ${{ github.event_name == 'workflow_dispatch' && github.ref || github.event.pull_request.head.ref }}
3334
run: python .github/workflows/innersourcing/cleanup.py

.github/workflows/innersourcing/cleanup.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,16 @@ def delete(url, username, password):
3737
if response.status_code != 200:
3838
print(f"Error: Received status code {response.status_code}.")
3939
print("Response message:", response.text) # Print the error message from the response
40-
return None
4140

42-
return response.json()
4341
except requests.exceptions.RequestException as e:
4442
print(f"Error during API call: {e}")
45-
return None
4643

4744
if __name__ == '__main__':
4845
# Load control planes and secrets
4946
control_planes = read_json_file('control_planes.json')
5047
secrets = read_json_file('secrets.json')
51-
feature_branch_name = os.getenv('GITHUB_REF_NAME', 'refs/heads/develop')
48+
feature_branch_name = os.getenv('GITHUB_REF_NAME')
49+
print(f'Cleaning Facets preview modules for branch {feature_branch_name}')
5250

5351
for key, value in control_planes.items():
5452
cp_url = value.get('URL', "")
@@ -59,7 +57,10 @@ def delete(url, username, password):
5957

6058
for module in modules:
6159
version = module.get('version', '')
62-
if f'-{feature_branch_name}' in version:
60+
intent = module.get('intent', '')
61+
flavor = module.get('flavor', '')
62+
stage = module.get('stage', '')
63+
if f'-{feature_branch_name}' in version and stage == "PREVIEW":
6364
module_id = module.get('id', '')
6465
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}")
66+
print(f"Deleted module with ID: {module_id} Intent: {intent} Flavor: {flavor} Version: {version} from control plane {cp_url}")

.github/workflows/preview.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
run: |
6060
set -e
6161
set -o pipefail
62-
GITHUB_REF="${{ github.ref }}"
62+
GITHUB_REF="${{ github.ref_name }}"
6363
FACETS_YAML_PATH="$MODULE_DIR_PATH/facets.yaml"
6464
# Check if facets.yaml exists
6565
if [ ! -f "$FACETS_YAML_PATH" ]; then

0 commit comments

Comments
 (0)