Skip to content

Commit

Permalink
Merge pull request #197 from KnapsackPro/github-retry-count
Browse files Browse the repository at this point in the history
Add support for CI node retry count on GitHub Actions
  • Loading branch information
ArturT authored May 23, 2023
2 parents 5136950 + dd91e1c commit 8a4d0d3
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 117 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

### 4.1.0

* Add support for CI node retry count on GitHub Actions

https://github.com/KnapsackPro/knapsack_pro-ruby/pull/197

https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v4.0.0...v4.1.0

### 4.0.0

* Raise when `KNAPSACK_PRO_CI_NODE_BUILD_ID` is missing
Expand Down
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
16 changes: 8 additions & 8 deletions spec/knapsack_pro/config/ci/app_veyor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,51 @@
describe '#node_build_id' do
subject { described_class.new.node_build_id }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'APPVEYOR_BUILD_ID' => 123 } }
it { should eql 123 }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#commit_hash' do
subject { described_class.new.commit_hash }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'APPVEYOR_REPO_COMMIT' => '2e13512fc230d6f9ebf4923352718e4d' } }
it { should eql '2e13512fc230d6f9ebf4923352718e4d' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#branch' do
subject { described_class.new.branch }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'APPVEYOR_REPO_BRANCH' => 'master' } }
it { should eql 'master' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#project_dir' do
subject { described_class.new.project_dir }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'APPVEYOR_BUILD_FOLDER' => '/path/to/clone/repo' } }
it { should eql '/path/to/clone/repo' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end
Expand Down
28 changes: 14 additions & 14 deletions spec/knapsack_pro/config/ci/buildkite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,90 +10,90 @@
describe '#node_total' do
subject { described_class.new.node_total }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'BUILDKITE_PARALLEL_JOB_COUNT' => 4 } }
it { should eql 4 }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#node_index' do
subject { described_class.new.node_index }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'BUILDKITE_PARALLEL_JOB' => 3 } }
it { should eql 3 }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#node_build_id' do
subject { described_class.new.node_build_id }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'BUILDKITE_BUILD_NUMBER' => 1514 } }
it { should eql 1514 }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#node_retry_count' do
subject { described_class.new.node_retry_count }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'BUILDKITE_RETRY_COUNT' => '1' } }
it { should eql '1' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#commit_hash' do
subject { described_class.new.commit_hash }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'BUILDKITE_COMMIT' => '3fa64859337f6e56409d49f865d13fd7' } }
it { should eql '3fa64859337f6e56409d49f865d13fd7' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#branch' do
subject { described_class.new.branch }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'BUILDKITE_BRANCH' => 'main' } }
it { should eql 'main' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#project_dir' do
subject { described_class.new.project_dir }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'BUILDKITE_BUILD_CHECKOUT_PATH' => '/home/user/knapsack_pro-ruby' } }
it { should eql '/home/user/knapsack_pro-ruby' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end
Expand Down
22 changes: 11 additions & 11 deletions spec/knapsack_pro/config/ci/circle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,64 @@
describe '#node_total' do
subject { described_class.new.node_total }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'CIRCLE_NODE_TOTAL' => 4 } }
it { should eql 4 }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#node_index' do
subject { described_class.new.node_index }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'CIRCLE_NODE_INDEX' => 3 } }
it { should eql 3 }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#node_build_id' do
subject { described_class.new.node_build_id }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'CIRCLE_BUILD_NUM' => 123 } }
it { should eql 123 }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#commit_hash' do
subject { described_class.new.commit_hash }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'CIRCLE_SHA1' => '3fa64859337f6e56409d49f865d13fd7' } }
it { should eql '3fa64859337f6e56409d49f865d13fd7' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#branch' do
subject { described_class.new.branch }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'CIRCLE_BRANCH' => 'main' } }
it { should eql 'main' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end
Expand All @@ -80,7 +80,7 @@
it { should eql '~/knapsack_pro-ruby' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end
Expand Down
24 changes: 12 additions & 12 deletions spec/knapsack_pro/config/ci/cirrus_ci_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,77 +10,77 @@
describe '#node_total' do
subject { described_class.new.node_total }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'CI_NODE_TOTAL' => 4 } }
it { should eql 4 }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#node_index' do
subject { described_class.new.node_index }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'CI_NODE_INDEX' => 3 } }
it { should eql 3 }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#node_build_id' do
subject { described_class.new.node_build_id }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'CIRRUS_BUILD_ID' => 123 } }
it { should eql 123 }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#commit_hash' do
subject { described_class.new.commit_hash }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'CIRRUS_CHANGE_IN_REPO' => '2e13512fc230d6f9ebf4923352718e4d' } }
it { should eql '2e13512fc230d6f9ebf4923352718e4d' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#branch' do
subject { described_class.new.branch }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'CIRRUS_BRANCH' => 'master' } }
it { should eql 'master' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end

describe '#project_dir' do
subject { described_class.new.project_dir }

context 'when environment exists' do
context 'when the environment exists' do
let(:env) { { 'CIRRUS_WORKING_DIR' => '/tmp/cirrus-ci-build' } }
it { should eql '/tmp/cirrus-ci-build' }
end

context "when environment doesn't exist" do
context "when the environment doesn't exist" do
it { should be nil }
end
end
Expand Down
Loading

0 comments on commit 8a4d0d3

Please sign in to comment.