Skip to content

Commit ed3bda7

Browse files
Merge pull request #6 from fac/fix-deploy-action
Fix deploy action
2 parents 1e4eda6 + 2dc502d commit ed3bda7

File tree

14 files changed

+102
-49
lines changed

14 files changed

+102
-49
lines changed

.rubocop.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ AllCops:
22
DisabledByDefault: true
33
Include:
44
- "**/Gemfile"
5-
- "**/lib/**.rb"
6-
- "**/test/**.rb"
7-
- "**/features/**/**.rb"
5+
- "**/lib/**/*"
6+
- "**/test/**/*"
7+
- "**/bin/**"
88
- "**.rb"
9-
- "**/producer/**.rb"
109
TargetRubyVersion: 2.7
1110

1211
#################### Layout ################################

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
serverless-tools (0.0.2)
4+
serverless-tools (0.0.3)
55
aws-sdk-lambda
66
aws-sdk-s3
77
thor
@@ -11,7 +11,7 @@ GEM
1111
specs:
1212
ast (2.4.2)
1313
aws-eventstream (1.2.0)
14-
aws-partitions (1.532.0)
14+
aws-partitions (1.534.0)
1515
aws-sdk-core (3.122.1)
1616
aws-eventstream (~> 1, >= 1.0.2)
1717
aws-partitions (~> 1, >= 1.525.0)
@@ -20,7 +20,7 @@ GEM
2020
aws-sdk-kms (1.51.0)
2121
aws-sdk-core (~> 3, >= 3.122.0)
2222
aws-sigv4 (~> 1.1)
23-
aws-sdk-lambda (1.71.0)
23+
aws-sdk-lambda (1.73.0)
2424
aws-sdk-core (~> 3, >= 3.122.0)
2525
aws-sigv4 (~> 1.1)
2626
aws-sdk-s3 (1.106.0)

lib/serverless-tools/cli.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class CLI < Thor
77
desc "comment", "create Github Issue comment body"
88
method_option :functions, :type => :string, :aliases => "-f", :default => "{}"
99
def comment
10-
comment = Comment.build(options[:functions])
10+
comment = Comment.new.build(options[:functions])
1111
puts "::set-output name=comment::#{comment}"
1212
end
1313

lib/serverless-tools/comment.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
require "json"
2+
require_relative "git"
23

34
module ServerlessTools
45
class Comment
5-
def self.build(function_json)
6-
lines = ["Functions updated for sha: #{ENV["GITHUB_SHA"]} %0A"]
6+
def initialize(git: Git.new)
7+
@git = git
8+
end
9+
10+
def build(function_json)
11+
lines = ["Functions updated for sha: #{@git.sha} %0A"]
712
lines << JSON.parse(function_json).map do |function, status|
813
"> **#{function}**: #{status} %0A"
914
end
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
require "yaml"
2+
require_relative "../git"
23

34
module ServerlessTools
45
module Deployer
56
class AwsLambdaConfig
67
attr_reader :function_name, :s3_archive_name, :handler_file, :bucket
78

8-
def initialize(filename:, function_name:)
9+
def initialize(filename:, function_name:, git: Git.new)
910
config_data = YAML.load_file(filename)
1011

12+
@git = git
1113
@repo = config_data[function_name]["repo"]
1214
@function_name = function_name
1315
@s3_archive_name = config_data[function_name]["s3_archive_name"]
@@ -16,7 +18,7 @@ def initialize(filename:, function_name:)
1618
end
1719

1820
def s3_key
19-
"#{repo}/deployments/#{git_sha}/#{function_name}/#{s3_archive_name}"
21+
"#{repo}/deployments/#{git.sha}/#{function_name}/#{s3_archive_name}"
2022
end
2123

2224
def local_filename
@@ -25,11 +27,7 @@ def local_filename
2527

2628
private
2729

28-
attr_reader :repo
29-
30-
def git_sha
31-
(ENV["GITHUB_SHA"] || (`git rev-parse HEAD`)).strip
32-
end
30+
attr_reader :repo, :git
3331
end
3432
end
3533
end

lib/serverless-tools/deployer/aws_lambda_function.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def initialize(config, client:)
99
end
1010

1111
def update_code(object)
12-
puts ""
1312
unless object.exists?
1413
puts "::warning:: Not updating #{config.function_name} as key does not exist!"
1514
puts "::warning:: key: #{object.key}"
@@ -20,15 +19,10 @@ def update_code(object)
2019
s3_bucket: object.bucket.name,
2120
s3_key: object.key,
2221
})
23-
puts "::set-output name=#{resp[:function_name]}::#{resp[:last_update_status]}"
24-
25-
puts "\\`#{resp[:function_name]}\\` function update was #{resp[:last_update_status]}"
26-
puts "> updated with #{object.key}"
22+
puts "::set-output name=#{resp[:function_name]}_status::#{resp[:last_update_status]}"
23+
puts "::set-output name=#{resp[:function_name]}_key::#{object.key}"
2724
rescue Aws::Lambda::Errors::ServiceError => e
2825
puts "::error:: An error occured when updating #{config.function_name} #{e.message}"
29-
puts "An error occured when updating \\`#{config.function_name}\\`"
30-
puts "> attempted to update with #{object.key}"
31-
puts "> error message: #{e.message}"
3226
end
3327

3428
private

lib/serverless-tools/git.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
module ServerlessTools
3+
class Git
4+
def sha
5+
(`git rev-parse HEAD`).strip
6+
end
7+
end
8+
end

lib/serverless-tools/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ServerlessTools
2-
VERSION = "0.0.2"
2+
VERSION = "0.0.3"
33
end

serverless-tools.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
3030
spec.executables = ["serverless-tools"]
3131
spec.require_paths = ["lib"]
3232

33-
spec.requirements << "zip"
33+
spec.requirements = ["zip", "git"]
3434

3535
spec.post_install_message = "Serverless tools, and beyond!"
3636

test/comment_test.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require "minitest/autorun"
2+
require "mocha/minitest"
3+
4+
require "serverless-tools/comment"
5+
6+
describe "Comment" do
7+
let(:git) { mock() }
8+
let(:key) { "/key/to/s3/object/function.zip" }
9+
let(:function) { "example_function" }
10+
let(:function_json) do
11+
{
12+
example_function_status: "Succeeded",
13+
example_function_key: key,
14+
}.to_json
15+
end
16+
17+
describe "#build" do
18+
before do
19+
git.stubs(:sha).returns("123")
20+
end
21+
22+
it "returns a value" do
23+
comment = ServerlessTools::Comment.new(git: git)
24+
25+
expected_result = "Functions updated for sha: 123 %0A"\
26+
"> **#{function}_status**: Succeeded %0A> **#{function}_key**: #{key} %0A"
27+
28+
assert_equal(comment.build(function_json), expected_result)
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)