From 0f3fa50deb4fc763d5de69efde30013bcfd4fddc Mon Sep 17 00:00:00 2001 From: Artur Trzop Date: Tue, 23 May 2023 16:04:08 +0200 Subject: [PATCH] feat(node_retry_count): Add support for node retry count on Github Actions --- lib/knapsack_pro/config/ci/github_actions.rb | 8 ++++++++ spec/knapsack_pro/config/ci/github_actions_spec.rb | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/knapsack_pro/config/ci/github_actions.rb b/lib/knapsack_pro/config/ci/github_actions.rb index ab2cb0a5..f44ce839 100644 --- a/lib/knapsack_pro/config/ci/github_actions.rb +++ b/lib/knapsack_pro/config/ci/github_actions.rb @@ -16,6 +16,14 @@ def node_build_id ENV['GITHUB_RUN_ID'] end + def node_retry_count + # A unique number for each attempt of a particular workflow run in a repository. + # This number begins at 1 for the workflow run's first attempt, and increments with each re-run. + run_attempt = ENV['GITHUB_RUN_ATTEMPT'] + return unless run_attempt + run_attempt.to_i - 1 + end + def commit_hash ENV['GITHUB_SHA'] end diff --git a/spec/knapsack_pro/config/ci/github_actions_spec.rb b/spec/knapsack_pro/config/ci/github_actions_spec.rb index 59062ea5..691b7d7e 100644 --- a/spec/knapsack_pro/config/ci/github_actions_spec.rb +++ b/spec/knapsack_pro/config/ci/github_actions_spec.rb @@ -32,6 +32,19 @@ end end + describe '#node_retry_count' do + subject { described_class.new.node_retry_count } + + context 'when the environment exists' do + let(:env) { { 'GITHUB_RUN_ATTEMPT' => 2 } } + it { should eql 1 } + end + + context "when the environment doesn't exist" do + it { should be nil } + end + end + describe '#commit_hash' do subject { described_class.new.commit_hash }