Skip to content

Commit

Permalink
moving release script to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
rambleraptor committed Feb 20, 2019
1 parent 5b65a3c commit 3aa3758
Showing 1 changed file with 109 additions and 1 deletion.
110 changes: 109 additions & 1 deletion .ci/magic-modules/release-ansible.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
#!/usr/bin/env bash

set -x
# Constants + functions
declare -a ignored_modules=(
gcp_backend_service
gcp_forwarding_rule
gcp_healthcheck
gcp_target_proxy
gcp_url_map
)

get_all_modules() {
remote_name=$1
file_name=$remote_name
git fetch $remote_name
ssh-agent bash -c "ssh-add ~/github_private_key; git fetch $remote_name"
git checkout $remote_name/devel
git ls-files -- lib/ansible/modules/cloud/google/gcp_* | cut -d/ -f 6 | cut -d. -f 1 > $file_name

for i in "${ignored_modules[@]}"; do
sed -i "/$i/d" $file_name
done
}

# Install dependencies for Template Generator
pushd "magic-modules-new-prs"
Expand All @@ -15,7 +36,6 @@ set +x
echo "$CREDS" > ~/github_private_key
set -x
chmod 400 ~/github_private_key

ssh-agent bash -c "ssh-add ~/github_private_key; git submodule update --remote --init build/ansible"
popd

Expand All @@ -26,3 +46,91 @@ git config --global user.name "Modular Magician"

# Run creation script.
ssh-agent bash -c "ssh-add ~/github_private_key; ../../tools/ansible-pr/run.sh"

if ! which hub; then
echo "Please install the hub CLI"
exit 1
fi

if ! git remote -v | grep "origin"; then
echo "Please set the origin remote"
exit 1
fi

set -e

git remote add upstream git@github.com:ansible/ansible.git

# Use HTTPS endpoint so we don't have to setup SSH keys.
git remote add magician git@github.com:modular-magician/ansible.git
ssh-agent bash -c "ssh-add ~/github_private_key; git fetch magician devel"
ssh-agent bash -c "ssh-add ~/github_private_key; git fetch upstream devel"
echo "Remotes setup properly"

# Create files with list of modules in a given branch.
get_all_modules "upstream"
get_all_modules "magician"

# Split existing modules into sets of 23
# Max 50 files per PR and a module can have 2 files (module + test)
# 23 = 50/2 - 2 (to account for module_util files)
split -l 23 upstream mm-bug

for filename in mm-bug*; do
echo "Building a Bug Fix PR for $filename"
# Checkout all files that file specifies and create a commit.
git checkout upstream/devel
git checkout -b bug_fixes$filename


while read p; do
git checkout magician/devel -- "lib/ansible/modules/cloud/google/$p.py"
if [[ $p != *"facts"* ]]; then
git checkout magician/devel -- "test/integration/targets/$p"
fi
done < $filename

git checkout magician/devel -- "lib/ansible/module_utils/gcp_utils.py"

# This commit may be empty
set +e
git commit -m "Bug fixes for GCP modules"

# Create a PR message + save to file
ruby ../../tools/ansible-pr/generate_template.rb > bug_fixes$filename

# Create PR
git push origin HEAD --force
hub pull-request -b ansible/ansible:devel -F bug_fixes$filename
set -e

echo "Bug Fix PR built for $filename"
done

## Get list of new modules (in magician, not in upstream)
comm -3 <(sort magician) <(sort upstream) > new_modules

while read module; do
echo "Building a New Module PR for $module"
git checkout upstream/devel
git checkout -b $module

git checkout magician/devel -- "lib/ansible/modules/cloud/google/$module.py"
if [[ $module != *"facts"* ]]; then
git checkout magician/devel -- "test/integration/targets/$module"
fi

git checkout magician/devel -- "lib/ansible/module_utils/gcp_utils.py"

# Create a PR message + save to file
set +e
git commit -m "New Module: $module"
ruby ../../tools/ansible-pr/generate_template.rb --new-module-name $module > bug_fixes$filename

# Create PR
git push origin HEAD --force
hub pull-request -b ansible/ansible:devel -F bug_fixes$filename
set -e

echo "New Module PR built for $module"
done < new_modules

0 comments on commit 3aa3758

Please sign in to comment.