Skip to content

Commit

Permalink
feat(gas): Declare Kokoro artifacts (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuma committed May 9, 2023
1 parent 5e19f5b commit 308d1b1
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 3 deletions.
56 changes: 56 additions & 0 deletions .kokoro/gas/trigger-cloud.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Build logs will be here
action {
define_artifacts {
regex: "**/*sponge_log.xml"
}
}

# Download Ruby-cloud resources
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-ruby"

# Download trampoline resources
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# Use the trampoline script to run in docker.
build_file: "ruby-common-tools/.kokoro/gas/trigger_trampoline.sh"

# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/yoshi-ruby/release"
}

# Entrypoint
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: ".kokoro/gas/trigger.sh"
}

# List of binary platforms for protobuf builds, colon-delimited.
env_vars: {
key: "GAS_PLATFORMS"
value: "aarch64-linux:arm64-darwin:x64-mingw-ucrt:x64-mingw32:x86-linux:x86-mingw32:x86_64-darwin:x86_64-linux"
}

# List of minor Ruby versions for protobuf builds, colon-delimited.
env_vars: {
key: "GAS_RUBY_VERSIONS"
value: "2.6:2.7:3.0:3.1:3.2"
}

# Path to the RubyGems API key file for the google-cloud account.
env_vars: {
key: "GAS_RUBYGEMS_KEY_FILE"
value: "rubygems-token-cloud.txt"
}

# Store the packages uploaded to rubygems.org, which
# we can later use to generate SBOMs and attestations.
action {
define_artifacts {
regex: "github/ruby-common-tools/gas/artifacts/*.gem"
strip_prefix: "github/ruby-common-tools/gas/artifacts"
}
}
9 changes: 9 additions & 0 deletions .kokoro/gas/trigger-generic.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ env_vars: {
key: "GAS_RUBYGEMS_KEY_FILE"
value: "rubygems-token-generic.txt"
}

# Store the packages uploaded to rubygems.org, which
# we can later use to generate SBOMs and attestations.
action {
define_artifacts {
regex: "github/ruby-common-tools/gas/artifacts/*.gem"
strip_prefix: "github/ruby-common-tools/gas/artifacts"
}
}
9 changes: 9 additions & 0 deletions .kokoro/gas/trigger-protobuf.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ env_vars: {
key: "GAS_RUBYGEMS_KEY_FILE"
value: "rubygems-token-protobuf.txt"
}

# Store the packages uploaded to rubygems.org, which
# we can later use to generate SBOMs and attestations.
action {
define_artifacts {
regex: "github/ruby-common-tools/gas/artifacts/*.gem"
strip_prefix: "github/ruby-common-tools/gas/artifacts"
}
}
2 changes: 1 addition & 1 deletion .kokoro/gas/trigger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export PATH=$GEM_HOME/bin:$PATH

cd gas
rbenv local $RUBY_31_VERSION
gem install --no-document toys:0.14.4
gem install --no-document toys:0.14.5
toys gas kokoro-trigger -v
9 changes: 8 additions & 1 deletion .trampolinerc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ required_envvars+=(

# Add env vars which are passed down into the container here.
pass_down_envvars+=(
"GAS_ADDITIONAL_GEMS" "GAS_DRY_RUN" "GAS_PLATFORMS" "GAS_RUBYGEMS_KEY_FILE" "GAS_RUBY_VERSIONS" "GAS_SOURCE_GEM"
"GAS_ADDITIONAL_GEMS"
"GAS_ARTIFACTS_DIR"
"GAS_DRY_RUN"
"GAS_PLATFORMS"
"GAS_RUBYGEMS_KEY_FILE"
"GAS_RUBY_VERSIONS"
"GAS_SOURCE_GEM"
"GAS_WORKSPACE_DIR"
)

# Prevent unintentional override on the default image.
Expand Down
1 change: 1 addition & 0 deletions gas/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/workspace
/artifacts
24 changes: 23 additions & 1 deletion gas/.toys/gas/.test/test_kokoro_trigger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

let(:exec_service) { Toys::Utils::Exec.new }
let(:workspace_dir) { Dir.mktmpdir }
let(:artifacts_dir) { File.join workspace_dir, "artifacts" }
let(:gem_platforms) do
[
"arm64-darwin",
Expand All @@ -52,7 +53,8 @@
"GAS_PLATFORMS" => gem_platforms.join(":"),
"GAS_RUBY_VERSIONS" => ruby_versions.join(":"),
"GAS_RUBYGEMS_KEY_FILE" => "data2/keyfile.txt",
"GAS_WORKSPACE_DIR" => workspace_dir
"GAS_WORKSPACE_DIR" => workspace_dir,
"GAS_ARTIFACTS_DIR" => artifacts_dir
}
end
let(:excluded_versions) do
Expand All @@ -61,6 +63,7 @@
"x64-mingw-ucrt" => ["2.7", "3.0"]
}
end
let(:fake_gems) { ["fake-gem-1.0.gem", "fake-gem-2.0.gem"] }

