Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Use the hub CLI instead of PR outs. (GoogleCloudPlatform#3)
Browse files Browse the repository at this point in the history
PR resource maintainer doesn't want to add 'create' to the PRs, so
we'll need to manage them ourselves.  It's okay - doesn't really
reduce usability, and the hub CLI only requires the token (which
is already present in the config).
  • Loading branch information
nat-henderson authored Mar 5, 2018
1 parent 727ae63 commit 6fb011c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 109 deletions.
43 changes: 14 additions & 29 deletions ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,6 @@ resources:
only_mergeable: true
require_review_approval: true

- name: mm-prs-out
type: github-pull-request
source:
repo: ((username))/magic-modules
private_key: ((repo_key))
access_token: ((repo_access))

- name: terraform-prs-out
type: github-pull-request
source:
repo: ((username))/terraform-provider-google
private_key: ((repo_key))
access_token: ((repo_access))

jobs:
- name: mm-generate
plan:
Expand Down Expand Up @@ -116,31 +102,30 @@ jobs:
params:
submodules: [build/terraform]
passed: [terraform-test, mm-generate]
# TODO(@ndmckinley): This get/task/put/task/put flow is confusing and should be cleaned up.
- get: mm-initial-pr
resource: magic-modules-new-prs
passed: [mm-generate]
version: every
- task: make-pr
file: ci/magic-modules/make-pr.yml
- task: create-pr
file: ci/magic-modules/create-pr.yml
params:
GITHUB_TOKEN: ((repo_access))
TERRAFORM_REPO: ((username))/terraform-provider-google
on_failure:
put: magic-modules-new-prs
params:
status: failure
path: mm-initial-pr
- put: magic-modules
params:
branch_file: mm-initial-pr/.git/branch
repository: magic-modules-out
repository: magic-modules
only_if_diff: true
- put: terraform-prs-out
params:
path: magic-modules-out/build/terraform
status: success
- task: make-comment
file: ci/magic-modules/make-comment.yml
params:
GH_USERNAME: ((username))
- put: mm-prs-out
- put: magic-modules-new-prs
params:
status: success
path: magic-modules-comment
comment: magic-modules-comment/pr_comment
path: mm-initial-pr
comment: magic-modules-with-comment/pr_comment

- name: merge-prs
plan:
Expand Down
5 changes: 5 additions & 0 deletions containers/hub/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from nmckinley/go-ruby:1.9-2.5

RUN apt-get update
RUN apt-get install -y ca-certificates
RUN go get github.com/github/hub
31 changes: 24 additions & 7 deletions magic-modules/create-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,32 @@ set -e
set -x

shopt -s dotglob
cp -r magic-modules/* magic-modules-out
cp -r magic-modules/* magic-modules-with-comment

cd magic-modules-out
pushd magic-modules-with-comment

# This says "check out the branch which contains HEAD, and set it up to track its upstream."
git checkout -t "$(git branch -a --contains "$(git rev-parse HEAD)" | grep -v "detached")"
# The 'checkout' command tells us to checkout the branch, the '-t' says "which tracks".
# This 'git branch -a --contains' command lists all branches which contain the SHA provided
# by 'git rev-parse HEAD' (which returns the rev at HEAD). Then we remove the 'detached'
# branch which we're currently on, collapse whitespace, and check it out.
# This will resolve to something like 'git checkout -t remotes/origin/abcdef12'
git checkout -t "$(git branch -a --contains "$(git rev-parse HEAD)" | grep -v "detached" | xargs echo -n)"

cd build/terraform
pushd build/terraform

git checkout -t "$(git branch -a --contains "$(git rev-parse HEAD)" | grep -v "detached")"
# This special string 'new' tells the PR resource to create a new PR.
git config pullrequest.id new
cat << EOF > ./downstream_body
$(git log -1 --pretty=%B)
<!-- This change is generated by MagicModules. -->
EOF
git checkout -t "$(git branch -a --contains "$(git rev-parse HEAD)" | grep -v "detached" | xargs echo -n)"
TF_PR=$(hub pull-request -b "$TERRAFORM_REPO:master" -F ./downstream_body)
popd

cat << EOF > ./pr_comment
I am a robot that works on MagicModules PRs!
I built this PR into one or more PRs on other repositories, and when those are closed, this PR will also be merged and closed.
depends: $TF_PR
EOF
25 changes: 25 additions & 0 deletions magic-modules/create-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# This takes in the magic-modules repo in detached-HEAD state,
# creates a PR on downstream modules, and writes a comment into
# a file so that the PR can be updated with that comment.
platform: linux

image_resource:
type: docker-image
source:
repository: nmckinley/hub
tag: 'latest'

inputs:
- name: magic-modules
- name: ci

outputs:
- name: magic-modules-with-comment

run:
path: ci/magic-modules/create-pr.sh

params:
GITHUB_TOKEN: ""
TERRAFORM_REPO: ""
27 changes: 0 additions & 27 deletions magic-modules/make-comment.sh

This file was deleted.

25 changes: 0 additions & 25 deletions magic-modules/make-comment.yml

This file was deleted.

21 changes: 0 additions & 21 deletions magic-modules/make-pr.yml

This file was deleted.

0 comments on commit 6fb011c

Please sign in to comment.