Skip to content

Commit

Permalink
Nightly release pipeline for Ansible (#1330)
Browse files Browse the repository at this point in the history
Merged PR #1330.
  • Loading branch information
rambleraptor authored and modular-magician committed Feb 12, 2019
1 parent d32f620 commit 2c10204
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 274 deletions.
9 changes: 9 additions & 0 deletions .ci/magic-modules/release-ansible.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e
set -x

pushd "magic-modules-gcp/build/ansible"
git remote add origin git@github.com:modular-magician/ansible.git

../../tools/ansible-pr/run.sh
19 changes: 19 additions & 0 deletions .ci/magic-modules/release-ansible.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# This file takes one input: magic-modules-branched in detached-HEAD state
# It will create a series of PRs on Ansible.
platform: linux

image_resource:
type: docker-image
source:
repository: gcr.io/magic-modules/go-ruby-python
tag: '1.11.5-2.6.0-2.7'

inputs:
- name: magic-modules-gcp

run:
path: "magic-modules-gcp/.ci/magic-modules/release-ansible.sh"

params:
GITHUB_TOKEN: ""
9 changes: 9 additions & 0 deletions .ci/release.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ resources:
private_key: ((repo-key.private_key))

jobs:
- name: ansible-nightly-release
plan:
- get: night-trigger
trigger: true
- get: magic-modules-gcp
- task: build
file: magic-modules-gcp/.ci/magic-modules/release-ansible.yml
params:
GITHUB_TOKEN: ((github-account.password))
- name: nightly-build
plan:
- get: night-trigger
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ group :test do
gem 'rspec'
gem 'rubocop', '~> 0.63.1'
end

group :pr_script do
gem 'octokit'
end
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,33 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.0)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
concurrent-ruby (1.0.5)
debug_inspector (0.0.3)
diff-lcs (1.3)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
i18n (1.1.1)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.2)
metaclass (0.0.4)
minitest (5.11.3)
mocha (1.3.0)
metaclass (~> 0.0.1)
multipart-post (2.0.0)
octokit (4.13.0)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.12.1)
parallel_tests (2.23.0)
parallel
parser (2.6.0.0)
ast (~> 2.4.0)
powerpack (0.1.2)
public_suffix (3.0.3)
rainbow (3.0.0)
rake (12.3.1)
rspec (3.8.0)
Expand All @@ -49,6 +57,9 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
ruby-progressbar (1.10.0)
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
Expand All @@ -61,6 +72,7 @@ DEPENDENCIES
activesupport
binding_of_caller
mocha (~> 1.3.0)
octokit
parallel_tests
rake
rspec
Expand Down
2 changes: 1 addition & 1 deletion build/terraform
4 changes: 2 additions & 2 deletions tools/ansible-pr/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ansible PR Script
This is a Ruby script that creates a series of PRs from the `build/ansible`
folder to ansible/ansible.
This is a Bash script that creates a series of PRs from the `build/ansible`
folder to ansible/ansible upstream repo.

Pull Requests are made from the origin remote to Ansible core.
By default, the origin remote points to MM's version of Ansible
Expand Down
103 changes: 103 additions & 0 deletions tools/ansible-pr/generate_template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env ruby
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'optparse'
require_relative '../../compile/core'
require 'octokit'
require 'time'

# Class to handle Compile include to avoid Rubocop issues.
class CompileClass
include Compile::Core
end

@options = {
directory: "#{Dir.pwd}/build/ansible/",
dry_run: false,
# Get all PRs from one day ago.
date: (Time.now - (3600 * 24)).iso8601
}

TEMPLATE = "
<%= ctx[:commit_msg] %>
##### SUMMARY
<%= ctx[:commit_msg] %>
<% if ctx[:prs] && !ctx[:prs].empty?-%>
This PR is the result of the following Magic Modules PRs:
<% ctx[:prs].each do |pr| -%>
- [<%= pr[:title] -%>](<%= pr[:url] -%>)
<% end -%>
<% end -%>
##### ISSUE TYPE
<% if ctx[:new] -%>
- New Module Pull Request
<% else -%>
- Bugfix Pull Request
<% end -%>
##### ADDITIONAL INFORMATION
```
This was generated by [Magic Modules](https://github.com/googlecloudplatform/magic-modules)
```
".freeze

@options = {
new: false,
mod_name: '',
date: (Time.now - (3600 * 24)).iso8601,
creds: nil
}

def all_pr_messages
# Limit of 50 bug fixes will go into a PR (should never hit this limit)
client = Octokit::Client.new(access_token: @options[:creds], per_page: 50)
client.list_issues('googlecloudplatform/magic-modules',
labels: 'ansible,downstream-generated',
state: 'closed', since: @options[:date].strip)
.map { |pr| { title: pr[:title], url: pr[:html_url] } }
end

OptionParser.new do |opts|
opts.banner = 'Usage: run [options]'

opts.on('--new-module-name [NAME]') do |v|
@options[:new] = true
@options[:mod_name] = v
end

opts.on('--date [DATE (as ISO8601 String)]',
'Find all GitHub issues with Ansible label after this date') do |v|
@options[:date] = v
end

opts.on('--github-creds [CREDS]', 'Github creds') do |v|
@options[:creds] = v
end
end.parse!

message = if @options[:new]
"New GCP module: #{@options[:mod_name]}"
else
"Bug fixes for GCP (as of #{@options[:date]})"
end

puts CompileClass.new.lines(
CompileClass.new.compile_string({
commit_msg: message,
new: @options[:new],
prs: all_pr_messages
}, TEMPLATE)
)
Loading

0 comments on commit 2c10204

Please sign in to comment.