Skip to content

Commit

Permalink
feat(node_retry_count): Add support for node retry count on Github Ac…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
ArturT committed May 23, 2023
1 parent 5136950 commit 0f3fa50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/knapsack_pro/config/ci/github_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/knapsack_pro/config/ci/github_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit 0f3fa50

Please sign in to comment.