-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58e7896
commit a3e8c32
Showing
1 changed file
with
74 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,81 +4,80 @@ on: | |
workflow_dispatch: | ||
|
||
jobs: | ||
update_csv: | ||
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 || echo "Failed to print original content" | ||
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 || echo "Failed to print modified content" | ||
if [[ "$csv_content" != "$modified_content" ]]; then | ||
# Write to a temporary file first | ||
temp_file="stats/temp_${file##*/}" | ||
echo "$modified_content" > "$temp_file" | ||
echo "Updated temp file: $temp_file" | ||
# Move the temporary file to the original location | ||
mv "$temp_file" "stats/${file##*/}" | ||
echo "Moved $temp_file to 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" || echo "No changes to commit" | ||
# Check git status | ||
git status | ||
# Check if there are any changes before trying to push | ||
if ! git diff --cached --quiet; then | ||
git push origin "$BRANCH_NAME" | ||
gh pr create --title "Update CSV files: set os_name to Linux for RPM files" --body "Automated update of CSV files." || echo "Failed to create PR." | ||
else | ||
echo "No changes made; skipping PR creation." | ||
fi | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: release_stats | ||
|
||
- name: Set up Git | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "SapMachine Github Actions Bot" | ||
- name: Fetch CSV files | ||
id: fetch_csv | ||
run: | | ||
files=$(curl -s "https://api.github.com/repos/SAP/SapMachine-infrastructure/contents/stats?ref=release_stats" | jq -r '.[].download_url') | ||
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 || echo "Failed to print original content" | ||
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 || echo "Failed to print modified content" | ||
if [[ "$csv_content" != "$modified_content" ]]; then | ||
# Write to a temporary file first | ||
temp_file="stats/temp_${file##*/}" | ||
echo "$modified_content" > "$temp_file" | ||
echo "Updated temp file: $temp_file" | ||
# Move the temporary file to the original location | ||
mv "$temp_file" "stats/${file##*/}" | ||
echo "Moved $temp_file to stats/${file##*/}" | ||
# Normalize line endings | ||
dos2unix "stats/${file##*/}" | ||
# Explicitly add the modified file | ||
git add "stats/${file##*/}" | ||
else | ||
echo "No changes made to $file" | ||
fi | ||
done | ||
git commit -m "Update CSV files: set os_name to Linux for RPM files" || echo "No changes to commit" | ||
# Create a pull request if there are changes | ||
if [ "$(git status --porcelain)" ]; then | ||
branch_name="update-csv-$(date +%s)" | ||
git checkout -b "$branch_name" | ||
git push origin "$branch_name" | ||
echo "Creating pull request..." | ||
gh pr create --title "Update CSV files" --body "This PR updates the CSV files to set os_name to Linux for RPM files." --base release_stats | ||
else | ||
echo "No changes made; skipping PR creation." | ||
fi |