diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1b4b5ad --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +# Container image +FROM ruby:3.1.1 + +COPY . /usr/src/app + +RUN cd /usr/src/app && bundle install + +RUN chmod +x /usr/src/app/entrypoint.sh + +# ENTRYPOINT ["/usr/src/app/entrypoint.sh"] +ENTRYPOINT ["ruby", "/usr/src/app/app.rb"] \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..b5aabfc --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' do + gem 'aws-sdk-states' +end \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1f78841 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright 2019 Amazon.com, Inc. or its affiliates. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..21a03fb --- /dev/null +++ b/action.yml @@ -0,0 +1,8 @@ +# action.yml +name: 'StepFunction Deployment Monitoring' +description: 'Polls a step function until completion.' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.STEP_FUNCTION_ARN }} diff --git a/app.rb b/app.rb new file mode 100644 index 0000000..b261e79 --- /dev/null +++ b/app.rb @@ -0,0 +1,38 @@ +require 'optparse' +require 'aws-sdk-states' + +options = {} +option_parser = OptionParser.new do |opts| + opts.banner = 'Usage: app.rb [options]' + opts.on('-e', '--execution-arn ', 'Step Function Execution ARN to monitor') do |v| + options[:execution_arn] = v + end +end + +option_parser.parse! +if options[:execution_arn].nil? + puts 'StepFunction execution arn is required!' + puts option_parser.help + exit 1 +end + +def get_deployment(execution_arn) + aws_client = Aws::States::Client.new(region: 'eu-west-1') + aws_client.describe_execution({ execution_arn: execution_arn }) +end + +deployment_status = get_deployment(options[:execution_arn]).status + +# One of: "RUNNING", "SUCCEEDED", "FAILED", "TIMED_OUT", "ABORTED" +if deployment_status == 'RUNNING' + puts 'Deployment in progress...🔄' + sleep 15 until get_deployment(options[:execution_arn]).status != 'RUNNING' +end + +if %w[FAILED TIMED_OUT ABORTED].include?(deployment_status) + puts "Deployment Failed: #{deployment_status} ❌" + exit 1 +elsif deployment_status == 'SUCCEEDED' + puts 'Deployment Successful 🎉' + exit 0 +end diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..84e7134 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,2 @@ +#!/bin/bash +ruby /usr/src/app/app.rb $STEP_FUNCTION_ARN