-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse metadata deletions in beta-test-env workflow
Add functionality to parse metadata deletions from log output and report them. * **Add `parse_metadata_deletions.py` script:** - Create a Python script to parse metadata deletions from log output. - Define a function to extract metadata type and name pairs and return them as JSON. * **Modify `.github/workflows/beta-test-env.yml`:** - Add a step to run the `parse_metadata_deletions.py` script after the `Deploy to Packaging Org` step. - Capture the output of the `cci flow run ci_master` command and pass it to the script. - Add steps to report metadata deletions via a Job Summary Report, JSON artifact, and GitHub Check. - Handle the scenario where parsing the log output fails, fail the build, and output details of why the parser failed. * **Add `create_github_check.py` script:** - Create a Python script to create a GitHub Check for metadata deletions. - Define a function to create a new Check called `Package Metadata Deletions` with a status of `needs attention` if new metadata deletions were found. * **Modify `Dockerfile`:** - Combine the d2x user creation, chmod, and writing to bashrc files into a single RUN. - Add a step to copy the `scripts` directory into the Docker image and make scripts executable. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/muselab-d2x/d2x/tree/cumulusci-next?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
Showing
5 changed files
with
115 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import requests | ||
import json | ||
import os | ||
|
||
def create_github_check(metadata_deletions): | ||
repo = os.getenv('GITHUB_REPOSITORY') | ||
sha = os.getenv('GITHUB_SHA') | ||
app_id = os.getenv('GITHUB_APP_ID') | ||
app_key = os.getenv('GITHUB_APP_KEY') | ||
|
||
url = f"https://api.github.com/repos/{repo}/check-runs" | ||
headers = { | ||
"Authorization": f"Bearer {app_key}", | ||
"Accept": "application/vnd.github.v3+json" | ||
} | ||
data = { | ||
"name": "Package Metadata Deletions", | ||
"head_sha": sha, | ||
"status": "completed", | ||
"conclusion": "neutral", | ||
"output": { | ||
"title": "Metadata Deletions", | ||
"summary": "The following metadata deletions were found:", | ||
"text": json.dumps(metadata_deletions, indent=2) | ||
} | ||
} | ||
|
||
if metadata_deletions: | ||
data["conclusion"] = "action_required" | ||
|
||
response = requests.post(url, headers=headers, json=data) | ||
response.raise_for_status() | ||
|
||
if __name__ == "__main__": | ||
with open('metadata_deletions.json') as f: | ||
metadata_deletions = json.load(f) | ||
create_github_check(metadata_deletions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import re | ||
import json | ||
|
||
def parse_metadata_deletions(log_content): | ||
deletions = [] | ||
deletion_section = False | ||
|
||
for line in log_content.splitlines(): | ||
if "Deleting metadata:" in line: | ||
deletion_section = True | ||
continue | ||
if deletion_section: | ||
if line.strip() == "": | ||
break | ||
match = re.match(r"\s*(\w+):\s*(\w+)", line) | ||
if match: | ||
metadata_type, metadata_name = match.groups() | ||
deletions.append({"type": metadata_type, "name": metadata_name}) | ||
|
||
return json.dumps(deletions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
parse_metadata_deletions() { | ||
local log_content="$1" | ||
local deletions=() | ||
local deletion_section=false | ||
|
||
while IFS= read -r line; do | ||
if [[ "$line" == *"Deleting metadata:"* ]]; then | ||
deletion_section=true | ||
continue | ||
fi | ||
if $deletion_section; then | ||
if [[ -z "$line" ]]; then | ||
break | ||
fi | ||
if [[ "$line" =~ ^[[:space:]]*([[:alnum:]]+):[[:space:]]*([[:alnum:]]+)$ ]]; then | ||
local metadata_type="${BASH_REMATCH[1]}" | ||
local metadata_name="${BASH_REMATCH[2]}" | ||
deletions+=("{\"type\":\"$metadata_type\",\"name\":\"$metadata_name\"}") | ||
fi | ||
fi | ||
done <<< "$log_content" | ||
|
||
echo "[${deletions[*]}]" | ||
} | ||
|
||
log_content=$(cat) | ||
parse_metadata_deletions "$log_content" |