Skip to content

Commit

Permalink
Stop creating the matrix entries manually
Browse files Browse the repository at this point in the history
h/t Zhian for the much improved way to generate the required
data using jq
  • Loading branch information
bsweger committed Jan 24, 2025
1 parent 0c59b8c commit 8b9d56e
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions .github/shared/shared-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,9 @@ generate_weekly_dates() {
local weeks=$2
local current_date=$start_date

# Format for GitHub Actions matrix
echo -n '{"include":['

for ((i=1; i<=$weeks; i++)); do
current_date=$(date -d "$current_date - 7 days" +%Y-%m-%d)
if [ $i -eq $weeks ]; then
# last item does not get a trailing comma
echo -n "{\"nowcast-date\":\"$current_date\"}"
else
echo -n "{\"nowcast-date\":\"$current_date\"},"
fi
done

echo ']}'
# Format a series of dates for GitHub Actions matrix
seq 0 7 $(bc --expression="7 * $weeks") \
| xargs -I {} date -d "$start_date -{} days" +%Y-%m-%d \
| jq -R \
| jq -s '. | map({"nowcast-date": .}) | {"include": .}'
}

0 comments on commit 8b9d56e

Please sign in to comment.