-
-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathupdate_readme.nu
executable file
·212 lines (182 loc) · 7.13 KB
/
update_readme.nu
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env nu
# Load required data
def load_flake [] {
nix flake show --json --all-systems | from json
}
def find_index [list: list<any>, value: any] {
let enumerated = ($list | enumerate)
let found = ($enumerated | where item == $value | first)
if ($found | is-empty) {
-1
} else {
$found.index
}
}
def get_systems [flake_json] {
$flake_json | get packages | columns
}
def get_postgres_versions [flake_json] {
let packages = ($flake_json | get packages | get aarch64-linux)
# Get available versions from postgresql packages
let available_versions = ($packages
| columns
| where {|col|
# Match exact postgresql_<number> or postgresql_orioledb-<number>
$col =~ "^postgresql_\\d+$" or $col =~ "^postgresql_orioledb-\\d+$"
}
| each {|pkg_name|
let is_orioledb = ($pkg_name =~ "orioledb")
let pkg_info = ($packages | get $pkg_name)
let version = if $is_orioledb {
$pkg_info.name | str replace "postgresql-" "" | split row "_" | first # Get "17" from "postgresql-17_5"
} else {
$pkg_info.name | str replace "postgresql-" "" | split row "." | first # Get "15" from "postgresql-15.8"
}
{
version: $version,
is_orioledb: $is_orioledb,
name: $pkg_info.name
}
}
)
$available_versions | uniq | sort-by version
}
def get_src_url [pkg_attr] {
let result = (do { nix eval $".#($pkg_attr).src.url" } | complete)
if $result.exit_code == 0 {
$result.stdout | str trim | str replace -a '"' '' # Remove all quotes
} else {
null
}
}
def get_extension_info [flake_json, pg_info] {
let major_version = ($pg_info.version | split row "." | first)
let version_prefix = if $pg_info.is_orioledb {
"psql_orioledb-" + $major_version + "/exts/"
} else {
"psql_" + $major_version + "/exts/"
}
print $"Looking for extensions with prefix: ($version_prefix)"
let sys_packages = ($flake_json | get packages | get aarch64-linux)
let ext_names = ($sys_packages
| columns
| where {|col| $col =~ $"^($version_prefix)"}
)
print $"Found extensions: ($ext_names | str join ', ')"
let all_exts = ($ext_names | each {|ext_name|
let ext_info = ($sys_packages | get $ext_name)
let name = ($ext_name | str replace $version_prefix "")
let version = if $name == "orioledb" {
$ext_info.name # Use name directly for orioledb
} else if ($ext_info.name | str contains "-") {
$ext_info.name | split row "-" | last
} else {
$ext_info.name
}
let src_url = (get_src_url $ext_name)
{
name: $name,
version: $version,
description: $ext_info.description,
url: $src_url
}
})
$all_exts | sort-by name
}
def create_version_link [pg_info] {
if $pg_info.is_orioledb {
let display = $"orioledb-($pg_info.name)"
let url = "https://github.com/orioledb/orioledb"
$"- ✅ Postgres [($display)]\(($url)\)"
} else {
let major_version = ($pg_info.version | split row "." | first)
let url = $"https://www.postgresql.org/docs/($major_version)/index.html"
$"- ✅ Postgres [($pg_info.name)]\(($url)\)" # Use full version number
}
}
def create_ext_table [extensions, pg_info] {
let header_version = if $pg_info.is_orioledb {
$"orioledb-($pg_info.version)" # Add orioledb prefix for orioledb versions
} else {
$pg_info.version
}
let header = [
"", # blank line for spacing
$"### PostgreSQL ($header_version) Extensions",
"| Extension | Version | Description |",
"| ------------- | :-------------: | ------------- |"
]
let rows = ($extensions | each {|ext|
let name = $ext.name
let version = $ext.version
let desc = $ext.description
let url = $ext.url # Get URL from extension info
$"| [($name)]\(($url)\) | [($version)]\(($url)\) | ($desc) |"
})
$header | append $rows
}
def update_readme [] {
let flake_json = (load_flake)
let readme_path = ([$env.PWD "README.md"] | path join)
let readme = (open $readme_path | lines)
let pg_versions = (get_postgres_versions $flake_json)
# Find section indices
let features_start = ($readme | where $it =~ "^## Primary Features" | first)
let features_end = ($readme | where $it =~ "^## Extensions" | first)
let features_start_idx = (find_index $readme $features_start)
let features_end_idx = (find_index $readme $features_end)
if $features_start_idx == -1 or $features_end_idx == -1 {
error make {msg: "Could not find Features sections"}
}
# Update Primary Features section
let features_content = [
($pg_versions | each {|version| create_version_link $version} | str join "\n")
"- ✅ Ubuntu 20.04 (Focal Fossa)."
"- ✅ [wal_level](https://www.postgresql.org/docs/current/runtime-config-wal.html) = logical and [max_replication_slots](https://www.postgresql.org/docs/current/runtime-config-replication.html) = 5. Ready for replication."
"- ✅ [Large Systems Extensions](https://github.com/aws/aws-graviton-getting-started#building-for-graviton-and-graviton2). Enabled for ARM images."
]
# Find extension section indices
let ext_start = ($readme | where $it =~ "^## Extensions" | first)
let ext_start_idx = (find_index $readme $ext_start)
# Find next section after Extensions or use end of file
let next_section_idx = ($readme
| enumerate
| where {|it| $it.index > $ext_start_idx and ($it.item =~ "^## ")}
| first
| get index
| default ($readme | length)
)
if $ext_start_idx == -1 {
error make {msg: "Could not find Extensions section"}
}
# Create extension sections content
let ext_sections_content = ($pg_versions | each {|version|
let extensions = (get_extension_info $flake_json $version)
create_ext_table $extensions $version
} | flatten)
# Combine sections, removing duplicate headers
let before_features = ($readme
| range (0)..($features_start_idx)
| where {|line| not ($line =~ "^## Primary Features")}
)
let features_header = ($readme | get $features_start_idx)
let between_sections = ($readme
| range ($features_end_idx)..($ext_start_idx)
| where {|line|
not ($line =~ "^## Primary Features" or $line =~ "^## Extensions")
}
)
let ext_header = ($readme | get $ext_start_idx)
let after_ext = ($readme | range ($next_section_idx)..($readme | length))
let output = ($before_features
| append $features_header
| append $features_content
| append $between_sections
| append $ext_header
| append $ext_sections_content
| append $after_ext
| str join "\n")
$output | save --force $readme_path
}
# Main execution
update_readme