Skip to content

Commit 6199e91

Browse files
authored
Merge pull request #147 from skipkayhil/hm-orlspzouxytyluwl
Automatically ci-skip if all changed files are md
2 parents 54cf2f7 + 9b591b8 commit 6199e91

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

bin/fetch-pr

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ def github_repo
1717
ENV.fetch("BUILDKITE_REPO")[%r{github\.com[/:](.+?)(?:\.git)?\z}, 1]
1818
end
1919

20-
uri = URI("https://api.github.com/repos/#{github_repo}/pulls/#{pull_request_number}")
20+
case ARGV
21+
in ["files"]
22+
$stderr.write "Fetching pull-request files: "
23+
uri = URI("https://api.github.com/repos/#{github_repo}/pulls/#{pull_request_number}/files")
24+
else
25+
$stderr.write "Fetching pull-request metadata: "
26+
uri = URI("https://api.github.com/repos/#{github_repo}/pulls/#{pull_request_number}")
27+
end
2128

2229
req = Net::HTTP::Get.new(uri)
2330
req["Authorization"] = "token #{github_token}"
@@ -26,4 +33,6 @@ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
2633
http.request(req)
2734
end
2835

36+
$stderr.write "#{res.code}.\n"
37+
2938
puts res.body

lib/buildkite/config/build_context.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,22 @@ def nightly?
2323
ENV.has_key?("RAILS_CI_NIGHTLY")
2424
end
2525

26+
def full?
27+
# [ci full], [full ci], [ci-full], or [full-ci]
28+
[ENV["BUILDKITE_MESSAGE"], FetchPr.title].grep(/(ci full|full ci|ci-full|full-ci)/i).any?
29+
end
30+
2631
def skip?
2732
# [ci skip], [skip ci], [ci-skip], or [skip-ci]
2833
[ENV["BUILDKITE_MESSAGE"], FetchPr.title].grep(/(ci skip|skip ci|ci-skip|skip-ci)/i).any?
2934
end
3035

36+
def only_markdown?
37+
filenames = FetchPr.filenames
38+
39+
!filenames.empty? && filenames.all? { |name| name.end_with? ".md" }
40+
end
41+
3142
def rails_root
3243
Pathname.pwd
3344
end

lib/buildkite/config/fetch_pr.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44

55
module Buildkite::Config
66
module FetchPr
7-
def self.title
8-
pr = JSON.parse(File.read(".buildkite/tmp/.pr-meta.json"))
9-
pr["title"]
10-
rescue
11-
""
7+
class << self
8+
def title
9+
pr = JSON.parse(File.read(".buildkite/tmp/.pr-meta.json"))
10+
pr["title"]
11+
rescue
12+
""
13+
end
14+
15+
def filenames
16+
JSON
17+
.load_file(".buildkite/tmp/.pr-files.json")
18+
.map { |f| f["filename"] }
19+
rescue
20+
[]
21+
end
1222
end
1323
end
1424
end

pipelines/rails-ci/initial.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ steps:
2727
2828
rm -rf .buildkite/.git
2929
30-
echo "Fetching pull-request metadata:"
3130
(docker run --rm \
3231
-v "$$PWD":/app:ro -w /app \
3332
-e GITHUB_PUBLIC_REPO_TOKEN \
@@ -36,6 +35,14 @@ steps:
3635
ruby:latest \
3736
.buildkite/bin/fetch-pr > .buildkite/tmp/.pr-meta.json) || true
3837
38+
(docker run --rm \
39+
-v "$$PWD":/app:ro -w /app \
40+
-e GITHUB_PUBLIC_REPO_TOKEN \
41+
-e BUILDKITE_REPO \
42+
-e BUILDKITE_PULL_REQUEST \
43+
ruby:latest \
44+
.buildkite/bin/fetch-pr files > .buildkite/tmp/.pr-files.json) || true
45+
3946
echo "Generating pipeline:"
4047
sh -c "$$PIPELINE_COMMAND"
4148

pipelines/rails-ci/pipeline.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
end
4343
end
4444

45-
if build_context.skip?
45+
if !build_context.full? && (build_context.skip? || build_context.only_markdown?)
4646
command do
4747
label ":bk-status-passed: Build skipped"
4848
skip true

0 commit comments

Comments
 (0)