Repository: apache/arrow
File: dev/release/02-source-test.rb (Ruby)

Code before:
  def setup
    @current_commit = git_current_commit
    detect_versions
    @tag_name_no_rc = "apache-arrow-#{@release_version}"
    @archive_name = "apache-arrow-#{@release_version}.tar.gz"
    @script = File.expand_path("dev/release/02-source.sh")
    @tarball_script = File.expand_path("dev/release/utils-create-release-tarball.sh")
    @env = File.expand_path("dev/release/.env")

    Dir.mktmpdir do |dir|
      Dir.chdir(dir) do
        yield
      end
    end
  end

  def source(*targets)
    env = {
      "SOURCE_DEFAULT" => "0",
      "release_hash" => @current_commit,
    }
    targets.each do |target|
      env["SOURCE_#{target}"] = "1"
    end
    sh(env, @tarball_script, @release_version, "0")
    Dir.mkdir("artifacts") unless Dir.exist?("artifacts")
    sh("mv", @archive_name, "artifacts/")
    File.open("artifacts/#{@archive_name}.sha512", "w") do |sha512|
      sha512.puts(sh(env, "shasum", "-a", "512", "artifacts/#{@archive_name}"))
    end
    output = sh(env, @script, @release_version, "0")
    sh("tar", "xf", "artifacts/#{@archive_name}")
    output
  end

  def test_symbolic_links
    source
    Dir.chdir(@tag_name_no_rc) do
      assert_equal([],
                   Find.find(".").find_all {|path| File.symlink?(path)})
    end
  end

  def test_python_version
    source
    Dir.chdir("#{@tag_name_no_rc}/python") do
      sh("python3", "setup.py", "sdist")
      if on_release_branch?
        pyarrow_source_archive = "dist/pyarrow-#{@release_version}.tar.gz"
      else
        pyarrow_source_archive = "dist/pyarrow-#{@release_version}a0.tar.gz"

Review comment (suggestion):
We can use `FileUtils.mkdir_p` for this. :-)

```suggestion
    FileUtils.mkdir_p("artifacts")
```

Code after:
    detect_versions
    @tag_name_no_rc = "apache-arrow-#{@release_version}"
    @archive_name = "apache-arrow-#{@release_version}.tar.gz"
    @script = File.expand_path("dev/release/02-source.sh")
    @tarball_script = File.expand_path("dev/release/utils-create-release-tarball.sh")
    @env = File.expand_path("dev/release/.env")

    Dir.mktmpdir do |dir|
      Dir.chdir(dir) do
        yield
      end
    end
  end

  def source(*targets)
    env = {
      "SOURCE_DEFAULT" => "0",
      "release_hash" => @current_commit,
    }
    targets.each do |target|
      env["SOURCE_#{target}"] = "1"
    end
    sh(env, @tarball_script, @release_version, "0")
    FileUtils.mkdir_p("artifacts")
    sh("mv", @archive_name, "artifacts/")
    File.write("artifacts/#{@archive_name}.sha512",
               sh(env, "shasum", "-a", "512", "artifacts/#{@archive_name}"))
    output = sh(env, @script, @release_version, "0")
    sh("tar", "xf", "artifacts/#{@archive_name}")
    output
  end

  def test_symbolic_links
    source
    Dir.chdir(@tag_name_no_rc) do
      assert_equal([],
                   Find.find(".").find_all {|path| File.symlink?(path)})
    end
  end

  def test_python_version
    source
    Dir.chdir("#{@tag_name_no_rc}/python") do
      sh("python3", "setup.py", "sdist")
      if on_release_branch?
        pyarrow_source_archive = "dist/pyarrow-#{@release_version}.tar.gz"
      else
        pyarrow_source_archive = "dist/pyarrow-#{@release_version}a0.tar.gz"
      end
      assert_equal([pyarrow_source_archive],
                   Dir.glob("dist/pyarrow-*.tar.gz"))