Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bamboo_ci/stop_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.build(bamboo_ci_ref)
end

def self.comment(check_suite, new_check_suite)
new_url = "https://ci1.netdef.org/browse/#{new_check_suite.bamboo_ci_ref}"
new_url = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{new_check_suite.bamboo_ci_ref}"
comment = "This execution was cancelled due to a new commit or `ci:rerun` (#{new_url})"

add_comment_to_ci(check_suite.bamboo_ci_ref, comment)
Expand Down
6 changes: 3 additions & 3 deletions lib/github/build/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def create_jobs(rerun)
if rerun
next unless ci_job.stage.configuration.can_retry?

url = "https://ci1.netdef.org/browse/#{ci_job.job_ref}"
url = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{ci_job.job_ref}"
ci_job.enqueue(@github, { title: ci_job.name, summary: "Details at [#{url}](#{url})" })
else
ci_job.create_check_run
Expand Down Expand Up @@ -156,7 +156,7 @@ def create_stage(stage_config)
status: 'queued',
name: name)

url = "https://ci1.netdef.org/browse/#{stage.check_suite.bamboo_ci_ref}"
url = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{stage.check_suite.bamboo_ci_ref}"
output = { title: "#{stage.name} summary", summary: "Uninitialized stage\nDetails at [#{url}](#{url})" }

stage.enqueue(@github, output: output)
Expand All @@ -172,7 +172,7 @@ def create_stage(stage_config)
# @return [Hash] The initial output.
def initial_output(ci_job)
output = { title: '', summary: '' }
url = "https://ci1.netdef.org/browse/#{ci_job.check_suite.bamboo_ci_ref}"
url = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{ci_job.check_suite.bamboo_ci_ref}"

output[:title] = "#{ci_job.name} summary"
output[:summary] = "Details at [#{url}](#{url})"
Expand Down
2 changes: 1 addition & 1 deletion lib/github/build/retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def enqueued_stages
next if stage.nil?
next if stage.success?

url = "https://ci1.netdef.org/browse/#{stage.check_suite.bamboo_ci_ref}"
url = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{stage.check_suite.bamboo_ci_ref}"
output = { title: "#{stage.name} summary", summary: "Uninitialized stage\nDetails at [#{url}](#{url})" }

stage.enqueue(@github, output: output)
Expand Down
14 changes: 7 additions & 7 deletions lib/github/build/summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def must_continue_next_stage(current_stage)
end

