Skip to content

Commit

Permalink
refactor: remove duplicate remote_versions_caches
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 26, 2024
1 parent 6882f53 commit 8ac009a
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 232 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ concurrency:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
GITHUB_API_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN || github.token }}

jobs:
docker:
Expand Down Expand Up @@ -85,8 +86,6 @@ jobs:
container:
image: ghcr.io/jdx/mise:dev
needs: [dev]
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- run: cargo install --path . --debug
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hyperfine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:

env:
CARGO_TERM_COLOR: always
GITHUB_TOKEN: ${{ secrets.RTX_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
MISE_EXPERIMENTAL: 1
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: clang
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS: -C link-arg=-fuse-ld=mold
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-plz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env:
NPM_CONFIG_FUND: false
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}

jobs:
release-plz:
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ env:
CARGO_TERM_COLOR: always
DRY_RUN: ${{ startsWith(github.event.ref, 'refs/tags/v') && '0' || '1' }}
RUST_BACKTRACE: 1
GITHUB_API_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}

jobs:
build-tarball:
Expand Down Expand Up @@ -96,7 +99,6 @@ jobs:
- uses: taiki-e/install-action@v2
with: { tool: cargo-cache }
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- if: steps.cache-crates.outputs.cache-hit != 'true'
run: cargo cache --autoclean
build-tarball-windows:
Expand Down Expand Up @@ -158,7 +160,6 @@ jobs:
- name: Run e2e tests
uses: nick-fields/retry@v3
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TEST_TRANCHE: ${{matrix.tranche}}
TEST_TRANCHE_COUNT: 8
TEST_ALL: 1
Expand Down Expand Up @@ -272,7 +273,6 @@ jobs:
CLOUDFLARE_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_ACCESS_KEY_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
CLOUDFLARE_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_SECRET_ACCESS_KEY }}
GITHUB_TOKEN: ${{ secrets.RTX_GITHUB_BOT_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: GitHub Release Assets
uses: softprops/action-gh-release@v2
Expand Down Expand Up @@ -339,4 +339,3 @@ jobs:
ALPINE_KEY_ID: ${{ secrets.ALPINE_KEY_ID }}
ALPINE_PRIV_KEY: ${{ secrets.ALPINE_PRIV_KEY }}
ALPINE_PUB_KEY: ${{ secrets.ALPINE_PUB_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 3 additions & 2 deletions .github/workflows/semantic-pr-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ on:
permissions:
pull-requests: read

env:
GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 1 addition & 4 deletions .github/workflows/test-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:

env:
CARGO_TERM_COLOR: always
GITHUB_API_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}

jobs:
build-linux:
Expand All @@ -43,8 +44,6 @@ jobs:
test-install-and-run:
runs-on: ubuntu-latest
needs: [build-linux]
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -121,8 +120,6 @@ jobs:
# and behaves as expected with mise.
runs-on: ubuntu-latest
needs: [build-linux]
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
fail-fast: false
matrix:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
MISE_EXPERIMENTAL: 1
MISE_LOCKFILE: 1
RUST_BACKTRACE: 1
GITHUB_TOKEN: ${{ secrets.RTX_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: clang
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS: -C link-arg=-fuse-ld=mold

Expand Down Expand Up @@ -105,7 +105,6 @@ jobs:
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
token: ${{ secrets.RTX_GITHUB_BOT_TOKEN || github.token }}
submodules: true
- uses: rui314/setup-mold@v1
if: ${{ matrix.os == 'ubuntu-latest' }}
Expand Down Expand Up @@ -152,7 +151,6 @@ jobs:
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
token: ${{ secrets.RTX_GITHUB_BOT_TOKEN || github.token }}
- run: rustup default nightly
- uses: Swatinem/rust-cache@v2
with:
Expand Down
89 changes: 38 additions & 51 deletions src/backend/aqua.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::aqua::aqua_registry::{AquaChecksumType, AquaPackage, AquaPackageType, AQUA_REGISTRY};
use crate::backend::backend_type::BackendType;
use crate::backend::Backend;
use crate::cache::{CacheManager, CacheManagerBuilder};
use crate::cli::args::BackendArg;
use crate::cli::version::{ARCH, OS};
use crate::cmd::CmdLineRunner;
Expand All @@ -12,7 +11,7 @@ use crate::install_context::InstallContext;
use crate::plugins::VERSION_REGEX;
use crate::registry::REGISTRY;
use crate::toolset::ToolVersion;
use crate::{dirs, file, github};
use crate::{file, github};
use eyre::{bail, ContextCompat, Result};
use indexmap::IndexSet;
use itertools::Itertools;
Expand All @@ -25,7 +24,6 @@ use std::path::{Path, PathBuf};
pub struct AquaBackend {
ba: BackendArg,
id: String,
remote_version_cache: CacheManager<Vec<String>>,
}

impl Backend for AquaBackend {
Expand All @@ -42,47 +40,43 @@ impl Backend for AquaBackend {
}

fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| {
let pkg = AQUA_REGISTRY.package(&self.id)?;
if !pkg.repo_owner.is_empty() && !pkg.repo_name.is_empty() {
let versions = if let Some("github_tag") = pkg.version_source.as_deref() {
github::list_tags(&format!("{}/{}", pkg.repo_owner, pkg.repo_name))?
} else {
github::list_releases(&format!("{}/{}", pkg.repo_owner, pkg.repo_name))?
.into_iter()
.map(|r| r.tag_name)
.collect_vec()
};
Ok(versions
.into_iter()
.filter_map(|v| {
let mut v = v.as_str();
match pkg.version_filter_ok(v) {
Ok(true) => {}
Ok(false) => return None,
Err(e) => {
warn!("[{}] aqua version filter error: {e}", self.ba);
}
}
if let Some(prefix) = &pkg.version_prefix {
if let Some(_v) = v.strip_prefix(prefix) {
v = _v
} else {
return None;
}
}
v = v.strip_prefix('v').unwrap_or(v);
Some(v.to_string())
})
.rev()
.collect())
} else {
warn!("no aqua registry found for {}", self.ba);
Ok(vec![])
}
})
.cloned()
let pkg = AQUA_REGISTRY.package(&self.id)?;
if !pkg.repo_owner.is_empty() && !pkg.repo_name.is_empty() {
let versions = if let Some("github_tag") = pkg.version_source.as_deref() {
github::list_tags(&format!("{}/{}", pkg.repo_owner, pkg.repo_name))?
} else {
github::list_releases(&format!("{}/{}", pkg.repo_owner, pkg.repo_name))?
.into_iter()
.map(|r| r.tag_name)
.collect_vec()
};
Ok(versions
.into_iter()
.filter_map(|v| {
let mut v = v.as_str();
match pkg.version_filter_ok(v) {
Ok(true) => {}
Ok(false) => return None,
Err(e) => {
warn!("[{}] aqua version filter error: {e}", self.ba);
}
}
if let Some(prefix) = &pkg.version_prefix {
if let Some(_v) = v.strip_prefix(prefix) {
v = _v
} else {
return None;
}
}
v = v.strip_prefix('v').unwrap_or(v);
Some(v.to_string())
})
.rev()
.collect())
} else {
warn!("no aqua registry found for {}", self.ba);
Ok(vec![])
}
}

fn install_version_impl(
Expand Down Expand Up @@ -168,13 +162,6 @@ impl AquaBackend {
});
}
Self {
remote_version_cache: CacheManagerBuilder::new(
ba.cache_path.join("remote_versions.msgpack.z"),
)
.with_fresh_duration(SETTINGS.fetch_remote_versions_cache())
.with_fresh_file(dirs::DATA.to_path_buf())
.with_fresh_file(ba.installs_path.to_path_buf())
.build(),
id: id.to_string(),
ba,
}
Expand Down
18 changes: 1 addition & 17 deletions src/backend/asdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub struct AsdfBackend {
pub toml: MisePluginToml,
plugin: Box<AsdfPlugin>,
cache: ExternalPluginCache,
remote_version_cache: CacheManager<Vec<String>>,
latest_stable_cache: CacheManager<Option<String>>,
alias_cache: CacheManager<Vec<(String, String)>>,
legacy_filename_cache: CacheManager<Vec<String>>,
Expand All @@ -51,13 +50,6 @@ impl AsdfBackend {
let toml = MisePluginToml::from_file(&toml_path).unwrap();
Self {
cache: ExternalPluginCache::default(),
remote_version_cache: CacheManagerBuilder::new(
ba.cache_path.join("remote_versions.msgpack.z"),
)
.with_fresh_duration(SETTINGS.fetch_remote_versions_cache())
.with_fresh_file(plugin_path.clone())
.with_fresh_file(plugin_path.join("bin/list-all"))
.build(),
latest_stable_cache: CacheManagerBuilder::new(
ba.cache_path.join("latest_stable.msgpack.z"),
)
Expand Down Expand Up @@ -240,15 +232,7 @@ impl Backend for AsdfBackend {
}

fn _list_remote_versions(&self) -> Result<Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| self.plugin.fetch_remote_versions())
.wrap_err_with(|| {
eyre!(
"Failed listing remote versions for asdf tool {}",
style(&self.name).blue().for_stderr(),
)
})
.cloned()
self.plugin.fetch_remote_versions()
}

fn latest_stable_version(&self) -> Result<Option<String>> {
Expand Down
35 changes: 11 additions & 24 deletions src/backend/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use url::Url;

use crate::backend::backend_type::BackendType;
use crate::backend::Backend;
use crate::cache::{CacheManager, CacheManagerBuilder};
use crate::cli::args::BackendArg;
use crate::cmd::CmdLineRunner;
use crate::config::{Config, SETTINGS};
Expand All @@ -20,7 +19,6 @@ use crate::{env, file};
#[derive(Debug)]
pub struct CargoBackend {
ba: BackendArg,
remote_version_cache: CacheManager<Vec<String>>,
}

impl Backend for CargoBackend {
Expand All @@ -45,20 +43,16 @@ impl Backend for CargoBackend {
// TODO: maybe fetch tags/branches from git?
return Ok(vec!["HEAD".into()]);
}
self.remote_version_cache
.get_or_try_init(|| {
let raw = HTTP_FETCH.get_text(get_crate_url(&self.tool_name())?)?;
let stream = Deserializer::from_str(&raw).into_iter::<CrateVersion>();
let mut versions = vec![];
for v in stream {
let v = v?;
if !v.yanked {
versions.push(v.vers);
}
}
Ok(versions)
})
.cloned()
let raw = HTTP_FETCH.get_text(get_crate_url(&self.tool_name())?)?;
let stream = Deserializer::from_str(&raw).into_iter::<CrateVersion>();
let mut versions = vec![];
for v in stream {
let v = v?;
if !v.yanked {
versions.push(v.vers);
}
}
Ok(versions)
}

fn install_version_impl(
Expand Down Expand Up @@ -134,14 +128,7 @@ impl Backend for CargoBackend {

impl CargoBackend {
pub fn from_arg(ba: BackendArg) -> Self {
Self {
remote_version_cache: CacheManagerBuilder::new(
ba.cache_path.join("remote_versions.msgpack.z"),
)
.with_fresh_duration(SETTINGS.fetch_remote_versions_cache())
.build(),
ba,
}
Self { ba }
}

fn is_binstall_enabled(&self, tv: &ToolVersion) -> bool {
Expand Down
Loading

0 comments on commit 8ac009a

Please sign in to comment.