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

Commit

Permalink
build(COOKIECUTTER): tooling to update existing roles
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed May 22, 2021
1 parent 5d0db24 commit 8cfd0bf
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/self-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ jobs:

- name: Shellcheck -- Shellcheck Scripts
run: |
shellcheck ./template/hooks/*.sh
shellcheck ./template/scripts/*.sh
shellcheck ./template/.github/scripts/*.sh
- name: Shellcheck -- Shellcheck Rendered Scripts
run: |
Expand Down
39 changes: 31 additions & 8 deletions hooks/post_gen_project.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
#!/bin/bash

git init
git checkout -b master
git stage .
git commit -m "build(Cookiecutter): Initial Generation"
git symbolic-ref HEAD refs/heads/master
git tag v0.0.0
mkdir -p files templates
poetry install
initialize_git() {
git init
git checkout -b master
git stage .
git commit -m "build(COOKIECUTTER): initial generation"
git symbolic-ref HEAD refs/heads/master
git tag v0.0.0
git checkout -b production
git checkout master
mkdir -p files templates
}

initialize_poetry() {
if [[ -z "$(poetry env list)" ]]; then
poetry install
fi
}

update_template_values() {
# Compatible with Linux and BSD sed
sed -i.bak 's/ansible-workbench\//https:\/\/github.com\/Shared-Vision-Solutions\/ansible-workbench.git/' .cookiecutter/cookiecutter.json
rm .cookiecutter/cookiecutter.json.bak
}

main() {
update_template_values
initialize_git
initialize_poetry
}

main
45 changes: 45 additions & 0 deletions scripts/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# This script helps automate the process of updating a role that has already been created.
# A branch "update-template" is created, with the changes required to update the workflow.
# Use git cherry-pick (or create a patch from this change set) to update your ansible role.

# Requires: https://pypi.org/project/cookiecutter-project-upgrader/

error() {
echo "USAGE: ./update.sh [ROLE FOLDER] [TEMPLATE TAG or BRANCH]"
exit 127
}

[[ -z $2 ]] && error
[[ -z $1 ]] && error

main() {

pushd "$1" || error
cookiecutter_project_upgrader \
-c .cookiecutter/cookiecutter.json \
-b "update-template" \
-u "$2" \
-f https://github.com/shared-vision-solutions/ansible-workbench.git \
-e "defaults" \
-e "handlers" \
-e "meta" \
-e "molecule" \
-e "tasks" \
-e "tests" \
-e "vars" \
-e ".ansible-lint" \
-e ".gitignore" \
-e "pyproject.toml" \
-e "requirements.yml" \
-e ".travis.yml" \
-e "LICENSE" \
-e "README.md"

git checkout update-template
popd || true

}

main "$@"

0 comments on commit 8cfd0bf

Please sign in to comment.