From 0a155790840bbe80fb0ca60f11c07b1d9f745d9e Mon Sep 17 00:00:00 2001 From: Brice TEXIER Date: Mon, 23 Dec 2024 11:31:13 +0100 Subject: [PATCH 1/2] Fix asdf_version usage --- .github/workflows/test.yml | 21 ++++++-------- CHANGELOG.md | 4 +++ lib/capistrano/asdf/version.rb | 2 +- lib/capistrano/tasks/asdf.rake | 52 ++++++++++++++++------------------ 4 files changed, 37 insertions(+), 42 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 327f49e..19e52a4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,18 +10,13 @@ on: jobs: build: runs-on: ubuntu-latest - name: Ruby ${{ matrix.ruby }} - strategy: - matrix: - ruby: - - '3.3.4' + name: Test and lint steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run the default task - run: bundle exec rake + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Run the default task + run: bundle exec rake diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cdab5e..d54438d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.5.2 + +Make ASDF version really usable with `asdf_version` variable. + ## 1.5.1 Remove update of ASDF which has been removed. See https://github.com/asdf-vm/asdf/pull/1806. diff --git a/lib/capistrano/asdf/version.rb b/lib/capistrano/asdf/version.rb index 5150f98..f6047b5 100644 --- a/lib/capistrano/asdf/version.rb +++ b/lib/capistrano/asdf/version.rb @@ -2,6 +2,6 @@ module Capistrano module Asdf - VERSION = "1.5.1" + VERSION = "1.5.2" end end diff --git a/lib/capistrano/tasks/asdf.rake b/lib/capistrano/tasks/asdf.rake index c5045ff..90f4193 100644 --- a/lib/capistrano/tasks/asdf.rake +++ b/lib/capistrano/tasks/asdf.rake @@ -24,9 +24,18 @@ namespace :asdf do if fetch(:asdf_setup) on roles(fetch(:asdf_roles)) do if test("[ -d #{fetch(:asdf_path)} ]") - info "ASDF is installed on #{fetch(:asdf_path)}" + within(fetch(:asdf_path)) do + version = capture(:cat, "version.txt").strip + if fetch(:asdf_version) == version + info "ASDF #{fetch(:asdf_version)} is already installed on #{fetch(:asdf_path)}" + else + execute :git, "checkout", "v#{fetch(:asdf_version)}" + info "ASDF is updated from #{version} to #{fetch(:asdf_version)} (on #{fetch(:asdf_path)})" + end + end else execute(:git, "clone", fetch(:asdf_repository), fetch(:asdf_path), "--branch", fetch(:asdf_version)) + info "ASDF #{fetch(:asdf_version)} is installed on #{fetch(:asdf_path)}" end end end @@ -61,20 +70,13 @@ namespace :asdf do end namespace :uninstall do - desc "Uninstall ASDF Ruby version based on the .tool-versions of your project" - task :ruby do - on roles(fetch(:asdf_roles)) do - within(release_path) do - execute(:asdf, "uninstall", "ruby") - end - end - end - - desc "Uninstall ASDF NodeJS version based on the .tool-versions of your project" - task :nodejs do - on roles(fetch(:asdf_roles)) do - within(release_path) do - execute(:asdf, "uninstall", "nodejs") + %i[ruby nodejs].each do |tool| + desc "Uninstall ASDF #{tool} version based on the .tool-versions of your project" + task tool do + on roles(fetch(:asdf_roles)) do + within(release_path) do + execute(:asdf, "uninstall", tool.to_s) + end end end end @@ -87,22 +89,16 @@ namespace :asdf do asdf_prefix = fetch(:asdf_prefix, -> { "#{fetch(:asdf_path)}/bin/asdf exec" }) SSHKit.config.command_map[:asdf] = "#{fetch(:asdf_path)}/bin/asdf" - if fetch(:asdf_tools).include?("ruby") - if fetch(:asdf_ruby_use_jemalloc) - on roles(fetch(:asdf_roles)) do - if test("[ -f #{fetch(:asdf_jemalloc_path)}/jemalloc.h ]") - SSHKit.config.default_env.merge!(ruby_configure_opts: "--with-jemalloc=#{fetch(:asdf_jemalloc_path)}") - end + if fetch(:asdf_tools).include?("ruby") && fetch(:asdf_ruby_use_jemalloc) + on roles(fetch(:asdf_roles)) do + if test("[ -f #{fetch(:asdf_jemalloc_path)}/jemalloc.h ]") + SSHKit.config.default_env.merge!(ruby_configure_opts: "--with-jemalloc=#{fetch(:asdf_jemalloc_path)}") end end - - fetch(:asdf_map_ruby_bins).uniq.each do |command| - SSHKit.config.command_map.prefix[command.to_sym].unshift(asdf_prefix) - end end - if fetch(:asdf_tools).include?("nodejs") - fetch(:asdf_map_nodejs_bins).uniq.each do |command| + fetch(:asdf_tools).each do |tool| + fetch(:"asdf_map_#{tool}_bins", []).uniq.each do |command| SSHKit.config.command_map.prefix[command.to_sym].unshift(asdf_prefix) end end @@ -119,7 +115,7 @@ namespace :load do task :defaults do set :asdf_path, fetch(:asdf_path, "~/.asdf") set :asdf_repository, fetch(:asdf_repository, "https://github.com/asdf-vm/asdf.git") - set :asdf_version, fetch(:asdf_version, "v0.14.1") + set :asdf_version, fetch(:asdf_version, "0.15.0") set :asdf_setup, fetch(:asdf_setup, true) set :asdf_roles, fetch(:asdf_roles, :all) set :asdf_ruby_use_jemalloc, fetch(:asdf_ruby_use_jemalloc, true) From 3bb193339765c87e9c4f019c528a12530199a403 Mon Sep 17 00:00:00 2001 From: Brice TEXIER Date: Tue, 24 Dec 2024 09:05:20 +0100 Subject: [PATCH 2/2] Add .tool-versions --- .tool-versions | 1 + 1 file changed, 1 insertion(+) create mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..5aa8e0c --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 3.3.6