Skip to content

Commit 87ede3b

Browse files
authored
Support GitHub Pre-releases (#20)
* Implemented support for prerelease github releases * Fixed multi-arch debian repo index * Add user-agent header for packhub
1 parent 522c5a6 commit 87ede3b

39 files changed

Lines changed: 1019 additions & 153 deletions

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ edition = "2024"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
axum = { version = "0.8", features = ["macros"] }
9+
axum = { version = "0.8", features = ["macros", "query"] }
1010
axum-extra = { version = "0.10", features = ["typed-header"] }
1111
axum-server = { version = "0.7", features = ["tls-rustls"] }
1212
askama = "0.13"
1313
chrono = { version = "0.4.38", features = ["clock"] }
1414
dotenvy = "0.15"
15-
octocrab = "0.44"
15+
octocrab = { version = "0.46", features = ["stream"] }
1616
regex = "1"
1717
semver = "1"
1818
lenient_semver = "0.4"
@@ -36,8 +36,10 @@ bson = { version = "2", features = ["chrono-0_4"] }
3636
serde = { version = "1", features = ["derive"] }
3737
serde_json = "1"
3838
sequoia-openpgp = "2.0.0"
39+
futures-util = "0.3"
3940

4041
[dev-dependencies]
42+
axum-test = "18"
4143
insta = { version = "1", features = ["filters"] }
4244
testcontainers-modules = { version = "0.11", features = ["mongo"] }
4345

infratest/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7-
bollard = "0.19"
87
tokio = { version = "1.0", features = ["full"] }
9-
futures-util = "0.3"
108
anyhow = "1.0"
119
reqwest = { version = "0.12", features = ["stream", "rustls-tls"] }
12-
tar = "0.4"
1310
testcontainers-modules = { version = "0.13", features = ["mongo"] }
14-
pretty_env_logger = "0.4"
15-
testcontainers = { git = "https://github.com/mominul/testcontainers-rs.git", branch = "platform_config", features = ["http_wait"] }
1611

1712
[patch.crates-io]
1813
testcontainers = { git = "https://github.com/mominul/testcontainers-rs.git", branch = "platform_config" }

infratest/scripts/check_apt_pre.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
apt update
4+
apt install sudo wget -y
5+
6+
echo
7+
echo "Running the package key and repository setup script"
8+
9+
wget -qO- http://localhost:3000/sh/ubuntu/github/mominul/pack-exp-pre?prerelease=true | sh
10+
return_value=$?
11+
12+
if [ $return_value -ne 0 ]; then
13+
echo "The script failed with exit code $return_value"
14+
# Handle error case here
15+
exit $return_value
16+
else
17+
echo "Package key and repository setup script ran successfully."
18+
fi
19+
20+
output=$(apt search openbangla 2>&1)
21+
status=$?
22+
23+
# Print the output of the apt command
24+
echo "$output"
25+
26+
# Check if the apt command was successful
27+
if [ $status -ne 0 ]; then
28+
echo "Error: apt search command failed." >&2
29+
exit $status
30+
fi
31+
32+
if echo "$output" | grep -q "openbangla-keyboard"; then
33+
echo
34+
echo "Package found successfully."
35+
else
36+
echo "Error: package not found." >&2
37+
exit 1
38+
fi
39+
40+
# check if apt can install the package
41+
apt_out=$(apt install openbangla-keyboard -y 2>&1)
42+
apt_status=$?
43+
44+
# Print the output of the apt command
45+
echo "$apt_out"
46+
47+
# Check if the apt command was successful
48+
if [ $apt_status -ne 0 ]; then
49+
echo "Error: apt install command failed." >&2
50+
exit $apt_status
51+
fi
52+
53+
echo "Package installed successfully."
54+
exit 0

infratest/scripts/check_dnf_pre.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
yes | dnf install wget sudo
4+
5+
echo
6+
echo "Running the package key and repository setup script"
7+
8+
wget -qO- http://localhost:3000/sh/yum/github/mominul/pack-exp-pre?prerelease=true | sh
9+
return_value=$?
10+
11+
if [ $return_value -ne 0 ]; then
12+
echo "The script failed with exit code $return_value"
13+
# Handle error case here
14+
exit $return_value
15+
else
16+
echo "Package key and repository setup script ran successfully."
17+
fi
18+
19+
output=$(yes | dnf search openbangla 2>&1)
20+
status=$?
21+
22+
# Print the output of the dnf command
23+
echo "$output"
24+
25+
# Check if the dnf command was successful
26+
if [ $status -ne 0 ]; then
27+
echo "Error: dnf search command failed." >&2
28+
exit $status
29+
fi
30+
31+
if echo "$output" | grep -q "openbangla-keyboard"; then
32+
echo
33+
echo "Package found successfully."
34+
else
35+
echo "Error: package not found." >&2
36+
exit 1
37+
fi
38+
39+
# check if dnf can install the package
40+
dnf_out=$(yes | dnf install openbangla-keyboard 2>&1)
41+
dnf_status=$?
42+
43+
# Print the output of the dnf command
44+
echo "$dnf_out"
45+
46+
# Check if the dnf command was successful
47+
if [ $dnf_status -ne 0 ]; then
48+
echo "Error: dnf install command failed." >&2
49+
exit $dnf_status
50+
fi
51+
52+
echo "Package installed successfully."
53+
exit 0

infratest/scripts/check_dnf_v1.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
yes | dnf install wget sudo
4+
5+
echo
6+
echo "Running the package key and repository setup script"
7+
8+
wget -qO- http://localhost:3000/sh/yum/github/mominul/pack-exp3?ver=v1 | sh
9+
return_value=$?
10+
11+
if [ $return_value -ne 0 ]; then
12+
echo "The script failed with exit code $return_value"
13+
# Handle error case here
14+
exit $return_value
15+
else
16+
echo "Package key and repository setup script ran successfully."
17+
fi
18+
19+
output=$(yes | dnf search openbangla 2>&1)
20+
status=$?
21+
22+
# Print the output of the dnf command
23+
echo "$output"
24+
25+
# Check if the dnf command was successful
26+
if [ $status -ne 0 ]; then
27+
echo "Error: dnf search command failed." >&2
28+
exit $status
29+
fi
30+
31+
if echo "$output" | grep -q "openbangla-keyboard"; then
32+
echo
33+
echo "Package found successfully."
34+
else
35+
echo "Error: package not found." >&2
36+
exit 1
37+
fi
38+
39+
# check if dnf can install the package
40+
dnf_out=$(yes | dnf install openbangla-keyboard 2>&1)
41+
dnf_status=$?
42+
43+
# Print the output of the dnf command
44+
echo "$dnf_out"
45+
46+
# Check if the dnf command was successful
47+
if [ $dnf_status -ne 0 ]; then
48+
echo "Error: dnf install command failed." >&2
49+
exit $dnf_status
50+
fi
51+
52+
echo "Package installed successfully."
53+
exit 0

infratest/src/infra.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use anyhow::{Result, bail};
2-
use testcontainers::{ContainerAsync, GenericImage};
3-
use testcontainers_modules::mongo::Mongo;
2+
use testcontainers_modules::{
3+
mongo::Mongo,
4+
testcontainers::{ContainerAsync, GenericImage},
5+
};
46
use tokio::task::{JoinHandle, JoinSet};
57

68
use crate::{

infratest/src/main.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@ async fn main() -> Result<()> {
6666
None,
6767
));
6868

69+
// Pre-release support tests
70+
infra.add_distro(Distro::new(
71+
"pre-release-pkg",
72+
"ubuntu",
73+
"25.04",
74+
"check_apt_pre.sh",
75+
None,
76+
));
77+
78+
infra.add_distro(Distro::new(
79+
"pre-release-pkg",
80+
"fedora",
81+
"42",
82+
"check_dnf_pre.sh",
83+
None,
84+
));
85+
86+
// Test rpm v1 support
87+
infra.add_distro(Distro::new(
88+
"v1-rpm",
89+
"fedora",
90+
"42",
91+
"check_dnf_v1.sh",
92+
None,
93+
));
94+
6995
infra.run_distros().await?;
7096

7197
Ok(())

src/apt/index.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashMap, io::Write};
1+
use std::{collections::BTreeMap, io::Write};
22