def cancelling_next_stage(pending_stage)
url = "https://ci1.netdef.org/browse/#{pending_stage.check_suite.bamboo_ci_ref}"
url = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{pending_stage.check_suite.bamboo_ci_ref}"
output = {
title:
"#{pending_stage.name} summary",
Expand All @@ -122,7 +122,7 @@ def finished_summary(stage)
end

def finished_stage_summary(stage)
url = "https://ci1.netdef.org/browse/#{stage.check_suite.bamboo_ci_ref}"
url = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{stage.check_suite.bamboo_ci_ref}"
output = {
title: "#{stage.name} summary",
summary: "#{summary_basic_output(stage)}\nDetails at [#{url}](#{url}).".force_encoding('utf-8')
Expand All @@ -146,7 +146,7 @@ def finished_stage_update(stage, output)
end

def update_summary(stage)
url = "https://ci1.netdef.org/browse/#{@check_suite.bamboo_ci_ref}"
url = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{@check_suite.bamboo_ci_ref}"
output = {
title: "#{stage.name} summary",
summary: "#{summary_basic_output(stage)}\nDetails at [#{url}](#{url}).".force_encoding('utf-8')
Expand Down Expand Up @@ -196,7 +196,7 @@ def in_progress_message(jobs)
message = "\n\n:arrow_right: Jobs in progress: #{in_progress.size}/#{jobs.size}\n\n"

message + jobs.where(status: %i[in_progress]).map do |job|
"- **#{job.name}** -> https://ci1.netdef.org/browse/#{job.job_ref}\n"
"- **#{job.name}** -> https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{job.job_ref}\n"
end.join("\n")
end

Expand All @@ -206,13 +206,13 @@ def queued_message(jobs)
message = ":arrow_right: Jobs queued: #{queued.size}/#{jobs.size}\n\n"
message +
queued.map do |job|
"- **#{job.name}** -> https://ci1.netdef.org/browse/#{job.job_ref}\n"
"- **#{job.name}** -> https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{job.job_ref}\n"
end.join("\n")
end

def success_message(jobs)
jobs.where(status: :success).map do |job|
"- **#{job.name}** -> https://ci1.netdef.org/browse/#{job.job_ref}\n"
"- **#{job.name}** -> https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{job.job_ref}\n"
end.join("\n")
end

Expand All @@ -227,7 +227,7 @@ def generate_message(name, job)
failures = build_message(job) if name.downcase.match?('build')
failures = checkout_message(job) if name.downcase.match?('source')

"- #{job.name} -> https://ci1.netdef.org/browse/#{job.job_ref}\n#{failures}"
"- #{job.name} -> https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{job.job_ref}\n#{failures}"
end

def tests_message(job)
Expand Down
10 changes: 7 additions & 3 deletions lib/github/plan_execution/finished.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ class Finished
#
# @param [Hash] payload The payload containing information about the CheckSuite.
def initialize(payload)
@check_suite = CheckSuite.find_by(bamboo_ci_ref: payload['bamboo_ref']) if payload['bamboo_ref']
@check_suite = CheckSuite.find(payload['check_suite_id']) if payload['check_suite_id']
@check_suite = CheckSuite.where(
bamboo_ci_ref: payload['bamboo_ref']
).or(
CheckSuite.where(id: payload['check_suite_id'])
).last

@logger = GithubLogger.instance.create('github_plan_execution_finished.log', Logger::INFO)
@hanged = payload['hanged'] || false
end
Expand Down Expand Up @@ -180,7 +184,7 @@ def update_ci_job_status(github_check, ci_job, state)
# @param [CiJob] ci_job The CI job to create the message for.
# @return [Hash] The output message.
def create_output_message(ci_job)
url = "https://ci1.netdef.org/browse/#{ci_job.job_ref}"
url = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{ci_job.job_ref}"

{
title: ci_job.name,
Expand Down
6 changes: 6 additions & 0 deletions lib/helpers/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def debug?
config.key? 'debug' and config['debug']
end

def ci_url
return @config['ci']['url'] if @config.key?('ci') && @config['ci'].key?('url')

'https://ci1.netdef.org'
end

private

def configuration
Expand Down
13 changes: 9 additions & 4 deletions lib/models/stage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,19 @@ def github_stage_full_name(name)
end

def output_in_progress
url = GitHubApp::Configuration.instance.ci_url
in_progress = jobs.where(status: :in_progress)

header = ":arrow_right: Jobs in progress: #{in_progress.size}/#{jobs.size}\n\n"
in_progress_jobs = jobs.where(status: :in_progress).map do |job|
"- **#{job.name}** -> https://ci1.netdef.org/browse/#{job.job_ref}\n"
end.join("\n")
in_progress_jobs = mount_in_progress_jobs(jobs)

url = "https://ci1.netdef.org/browse/#{check_suite.bamboo_ci_ref}"
url = "https://#{url}/browse/#{check_suite.bamboo_ci_ref}"
{ title: "#{name} summary", summary: "#{header}#{in_progress_jobs}\nDetails at [#{url}](#{url})" }
end

def mount_in_progress_jobs(jobs)
jobs.where(status: :in_progress).map do |job|
"- **#{job.name}** -> https://#{url}/browse/#{job.job_ref}\n"
end.join("\n")
end
end
6 changes: 3 additions & 3 deletions lib/slack_bot/slack_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def send_stage_notification(stage, pull_request, subscription)
url = "#{GitHubApp::Configuration.instance.config['slack_bot_url']}/github/user"

pr_url = "https://github.com/#{pull_request.repository}/pull/#{pull_request.github_pr_id}"
bamboo_link = "https://ci1.netdef.org/browse/#{stage.check_suite.bamboo_ci_ref}"
bamboo_link = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{stage.check_suite.bamboo_ci_ref}"

post_request(URI(url),
machine: 'slack_bot.netdef.org',
Expand Down Expand Up @@ -197,15 +197,15 @@ def pull_request_message(check_suite, status)
pr = check_suite.pull_request

pr_url = "https://github.com/#{pr.repository}/pull/#{pr.github_pr_id}"
bamboo_link = "https://ci1.netdef.org/browse/#{check_suite.bamboo_ci_ref}"
bamboo_link = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{check_suite.bamboo_ci_ref}"

"PR <#{pr_url}|##{pr.github_pr_id}>. <#{bamboo_link}|#{status}> "
end

def generate_notification_message(job, status)
pr = job.check_suite.pull_request
pr_url = "https://github.com/#{pr.repository}/pull/#{pr.github_pr_id}/checks?check_run_id=#{job.check_ref}"
bamboo_link = "https://ci1.netdef.org/browse/#{job.job_ref}"
bamboo_link = "https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{job.job_ref}"

"PR <#{pr_url}|##{pr.github_pr_id}>. <#{bamboo_link}|#{job.name} - #{status}> "
end
Expand Down
115 changes: 115 additions & 0 deletions rbenv-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
- name: Install RbEnv and Ruby build dependencies
hosts: all
become: yes

vars:
rbenv_packages:
- git
- curl
- build-essential
- libssl-dev
- zlib1g-dev
- libpq-dev
- rbenv
- libffi-dev
- libyaml-dev
- autoconf
- bison

tasks:
- name: Update apt cache
apt:
update_cache: yes

- name: Install required packages for rbenv and Ruby
apt:
name: "{{ rbenv_packages }}"
state: present
install_recommends: yes

- name: Ensure rbenv is initialized in .bashrc
lineinfile:
path: ~/.bashrc
line: 'eval "$(rbenv init -)"'
state: present
insertafter: EOF
become: no

- name: Install rbenv using git
git:
repo: 'https://github.com/rbenv/rbenv.git'
dest: ~/.rbenv
update: no
become: no

- name: Add rbenv to PATH
lineinfile:
path: ~/.bashrc
line: 'export PATH="$HOME/.rbenv/bin:$PATH"'
state: present
insertafter: EOF
become: no

- name: Install ruby-build as rbenv plugin
git:
repo: 'https://github.com/rbenv/ruby-build.git'
dest: ~/.rbenv/plugins/ruby-build
update: no
become: no

- name: Ensure rbenv is initialized in .bashrc
lineinfile:
path: ~/.bashrc
line: 'eval "$(rbenv init -)"'
state: present
insertafter: EOF
become: no

- name: Reload shell to use rbenv
shell: |
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
args:
executable: /bin/bash
become: no

- name: Install Ruby 3.1.2
shell: |
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
rbenv install -s 3.1.2
args:
creates: ~/.rbenv/versions/3.1.2
executable: /bin/bash
become: no

- name: Set Ruby 3.1.2 as local version
shell: |
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
rbenv local 3.1.2
args:
chdir: "{{ ansible_env.PWD }}"
executable: /bin/bash
become: no

- name: Install bundler gem
shell: |
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
gem install bundler
rbenv rehash
args:
executable: /bin/bash
become: no

- name: Run bundle install
shell: |
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
bundle install
args:
chdir: "{{ ansible_env.PWD }}"
executable: /bin/bash
become: no
2 changes: 1 addition & 1 deletion reports/build_stage_failed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
.where(jobs: { created_at: [begin_date..end_date], status: %i[failure skipped] })
.where(check_suites: { author: author })
.each do |stage|
message = "Check Suite ID: https://ci1.netdef.org/browse/#{stage.check_suite.bamboo_ci_ref}"
message = "Check Suite ID: https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{stage.check_suite.bamboo_ci_ref}"
check_suites << message unless check_suites.include? message
end

Expand Down
2 changes: 1 addition & 1 deletion reports/github_user_usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
else
puts "Check Suites for user: #{user.github_login}"
user.check_suites.each do |cs|
puts "Check Suite: https://ci1.netdef.org/browse/#{cs.bamboo_ci_ref}"
puts "Check Suite: https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{cs.bamboo_ci_ref}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/github/build/summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@
create(:ci_job, :success, stage: stage, check_suite: check_suite, name: 'Sourcecode', summary: 'HI')
end
let(:message) do
"Sourcecode -> https://ci1.netdef.org/browse/#{ci_job.job_ref}\n```\nHI\n```"
"Sourcecode -> https://#{GitHubApp::Configuration.instance.ci_url}/browse/#{ci_job.job_ref}\n```\nHI\n```"
end

it 'must update stage' do
Expand Down
Loading