Skip to content

Commit 647fabb

Browse files
committed
Add some CI
1 parent 237b21b commit 647fabb

File tree

9 files changed

+169
-57
lines changed

9 files changed

+169
-57
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Continuous Integration
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
7+
jobs:
8+
ruby:
9+
strategy:
10+
fail-fast: false
11+
matrix: 3.3
12+
runs-on: ubuntu-latest
13+
steps:
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
- name: Setup Ruby
18+
uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: ${{ matrix.ruby }}
21+
- name: Install dependencies
22+
run: bundle install
23+
# no tests yet
24+
#- name: Run rspec
25+
# run: bundle exec rspec
26+
- name: Run chefstyle
27+
run: ./scripts/run_chefstyle.sh
28+
- name: Run markdownlint
29+
run: ./scripts/run_markdownlint.sh

.github/workflows/dco.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: DCO Check
2+
on: [pull_request]
3+
4+
jobs:
5+
dco_check_job:
6+
runs-on: ubuntu-latest
7+
name: DCO Check
8+
steps:
9+
- name: Get PR Commits
10+
uses: tim-actions/get-pr-commits@master
11+
id: 'get-pr-commits'
12+
with:
13+
token: ${{ secrets.GITHUB_TOKEN }}
14+
- name: DCO Check
15+
uses: tim-actions/dco@master
16+
with:
17+
commits: ${{ steps.get-pr-commits.outputs.commits }}

.sugarjar.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
on_push: [lint]
2+
lint:
3+
- scripts/run_chefstyle.sh
4+
- scripts/run_markdownlint.sh

Gemfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
source "https://rubygems.org"
22

3-
gem 'sqlite3'
4-
gem 'octokit'
5-
gem 'faraday-retry'
6-
gem 'gruff'
3+
gem "sqlite3"
4+
gem "octokit"
5+
gem "faraday-retry"
6+
gem "gruff"
7+
8+
group(:development) do
9+
gem "chefstyle"
10+
gem "mdl"
11+
end

Gemfile.lock

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ GEM
33
specs:
44
addressable (2.8.7)
55
public_suffix (>= 2.0.2, < 7.0)
6+
ast (2.4.2)
67
bigdecimal (3.1.9)
8+
chef-utils (18.6.2)
9+
concurrent-ruby
10+
chefstyle (2.2.3)
11+
rubocop (= 1.25.1)
12+
concurrent-ruby (1.3.5)
713
faraday (2.12.2)
814
faraday-net_http (>= 2.0, < 3.5)
915
json
@@ -18,18 +24,53 @@ GEM
1824
rmagick (>= 5.5)
1925
histogram (0.2.4.1)
2026
json (2.10.2)
27+
kramdown (2.5.1)
28+
rexml (>= 3.3.9)
29+
kramdown-parser-gfm (1.1.0)
30+
kramdown (~> 2.0)
2131
logger (1.6.6)
32+
mdl (0.13.0)
33+
kramdown (~> 2.3)
34+
kramdown-parser-gfm (~> 1.1)
35+
mixlib-cli (~> 2.1, >= 2.1.1)
36+
mixlib-config (>= 2.2.1, < 4)
37+
mixlib-shellout
38+
mixlib-cli (2.1.8)
39+
mixlib-config (3.0.27)
40+
tomlrb
41+
mixlib-shellout (3.3.8)
42+
chef-utils
2243
net-http (0.6.0)
2344
uri
2445
observer (0.1.2)
2546
octokit (9.2.0)
2647
faraday (>= 1, < 3)
2748
sawyer (~> 0.9)
49+
parallel (1.26.3)
50+
parser (3.3.7.1)
51+
ast (~> 2.4.1)
52+
racc
2853
pkg-config (1.6.0)
2954
public_suffix (6.0.1)
55+
racc (1.8.1)
56+
rainbow (3.1.1)
57+
regexp_parser (2.10.0)
58+
rexml (3.4.1)
3059
rmagick (6.1.1)
3160
observer (~> 0.1)
3261
pkg-config (~> 1.4)
62+
rubocop (1.25.1)
63+
parallel (~> 1.10)
64+
parser (>= 3.1.0.0)
65+
rainbow (>= 2.2.2, < 4.0)
66+
regexp_parser (>= 1.8, < 3.0)
67+
rexml
68+
rubocop-ast (>= 1.15.1, < 2.0)
69+
ruby-progressbar (~> 1.7)
70+
unicode-display_width (>= 1.4.0, < 3.0)
71+
rubocop-ast (1.38.1)
72+
parser (>= 3.3.1.0)
73+
ruby-progressbar (1.13.0)
3374
sawyer (0.9.2)
3475
addressable (>= 2.3.5)
3576
faraday (>= 0.17.3, < 3)
@@ -43,6 +84,8 @@ GEM
4384
sqlite3 (2.6.0-x86_64-darwin)
4485
sqlite3 (2.6.0-x86_64-linux-gnu)
4586
sqlite3 (2.6.0-x86_64-linux-musl)
87+
tomlrb (2.0.3)
88+
unicode-display_width (2.6.0)
4689
uri (1.0.3)
4790

4891
PLATFORMS
@@ -58,8 +101,10 @@ PLATFORMS
58101
x86_64-linux-musl
59102

60103
DEPENDENCIES
104+
chefstyle
61105
faraday-retry
62106
gruff
107+
mdl
63108
octokit
64109
sqlite3
65110

