From 29d301d6a79fa616dda5e0b1214efefc9f54e5fb Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Thu, 14 Dec 2023 04:34:35 -0600 Subject: [PATCH] CI: consolidate GH action cache (#1181) * CI: consolidate GH action cache * CI: consolidate GH action cache * Commit from GitHub Actions (test) * CI: test run formatting * e2e * ci * ci * poetry * e2e * poetry * e2e * poetry * e2e * make more e2e tests slow --------- Co-authored-by: rtx[bot] <123107610+rtx-vm@users.noreply.github.com> --- .github/workflows/{rtx.yml => test.yml} | 13 ++++++------- e2e/cd/test_bash | 15 +++++++++++---- e2e/config/.e2e.rtx.toml | 4 +--- e2e/run_all_tests | 6 ++++++ e2e/run_test | 16 ++++++++++++++-- e2e/test_bun | 4 ++-- e2e/test_local | 16 ++++------------ e2e/test_nodejs | 19 ++++--------------- e2e/test_plugins_install | 1 + e2e/test_poetry | 9 +++++++++ e2e/test_python | 4 ++++ justfile | 15 ++++++++++++--- scripts/release.sh | 9 ++++++++- src/cli/install.rs | 6 +----- src/shims.rs | 11 +++-------- src/toolset/mod.rs | 23 ++++++++--------------- 16 files changed, 94 insertions(+), 77 deletions(-) rename .github/workflows/{rtx.yml => test.yml} (93%) diff --git a/.github/workflows/rtx.yml b/.github/workflows/test.yml similarity index 93% rename from .github/workflows/rtx.yml rename to .github/workflows/test.yml index ad0858f94..f8d3c434f 100644 --- a/.github/workflows/rtx.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,4 @@ -name: rtx - +name: test on: push: tags: ["v*"] @@ -29,8 +28,9 @@ jobs: ref: ${{ github.event.pull_request.head.ref }} - uses: Swatinem/rust-cache@v2 with: - shared-key: unit - save-if: ${{ github.event_name == 'push' && github.ref_name == 'main' }} + shared-key: test + save-if: ${{ github.ref_name == 'main' }} + cache-all-crates: true - uses: taiki-e/install-action@v2 with: tool: nextest,just,cargo-deny,cargo-msrv,cargo-machete @@ -70,9 +70,8 @@ jobs: #- run: rustup toolchain install nightly --component llvm-tools-preview --profile minimal - uses: Swatinem/rust-cache@v2 with: - shared-key: coverage - save-if: ${{ github.event_name == 'push' && github.ref_name == 'main' }} - cache-all-crates: true + shared-key: test + save-if: false - run: sudo apt-get update; sudo apt-get install zsh fish direnv shfmt - run: npm i -g markdown-magic - uses: taiki-e/install-action@v2 diff --git a/e2e/cd/test_bash b/e2e/cd/test_bash index 836a4e6f0..af7d4aabf 100755 --- a/e2e/cd/test_bash +++ b/e2e/cd/test_bash @@ -31,24 +31,31 @@ assert_path() { fi } +NODE_18="INSTALLS/node/18.0.0/bin" +NODE_20="INSTALLS/node/20.0.0/bin" +TINY="INSTALLS/tiny/3.1.0/bin" +SHELLCHECK="INSTALLS/shellcheck/0.9.0/bin" +SHFMT="INSTALLS/shfmt/3.6.0/bin" + +rtx ls rtx i && _rtx_hook test "$(node -v)" = "v20.0.0" -assert_path "/root:ROOT/e2e/cwd:INSTALLS/node/20.0.0/bin:INSTALLS/python/3.12.0/bin:INSTALLS/tiny/3.1.0/bin:INSTALLS/poetry/1.7.1/bin:INSTALLS/shellcheck/0.9.0/bin:INSTALLS/shfmt/3.6.0/bin" +assert_path "/root:ROOT/e2e/cwd:$NODE_20:$TINY:$SHELLCHECK:$SHFMT" assert "$FOO" "cd" cd 18 && rtx i && _rtx_hook test "$(node -v)" = "v18.0.0" -assert_path "/root:ROOT/e2e/cwd:INSTALLS/node/18.0.0/bin:INSTALLS/python/3.12.0/bin:INSTALLS/tiny/3.1.0/bin:INSTALLS/poetry/1.7.1/bin:INSTALLS/shellcheck/0.9.0/bin:INSTALLS/shfmt/3.6.0/bin" +assert_path "/root:ROOT/e2e/cwd:$NODE_18:$TINY:$SHELLCHECK:$SHFMT" assert "$FOO" "18" cd .. && _rtx_hook test "$(node -v)" = "v20.0.0" -assert_path "/root:ROOT/e2e/cwd:INSTALLS/node/20.0.0/bin:INSTALLS/python/3.12.0/bin:INSTALLS/tiny/3.1.0/bin:INSTALLS/poetry/1.7.1/bin:INSTALLS/shellcheck/0.9.0/bin:INSTALLS/shfmt/3.6.0/bin" +assert_path "/root:ROOT/e2e/cwd:$NODE_20:$TINY:$SHELLCHECK:$SHFMT" export PATH="PRE:$PATH" cd 18 && _rtx_hook test "$(node -v)" = "v18.0.0" -assert_path "PRE:/root:ROOT/e2e/cwd:INSTALLS/node/18.0.0/bin:INSTALLS/python/3.12.0/bin:INSTALLS/tiny/3.1.0/bin:INSTALLS/poetry/1.7.1/bin:INSTALLS/shellcheck/0.9.0/bin:INSTALLS/shfmt/3.6.0/bin" +assert_path "PRE:/root:ROOT/e2e/cwd:$NODE_18:$TINY:$SHELLCHECK:$SHFMT" rtx shell node@18.0.0 && _rtx_hook test "$(node -v)" = "v18.0.0" diff --git a/e2e/config/.e2e.rtx.toml b/e2e/config/.e2e.rtx.toml index 84239c98b..6a2d5fe45 100644 --- a/e2e/config/.e2e.rtx.toml +++ b/e2e/config/.e2e.rtx.toml @@ -5,10 +5,8 @@ env_path = ["/root", "./cwd"] FOO = "bar" [tools] -python = "3.12.0" tiny = "latest" -poetry = {version="1.7.1", pyproject="pyproject.toml"} #golang = {version="1.19.5", foo="bar"} [plugins] -tiny-ref = "https://github.com/rtx-plugins/rtx-tiny#df03b6719dd465d565bb66273942c8495673eaa4" +tiny-ref = "https://github.com/rtx-plugins/rtx-tiny#c532b140abd4ca00d3e76651b9bd32a980bd483c" diff --git a/e2e/run_all_tests b/e2e/run_all_tests index f4f967168..9bcd26c90 100755 --- a/e2e/run_all_tests +++ b/e2e/run_all_tests @@ -5,6 +5,12 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" FILES=$(find e2e -name 'test_*' -type f -not -path "*/.rtx/*" | sort) test_count=0 +if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then + { + echo "| Test | Duration | Result |" + echo "| ---- | -------- | ------ |" + } >>"$GITHUB_STEP_SUMMARY" +fi for f in $FILES; do # split tests into two tranches to reduce test time if [ -n "${TEST_TRANCHE_COUNT:-}" ]; then diff --git a/e2e/run_test b/e2e/run_test index c1e46487a..9a930311d 100755 --- a/e2e/run_test +++ b/e2e/run_test @@ -15,6 +15,7 @@ setup_env() { export RTX_DEFAULT_TOOL_VERSIONS_FILENAME=.e2e-tool-versions export RTX_DEFAULT_CONFIG_FILENAME=.e2e.rtx.toml export RTX_CONFIG_FILE="$ROOT/e2e/.config/rtx/config.toml" + export RTX_ALWAYS_KEEP_DOWNLOAD="1" export RTX_TRUSTED_CONFIG_PATHS="$ROOT/e2e" export RTX_YES="1" export NPM_CONFIG_FUND="false" @@ -30,15 +31,26 @@ setup_config_files() { } run_test() { - echo "Running $TEST" + echo "::group::E2E $TEST" rm -f "$RTX_CONFIG_FILE" cd "$(dirname "$TEST")" START=$(date +%s) - "./$(basename "$TEST")" + local status=0 + "./$(basename "$TEST")" || status=$? END=$(date +%s) + if [[ "$status" == 0 ]]; then + STATUS_MSG=":white_check_mark:" + else + echo "::error file=$TEST::E2E Test Failed (code: $status)" + STATUS_MSG=":x:" + fi echo "$TEST: $((END - START))s" + if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then + echo "| $TEST | $((END - START))s | $STATUS_MSG" >>"$GITHUB_STEP_SUMMARY" + fi + return "$status" } setup_env diff --git a/e2e/test_bun b/e2e/test_bun index 383c3501e..a4241e98b 100755 --- a/e2e/test_bun +++ b/e2e/test_bun @@ -6,8 +6,8 @@ source "$(dirname "$0")/assert.sh" export RTX_EXPERIMENTAL=1 cat <.bun-version -0.7.0 +1.0.17 EOF rtx i bun -assert_contains "rtx x bun -- bun -v" "0.7.0" +assert_contains "rtx x bun -- bun -v" "1.0.17" rm .bun-version diff --git a/e2e/test_local b/e2e/test_local index d0e720cfa..b32dbf51e 100755 --- a/e2e/test_local +++ b/e2e/test_local @@ -25,13 +25,11 @@ env_path = [\"/root\", \"./cwd\"] FOO = \"bar\" [tools] -python = \"3.12.0\" tiny = \"latest\" -poetry = {version=\"1.7.1\", pyproject=\"pyproject.toml\"} #golang = {version=\"1.19.5\", foo=\"bar\"} [plugins] -tiny-ref = \"https://github.com/rtx-plugins/rtx-tiny#df03b6719dd465d565bb66273942c8495673eaa4\" +tiny-ref = \"https://github.com/rtx-plugins/rtx-tiny#c532b140abd4ca00d3e76651b9bd32a980bd483c\" " rtx local shfmt@3.5.0 @@ -42,14 +40,12 @@ env_path = [\"/root\", \"./cwd\"] FOO = \"bar\" [tools] -python = \"3.12.0\" tiny = \"latest\" -poetry = {version=\"1.7.1\", pyproject=\"pyproject.toml\"} shfmt = \"3.5.0\" #golang = {version=\"1.19.5\", foo=\"bar\"} [plugins] -tiny-ref = \"https://github.com/rtx-plugins/rtx-tiny#df03b6719dd465d565bb66273942c8495673eaa4\" +tiny-ref = \"https://github.com/rtx-plugins/rtx-tiny#c532b140abd4ca00d3e76651b9bd32a980bd483c\" " rtx exec -- shfmt --version >&2 @@ -65,14 +61,12 @@ env_path = [\"/root\", \"./cwd\"] FOO = \"bar\" [tools] -python = \"3.12.0\" tiny = \"latest\" -poetry = {version=\"1.7.1\", pyproject=\"pyproject.toml\"} shfmt = \"3.6.0\" #golang = {version=\"1.19.5\", foo=\"bar\"} [plugins] -tiny-ref = \"https://github.com/rtx-plugins/rtx-tiny#df03b6719dd465d565bb66273942c8495673eaa4\" +tiny-ref = \"https://github.com/rtx-plugins/rtx-tiny#c532b140abd4ca00d3e76651b9bd32a980bd483c\" " rtx exec -- shfmt --version >&2 @@ -88,13 +82,11 @@ env_path = [\"/root\", \"./cwd\"] FOO = \"bar\" [tools] -python = \"3.12.0\" tiny = \"latest\" -poetry = {version=\"1.7.1\", pyproject=\"pyproject.toml\"} #golang = {version=\"1.19.5\", foo=\"bar\"} [plugins] -tiny-ref = \"https://github.com/rtx-plugins/rtx-tiny#df03b6719dd465d565bb66273942c8495673eaa4\" +tiny-ref = \"https://github.com/rtx-plugins/rtx-tiny#c532b140abd4ca00d3e76651b9bd32a980bd483c\" " export RTX_DEFAULT_CONFIG_FILENAME=.MISSING diff --git a/e2e/test_nodejs b/e2e/test_nodejs index e861976aa..e19e06d4f 100755 --- a/e2e/test_nodejs +++ b/e2e/test_nodejs @@ -4,20 +4,21 @@ set -euo pipefail source "$(dirname "$0")/assert.sh" export RTX_EXPERIMENTAL=1 -export RTX_NODE_BUILD=1 +export RTX_NODE_COREPACK=1 export RTX_NODE_DEFAULT_PACKAGES_FILE="$ROOT/e2e/.default-npm-packages" rtx plugin uninstall node rtx i node node@lts/hydrogen assert_contains "rtx x node@lts/hydrogen -- node --version" "v18." assert "rtx x -- node --version" "v20.0.0" -assert_contains "rtx node node-build --version" "node-build " +assert_contains "rtx x -- which yarn" "yarn" # test asdf-nodejs rtx plugin i nodejs https://github.com/asdf-vm/asdf-nodejs.git rtx use nodejs@20.1.0 rtx ls assert "rtx x -- node --version" "v20.1.0" +assert_contains "rtx ls-remote nodejs" "20.1.0" assert_contains "rtx node nodebuild --version" "node-build " rtx use --rm node @@ -25,19 +26,7 @@ rtx use --rm node RTX_LEGACY_VERSION_FILE=1 assert_contains "rtx current node" "20.0.0" RTX_LEGACY_VERSION_FILE=0 assert_not_contains "rtx current node" "20.0.0" rtx plugin uninstall nodejs +assert_not_contains "rtx plugins --user" "node" # disable nodejs plugin RTX_DISABLE_TOOLS=node assert_not_contains "rtx plugins --core" "node" - -export RTX_NODE_BUILD=0 -rtx uninstall -a node -rtx i node -assert "rtx x -- node --version" "v20.0.0" -# rtx uninstall node -# RTX_NODE_COMPILE=1 rtx i node -# assert "rtx x -- node --version" "v20.0.0" - -export RTX_NODE_COREPACK=1 -rtx uninstall node -rtx i node -assert_contains "rtx x node -- which yarn" "yarn" diff --git a/e2e/test_plugins_install b/e2e/test_plugins_install index 8e112d79f..c18662080 100755 --- a/e2e/test_plugins_install +++ b/e2e/test_plugins_install @@ -47,3 +47,4 @@ rtx plugin uninstall tiny rtx plugin update rtx plugin update shfmt +rtx i diff --git a/e2e/test_poetry b/e2e/test_poetry index c669db4d2..bd9620041 100755 --- a/e2e/test_poetry +++ b/e2e/test_poetry @@ -3,11 +3,20 @@ set -euo pipefail # shellcheck source-path=SCRIPTDIR source "$(dirname "$0")/assert.sh" +if [ "${TEST_ALL:-}" != 1 ]; then + exit +fi + rm -rf "$RTX_DATA_DIR/cache/poetry" export POETRY_HOME=".poetry" eval "$(rtx activate bash)" +cat >.e2e.rtx.toml <VERSION cp rtx-latest-linux-x64 rtx-latest-linux-amd64 @@ -54,18 +57,22 @@ gpg --clearsign -u 408B88DB29DDE9E0 SHASUMS256.asc gpg --clearsign -u 408B88DB29DDE9E0 SHASUMS512.asc popd +echo "::group::install.sh" ./rtx/scripts/render-install.sh >"$RELEASE_DIR"/install.sh chmod +x "$RELEASE_DIR"/install.sh shellcheck "$RELEASE_DIR"/install.sh gpg -u 408B88DB29DDE9E0 --output "$RELEASE_DIR"/install.sh.sig --sign "$RELEASE_DIR"/install.sh if [[ "$DRY_RUN" != 1 ]]; then + echo "::group::Publish npm @jdxcode/rtx" NPM_PREFIX=@jdxcode/rtx ./rtx/scripts/release-npm.sh + echo "::group::Publish npm rtx-cli" NPM_PREFIX=rtx-cli ./rtx/scripts/release-npm.sh - #AWS_S3_BUCKET=rtx.jdx.dev ./rtx/scripts/publish-s3.sh + echo "::group::Publish r2" ./rtx/scripts/publish-r2.sh fi +echo "::group::Publish homebrew" ./rtx/scripts/render-homebrew.sh >homebrew-tap/rtx.rb pushd homebrew-tap git add . && git commit -m "rtx ${RTX_VERSION#v}" diff --git a/src/cli/install.rs b/src/cli/install.rs index e5db33a7e..4b9f3b0d1 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -120,11 +120,7 @@ impl Install { fn install_missing_runtimes(&self, config: &Config) -> Result<()> { let mut ts = ToolsetBuilder::new().with_latest_versions().build(config)?; - let versions = ts - .list_missing_versions(config) - .into_iter() - .cloned() - .collect::>(); + let versions = ts.list_missing_versions(); if versions.is_empty() { info!("all runtimes are installed"); return Ok(()); diff --git a/src/shims.rs b/src/shims.rs index ab98a55fe..c5fc75be5 100644 --- a/src/shims.rs +++ b/src/shims.rs @@ -64,7 +64,7 @@ fn which_shim(config: &Config, bin_name: &str) -> Result { } } let tvs = ts.list_rtvs_with_bin(config, bin_name)?; - err_no_version_set(config, ts, bin_name, tvs)?; + err_no_version_set(ts, bin_name, tvs)?; } Err(eyre!("{} is not a valid shim", bin_name)) } @@ -190,18 +190,13 @@ fn make_shim(target: &Path, shim: &Path) -> Result<()> { Ok(()) } -fn err_no_version_set( - config: &Config, - ts: Toolset, - bin_name: &str, - tvs: Vec, -) -> Result<()> { +fn err_no_version_set(ts: Toolset, bin_name: &str, tvs: Vec) -> Result<()> { if tvs.is_empty() { return Ok(()); } let missing_plugins = tvs.iter().map(|tv| &tv.plugin_name).collect::>(); let mut missing_tools = ts - .list_missing_versions(config) + .list_missing_versions() .into_iter() .filter(|t| missing_plugins.contains(&t.plugin_name)) .collect_vec(); diff --git a/src/toolset/mod.rs b/src/toolset/mod.rs index c90c5566a..a44abf030 100644 --- a/src/toolset/mod.rs +++ b/src/toolset/mod.rs @@ -93,10 +93,11 @@ impl Toolset { pub fn install_arg_versions(&mut self, config: &Config, opts: &InstallOptions) -> Result<()> { let mpr = MultiProgressReport::new(); let versions = self - .list_missing_versions(config) + .list_current_versions() .into_iter() + .filter(|(p, tv)| opts.force || !p.is_version_installed(tv)) + .map(|(_, tv)| tv) .filter(|tv| matches!(self.versions[&tv.plugin_name].source, ToolSource::Argument)) - .cloned() .collect_vec(); self.install_versions(config, versions, &mpr, opts) } @@ -170,19 +171,11 @@ impl Toolset { shims::reshim(config, self)?; runtime_symlinks::rebuild(config) } - pub fn list_missing_versions(&self, config: &Config) -> Vec<&ToolVersion> { - self.versions - .iter() - .map(|(p, tvl)| { - let p = config.get_or_create_plugin(p); - (p, tvl) - }) - .flat_map(|(p, tvl)| { - tvl.versions - .iter() - .filter(|tv| !p.is_version_installed(tv)) - .collect_vec() - }) + pub fn list_missing_versions(&self) -> Vec { + self.list_current_versions() + .into_iter() + .filter(|(p, tv)| !p.is_version_installed(tv)) + .map(|(_, tv)| tv) .collect() } pub fn list_installed_versions(