-
-
Notifications
You must be signed in to change notification settings - Fork 137
102 lines (95 loc) · 3.65 KB
/
distrolist.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Check/Generate distrolist
permissions:
contents: write
pull-requests: write
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
push:
branches:
- master
jobs:
gen-distrolist:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
ref: master
- name: Generate distrolist
run: |
function get_distrolist() {
local target="${1}" location="${2}"
mapfile -t "${target}" < <(curl -fsSL "${location}"/{ubuntu.csv,debian.csv} \
| awk -F ',' -v current_date="$(date +'%Y-%m-%d')" '
BEGIN {
is_first = 1
}
$3 == "series" {
if (is_first) {
print "ubuntu:"
is_first = 0
} else {
print " devel\ndebian:"
}
next
}
NR > 1 && (($6 > current_date) || ($7 > current_date) || ($6 == "")) &&
($4 <= current_date) && $3 != "experimental" {
gsub(" LTS", "", $1);
if ($1 != "") {
print " " $3 "/" $1
} else {
print " " $3
}
}'
)
}
get_distrolist parsed_distros "https://salsa.debian.org/debian/distro-info-data/-/raw/main"
if [[ -z "${parsed_distros[*]}" ]]; then
[[ $(dpkg-query -W --showformat='${db:Status-Status}' "distro-info-data" 2> /dev/null) != "installed" ]] \
&& { apt-get update && apt-get install distro-info-data; }
get_distrolist parsed_distros "file:///usr/share/distro-info"
fi
printf "%s\n" "${parsed_distros[@]}" > distrolist
- name: Calculate diff + PR title
id: calc_pr
run: |
diff_output="$(git diff --unified=0 distrolist)"
if [[ -z "${diff_output}" ]]; then
echo "No changes to distrolist."
echo "changes_detected=false" >> $GITHUB_ENV
exit 0
else
echo "changes_detected=true" >> $GITHUB_ENV
fi
added_entries="$(echo "$diff_output" | grep '^+ ' | sed 's/^\+ //' | awk -v ORS=', ' '{print "`"$0"`"}' | sed 's/, $//')"
removed_entries="$(echo "$diff_output" | grep '^- ' | sed 's/^- //' | awk -v ORS=', ' '{print "`"$0"`"}' | sed 's/, $//')"
title="upd(distrolist): "
if [[ -n "$added_entries" && -z "$removed_entries" ]]; then
title+="add ${added_entries}"
elif [[ -z "$added_entries" && -n "$removed_entries" ]]; then
title+="rm ${removed_entries}"
elif [[ -n "$added_entries" && -n "$removed_entries" ]]; then
title+="add ${added_entries}; rm ${removed_entries}"
fi
echo "distlist_title=${title}" >> $GITHUB_ENV
echo "distlist_body=Automatically generated by CI" >> $GITHUB_ENV
dl_hash="$(echo -n "${title}" | sha256sum | cut -c1-8)"
if git ls-remote --heads origin | grep "update-distrolist-${dl_hash}"; then
echo "No changes to distrolist."
echo "changes_detected=false" >> $GITHUB_ENV
exit 0
fi
echo "dl_hash=${dl_hash}" >> $GITHUB_ENV
- name: Create PR if changes detected
if: env.changes_detected == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
add-paths: distrolist
base: master
branch: update-distrolist-${{ env.dl_hash }}
title: ${{ env.distlist_title }}
body: ${{ env.distlist_body }}