scripts/run_chefstyle.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
bundle exec chefstyle "$@"

scripts/run_markdownlint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
bundle exec mdl "$@"

src/chef-ci-status.rb

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#!/usr/bin/env ruby
22

3-
require 'optparse'
4-
require 'date'
5-
require 'yaml'
6-
require 'octokit'
7-
require 'set'
8-
3+
require "optparse"
4+
require "date"
5+
require "yaml"
6+
require "octokit"
7+
require "set"
98

109
# Get GitHub token
1110
def get_github_token
12-
config_path = File.expand_path('~/.config/gh/hosts.yml')
11+
config_path = File.expand_path("~/.config/gh/hosts.yml")
1312
if File.exist?(config_path)
1413
config = YAML.load_file(config_path)
15-
return config.dig('github.com', 'oauth_token')
14+
return config.dig("github.com", "oauth_token")
1615
end
1716
nil
1817
end
@@ -33,7 +32,7 @@ def get_failed_tests_from_ci(client, options, branches)
3332
page = 1
3433

3534
loop do
36-
runs = client.workflow_runs(repo, workflow.id, branch: branch, status: 'completed', per_page: 100, page: page)
35+
runs = client.workflow_runs(repo, workflow.id, branch: branch, status: "completed", per_page: 100, page: page)
3736
break if runs.workflow_runs.empty?
3837

3938
workflow_runs.concat(runs.workflow_runs)
@@ -42,7 +41,7 @@ def get_failed_tests_from_ci(client, options, branches)
4241
page += 1
4342
end
4443

45-
workflow_runs.sort_by! { |run| run.created_at }
44+
workflow_runs.sort_by!(&:created_at)
4645
last_failure_date = {}
4746

4847
workflow_runs.each do |run|
@@ -55,7 +54,7 @@ def get_failed_tests_from_ci(client, options, branches)
5554
jobs.each do |job|
5655
puts " Checking job: #{job.name} (Status: #{job.conclusion})" if options[:verbose]
5756

58-
failed_tests[branch][job.name] ||= Set.new if job.conclusion == 'failure'
57+
failed_tests[branch][job.name] ||= Set.new if job.conclusion == "failure"
5958
last_date = last_failure_date[job.name]
6059

6160
if last_date
@@ -66,11 +65,11 @@ def get_failed_tests_from_ci(client, options, branches)
6665
end
6766
end
6867

69-
if job.conclusion == 'failure'
68+
if job.conclusion == "failure"
7069
puts " -> First failure of #{job.name}" if options[:verbose] && !last_failure_date.key?(job.name)
7170
failed_tests[branch][job.name] << run_date
7271
last_failure_date[job.name] = run_date
73-
elsif job.conclusion == 'success'
72+
elsif job.conclusion == "success"
7473
last_failure_date.delete(job.name)
7574
end
7675
rescue StandardError => e
@@ -93,35 +92,35 @@ def get_failed_tests_from_ci(client, options, branches)
9392
end
9493

9594
options = {
96-
owner: 'chef',
97-
repo: 'chef',
98-
branches: 'chef-18,main',
95+
owner: "chef",
96+
repo: "chef",
97+
branches: "chef-18,main",
9998
days: 30,
100-
verbose: false
99+
verbose: false,
101100
}
102101

103102
OptionParser.new do |opts|
104-
opts.banner = 'Usage: script.rb [options]'
103+
opts.banner = "Usage: script.rb [options]"
105104

106-
opts.on('--owner OWNER', 'GitHub owner/org name') { |v| options[:owner] = v }
107-
opts.on('--repo REPO', 'GitHub repository name') { |v| options[:repo] = v }
108-
opts.on('--branches BRANCHES', 'Comma-separated list of branches') { |v| options[:branches] = v }
109-
opts.on('--days DAYS', Integer, 'Number of days to analyze') { |v| options[:days] = v }
110-
opts.on('-v', '--verbose', 'Enable verbose output') { options[:verbose] = true }
105+
opts.on("--owner OWNER", "GitHub owner/org name") { |v| options[:owner] = v }
106+
opts.on("--repo REPO", "GitHub repository name") { |v| options[:repo] = v }
107+
opts.on("--branches BRANCHES", "Comma-separated list of branches") { |v| options[:branches] = v }
108+
opts.on("--days DAYS", Integer, "Number of days to analyze") { |v| options[:days] = v }
109+
opts.on("-v", "--verbose", "Enable verbose output") { options[:verbose] = true }
111110
end.parse!
112111

113112
github_token = get_github_token
114-
raise 'GitHub token not found in ~/.config/gh/hosts.yml' unless github_token
113+
raise "GitHub token not found in ~/.config/gh/hosts.yml" unless github_token
115114

116115
client = Octokit::Client.new(access_token: github_token)
117116

118-
branches = options[:branches].split(',')
117+
branches = options[:branches].split(",")
119118
test_failures = get_failed_tests_from_ci(client, options, branches)
120119
puts "Days each job was broken in the last #{options[:days]} days:"
121120
test_failures.each do |branch, jobs|
122121
puts "\nBranch: #{branch}"
123122
if jobs.empty?
124-
puts ' No job failures found.'
123+
puts " No job failures found."
125124
else
126125
jobs.sort.each do |job, dates|
127126
puts " #{job}: #{dates.size} days"

0 commit comments

Comments
 (0)