33
use anyhow::Result;
44
use askama::Template;
@@ -11,20 +11,20 @@ use sha2::{Sha256, Sha512};
1111
use crate::{
1212
apt::deb::DebianPackage,
1313
package::Package,
14-
utils::{Arch, hashsum},
14+
utils::{Arch, ReleaseChannel, hashsum},
1515
};
1616

1717
#[derive(Debug)]
1818
pub struct AptIndices {
19-
packages: HashMap<Arch, Vec<DebianPackage>>,
19+
packages: BTreeMap<Arch, Vec<DebianPackage>>,
2020
date: DateTime<Utc>,
2121
}
2222

2323
#[derive(Template)]
2424
#[template(path = "Release")]
2525
struct ReleaseIndex<'a> {
26-
origin: &'a str,
27-
label: &'a str,
26+
channel: &'a ReleaseChannel,
27+
arch: Vec<String>,
2828
date: String,
2929
files: Vec<Files>,
3030
}
@@ -46,7 +46,7 @@ struct Files {
4646

4747
impl AptIndices {
4848
pub fn new(packages: &[Package]) -> Result<AptIndices> {
49-
let mut debian: HashMap<Arch, Vec<DebianPackage>> = HashMap::new();
49+
let mut debian: BTreeMap<Arch, Vec<DebianPackage>> = BTreeMap::new();
5050
// Find the latest date from the list of packages
5151
let mut date = DateTime::UNIX_EPOCH;
5252
for package in packages {
@@ -85,8 +85,7 @@ impl AptIndices {
8585
index.render().unwrap().trim().to_owned()
8686
}
8787

88-
pub fn get_release_index(&self) -> String {
89-
let name = ". stable";
88+
pub fn get_release_index(&self, channel: &ReleaseChannel) -> String {
9089
let date = self.date.to_rfc2822();
9190

9291
let mut files = vec![];
@@ -122,8 +121,8 @@ impl AptIndices {
122121
let index = ReleaseIndex {
123122
date,
124123
files,
125-
origin: name,
126-
label: name,
124+
channel,
125+
arch: self.packages.keys().map(|s| s.to_string()).collect(),
127126
};
128127

129128
index.render().unwrap()
@@ -166,7 +165,7 @@ mod tests {
166165
assert_snapshot!(packages);
167166

168167
// Release
169-
let release = indices.get_release_index();
168+
let release = indices.get_release_index(&ReleaseChannel::Stable);
170169
assert_snapshot!(release);
171170
}
172171

@@ -192,7 +191,7 @@ mod tests {
192191
assert_eq!(packages_gz.len(), 1105);
193192

194193
// Release
195-
let release = indices.get_release_index();
194+
let release = indices.get_release_index(&ReleaseChannel::Stable);
196195
assert_snapshot!(release);
197196
}
198197

@@ -233,7 +232,7 @@ mod tests {
233232
let indices = AptIndices::new(&packages).unwrap();
234233

235234
// Release
236-
let release = indices.get_release_index();
235+
let release = indices.get_release_index(&ReleaseChannel::Stable);
237236
assert_snapshot!(release);
238237
}
239238
}

0 commit comments

Comments
 (0)