-
Notifications
You must be signed in to change notification settings - Fork 16
76 lines (61 loc) · 2.46 KB
/
process_csv.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: Update CSV Files
on:
workflow_dispatch: # Allows the workflow to be triggered manually
jobs:
update_csv:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: release_stats
- name: Set up Git configuration
run: |
git config --local user.email "[email protected]"
git config --local user.name "SapMachine Github Actions Bot"
- name: Fetch and process CSV files
run: |
GITHUB_FOLDER="https://api.github.com/repos/SAP/SapMachine-infrastructure/contents/stats?ref=release_stats"
response=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$GITHUB_FOLDER")
files=$(echo "$response" | jq -r '.[] | select(.name | endswith(".csv")) | .download_url')
BRANCH_NAME="update-csv-$(date +%s)"
git checkout -b "$BRANCH_NAME"
for file in $files; do
echo "Processing $file"
csv_content=$(curl -s "$file")
# Debug: Print the first 3 lines of the original content
echo "Original Content:"
echo "$csv_content" | head -n 3
if [[ -z "$csv_content" ]]; then
echo "No content found for $file"
continue
fi
modified_content=$(echo "$csv_content" | awk -F, '
{
for (i = 1; i <= NF; i++) {
if ($i ~ /\.rpm$/ && $(i+5) == "") {
$(i+5) = "linux"; # Change the os_name field
}
}
print $0
}')
# Debug: Print the modified content
echo "Modified Content:"
echo "$modified_content" | head -n 3
if [[ "$csv_content" != "$modified_content" ]]; then
temp_file="modified_${file##*/}"
echo "$modified_content" > "$temp_file"
mv "$temp_file" "stats/${file##*/}"
echo "Updated stats/${file##*/}"
else
echo "No changes made to $file"
fi
done
git add stats/*.csv
git commit -m "Update CSV files: set os_name to Linux for RPM files"
if ! git diff --cached --quiet; then
git push origin "$BRANCH_NAME"
hub pull-request -m "Update CSV files: set os_name to Linux for RPM files" || echo "Failed to create PR."
else
echo "No changes made; skipping PR creation."
fi