Skip to content

Add date alongside release version #2847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: cargo sqlx migrate run --database-url $DOCSRS_DATABASE_URL

- name: run sqlx prepare --check
run: just sqlx-check
run: just sqlx-prepare

- name: test reverse migrations
run: |
Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/commit-sqlx-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
on:
pull_request_target:
branches:
- master
types: [closed]

env:
RUST_BACKTRACE: 1
RUST_CACHE_KEY: rust-cache-20241114
DOCSRS_PREFIX: ignored/cratesfyi-prefix
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@localhost:15432
DOCSRS_LOG: docs_rs=debug,rustwide=info
AWS_ACCESS_KEY_ID: cratesfyi
AWS_SECRET_ACCESS_KEY: secret_key
S3_ENDPOINT: http://localhost:9000
DOCSRS_INCLUDE_DEFAULT_TARGETS: false
DOCSRS_DOCKER_IMAGE: ghcr.io/rust-lang/crates-build-env/linux-micro
SENTRY_ENVIRONMENT: dev

permissions:
contents: write

jobs:
update-labels:
if: ${{ github.event.pull_request.merged }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: install `just`
run: sudo snap install --edge --classic just

- name: restore build & cargo cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: ${{ env.RUST_CACHE_KEY }}

- name: install SQLX CLI
run: cargo install sqlx-cli --no-default-features --features postgres

- name: run database migrations
run: cargo sqlx migrate run --database-url $DOCSRS_DATABASE_URL

- name: Commit sqlx changes on master branch if any
run: |
cp .env.sample .env
mkdir -p ${DOCSRS_PREFIX}/public-html
docker compose up -d db s3
# Give the database enough time to start up
sleep 5
# Make sure the database is actually working
psql "${DOCSRS_DATABASE_URL}"

just sqlx-prepare
# If there are differences in the SQLX files, then we push them on the master branch
if git status --porcelain .sqlx ; then
git config --global user.name 'Docs.rs developers'
git config --global user.email '[email protected]'
git add .sqlx
git commit -m 'Update SQLX files'
git push
fi

- name: Clean up the database
run: docker compose down --volumes
2 changes: 1 addition & 1 deletion .github/workflows/tag-merged-pr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on:
pull_request_target:
branches:
branches:
- master
types: [closed]

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub(crate) struct Release {
pub is_library: Option<bool>,
pub rustdoc_status: Option<bool>,
pub target_name: Option<String>,
pub release_time: Option<DateTime<Utc>>,
}

impl CrateDetails {
Expand Down Expand Up @@ -382,6 +383,7 @@ pub(crate) async fn releases_for_crate(
releases.yanked,
releases.is_library,
releases.rustdoc_status,
releases.release_time,
releases.target_name
FROM releases
INNER JOIN release_build_status ON releases.id = release_build_status.rid
Expand Down Expand Up @@ -412,6 +414,7 @@ pub(crate) async fn releases_for_crate(
is_library: row.is_library,
rustdoc_status: row.rustdoc_status,
target_name: row.target_name,
release_time: row.release_time,
}))
})
.try_collect()
Expand Down Expand Up @@ -1143,7 +1146,10 @@ mod tests {
.await?;

let mut conn = db.async_conn().await;
let details = crate_details(&mut conn, "foo", "0.2.0", None).await;
let mut details = crate_details(&mut conn, "foo", "0.2.0", None).await;
for detail in &mut details.releases {
detail.release_time = None;
}

assert_eq!(
details.releases,
Expand All @@ -1156,6 +1162,7 @@ mod tests {
rustdoc_status: Some(true),
id: details.releases[0].id,
target_name: Some("foo".to_owned()),
release_time: None,
},
Release {
version: semver::Version::parse("0.12.0")?,
Expand All @@ -1165,6 +1172,7 @@ mod tests {
rustdoc_status: Some(true),
id: details.releases[1].id,
target_name: Some("foo".to_owned()),
release_time: None,
},
Release {
version: semver::Version::parse("0.3.0")?,
Expand All @@ -1174,6 +1182,7 @@ mod tests {
rustdoc_status: Some(false),
id: details.releases[2].id,
target_name: Some("foo".to_owned()),
release_time: None,
},
Release {
version: semver::Version::parse("0.2.0")?,
Expand All @@ -1183,6 +1192,7 @@ mod tests {
rustdoc_status: Some(true),
id: details.releases[3].id,
target_name: Some("foo".to_owned()),
release_time: None,
},
Release {
version: semver::Version::parse("0.2.0-alpha")?,
Expand All @@ -1192,6 +1202,7 @@ mod tests {
rustdoc_status: Some(true),
id: details.releases[4].id,
target_name: Some("foo".to_owned()),
release_time: None,
},
Release {
version: semver::Version::parse("0.1.1")?,
Expand All @@ -1201,6 +1212,7 @@ mod tests {
rustdoc_status: Some(true),
id: details.releases[5].id,
target_name: Some("foo".to_owned()),
release_time: None,
},
Release {
version: semver::Version::parse("0.1.0")?,
Expand All @@ -1210,6 +1222,7 @@ mod tests {
rustdoc_status: Some(true),
id: details.releases[6].id,
target_name: Some("foo".to_owned()),
release_time: None,
},
Release {
version: semver::Version::parse("0.0.1")?,
Expand All @@ -1219,6 +1232,7 @@ mod tests {
rustdoc_status: Some(false),
id: details.releases[7].id,
target_name: Some("foo".to_owned()),
release_time: None,
},
]
);
Expand Down
56 changes: 55 additions & 1 deletion src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ mod test {
web::{cache::CachePolicy, encode_url_path},
};
use anyhow::Context;
use chrono::{NaiveDate, Utc};
use kuchikiki::traits::TendrilSink;
use reqwest::StatusCode;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -2381,7 +2382,7 @@ mod test {
let anchor = page
.select(&selector)
.unwrap()
.find(|a| a.text_contents().trim() == version)
.find(|a| a.text_contents().trim().split(" ").next().unwrap() == version)
.unwrap();
let attributes = anchor.as_node().as_element().unwrap().attributes.borrow();
let classes = attributes.get("class").unwrap();
Expand All @@ -2395,6 +2396,59 @@ mod test {
})
}

#[test]
fn test_crate_release_version_and_date() {
async_wrapper(|env| async move {
env.fake_release()
.await
.name("hexponent")
.version("0.3.0")
.release_time(
NaiveDate::from_ymd_opt(2021, 1, 12)
.unwrap()
.and_hms_milli_opt(0, 0, 0, 0)
.unwrap()
.and_local_timezone(Utc)
.unwrap(),
)
.create()
.await?;
env.fake_release()
.await
.name("hexponent")
.version("0.2.0")
.release_time(
NaiveDate::from_ymd_opt(2020, 12, 1)
.unwrap()
.and_hms_milli_opt(0, 0, 0, 0)
.unwrap()
.and_local_timezone(Utc)
.unwrap(),
)
.create()
.await?;
let web = env.web_app().await;

let status = |version, date| {
let web = web.clone();
async move {
let page = kuchikiki::parse_html()
.one(web.get("/crate/hexponent/0.3.0").await?.text().await?);
let selector = format!(r#"ul > li a[href="/crate/hexponent/{version}"]"#);
let full = format!("{version} ({date})");
Result::<bool, anyhow::Error>::Ok(page.select(&selector).unwrap().any(|a| {
eprintln!("++++++> {:?}", a.text_contents());
a.text_contents().trim() == full
}))
}
};

assert!(status("0.3.0", "2021/01/12").await?);
assert!(status("0.2.0", "2020/12/01").await?);
Ok(())
})
}

#[test_case(true)]
#[test_case(false)]
fn test_no_trailing_rustdoc_slash(archive_storage: bool) {
Expand Down
17 changes: 10 additions & 7 deletions templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,16 @@
{% if !title.is_empty() %} title="{{ title }}"{% endif %}
{% if retain_fragment %}data-fragment="retain"{% endif %}
>
{% if warning %}
{{ crate::icons::IconTriangleExclamation.render_solid(false, false, "") }}
{% endif %}
{% if release.build_status == "in_progress" %}
{{ crate::icons::IconGear.render_solid(true, true, "") }}
{% endif %}
{{ release.version }}
{%- if warning -%}
{{ crate::icons::IconTriangleExclamation.render_solid(false, false, "") -}}
{%+ endif -%}
{% if release.build_status == "in_progress" -%}
{{ crate::icons::IconGear.render_solid(true, true, "") -}}
{%+ endif -%}
<b>{{ release.version }}</b>
{%- if let Some(release_time) = release.release_time -%}
{# +#} ({{ release_time.format("%Y/%m/%d") }})
{%- endif -%}
</a>
</li>
{%- endfor -%}
Expand Down
2 changes: 1 addition & 1 deletion templates/rustdoc/topbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{%- if metadata.req_version.to_string() == "latest" -%}
<li class="pure-menu-item">
<a href="{% if permalink_path is defined %}{{permalink_path|safe}}{% endif %}" class="pure-menu-link description" id="permalink" title="Get a link to this specific version">
{{ crate::icons::IconLink.render_solid(false, false, "") }} Permalink
{{- crate::icons::IconLink.render_solid(false, false, "") }} Permalink
</a>
</li>
{%- endif -%}
Expand Down