def temp_set_env hash
old_env = hash.to_h do |key, val|
Expand Down Expand Up @@ -133,5 +136,24 @@ def quiet_trigger noisy: false
end
end
end

# Make sure we copied gems into the artifacts directory
gem_platforms.each do |platform|
artifact_name = "#{gem_and_version}-#{platform}.gem"
assert File.exist? "#{artifacts_dir}/#{artifact_name}"
artifact_content = File.read "#{artifacts_dir}/#{artifact_name}"
original_content = File.read "#{workspace_dir}/#{gem_and_version}/pkg/#{artifact_name}"
assert_equal original_content, artifact_content
end

# Make sure the artifacts directory includes the source and additional gems
original_content = File.read "#{__dir__}/data/#{gem_and_version}.gem"
artifact_content = File.read "#{artifacts_dir}/#{gem_and_version}.gem"
assert_equal original_content, artifact_content
fake_gems.each do |fake_gem|
original_content = File.read "#{__dir__}/data2/#{fake_gem}"
artifact_content = File.read "#{artifacts_dir}/#{fake_gem}"
assert_equal original_content, artifact_content
end
end
end
24 changes: 24 additions & 0 deletions gas/.toys/gas/kokoro-trigger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def run
analyze_source
build_binaries
upload_gems
prepare_artifacts
end

# Read input and configuration from the environment.
Expand All @@ -67,6 +68,7 @@ def read_input
@rubygems_key_file = File.join gfile_dir, ENV["GAS_RUBYGEMS_KEY_FILE"]
@dry_run = !ENV["GAS_DRY_RUN"].to_s.empty?
@workspace_dir = ENV["GAS_WORKSPACE_DIR"] || "workspace"
@artifacts_dir = ENV["GAS_ARTIFACTS_DIR"] || "artifacts"
end

# Read the gem name and version from the source gem metadata
Expand Down Expand Up @@ -122,3 +124,25 @@ def upload_gems
exit result
end
end

def prepare_artifacts
return if @artifacts_dir.empty? || @dry_run
rm_rf @artifacts_dir
mkdir_p @artifacts_dir
cd "#{@workspace_dir}/#{@gem_name}-#{@gem_version}/pkg" do
Dir.glob "*.gem" do |name|
cp name, "#{@artifacts_dir}/#{name}"
end
end
cp @source_gem, "#{@artifacts_dir}/#{File.basename @source_gem}"
@additional_gems.each do |additional_entry|
if File.file? additional_entry
cp additional_entry, "#{@artifacts_dir}/#{File.basename additional_entry}"
elsif File.directory? additional_entry
additional_gems = Dir.glob "#{additional_entry}/**/*.gem"
additional_gems.each do |additional_gem|
cp additional_gem, "#{@artifacts_dir}/#{File.basename additional_gem}"
end
end
end
end

0 comments on commit 308d1b1

Please sign in to comment.