Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease reusability of the template #180

Merged
merged 3 commits into from
Dec 16, 2019
Merged

Conversation

dafyddj
Copy link
Contributor

@dafyddj dafyddj commented Nov 22, 2019

PR progress checklist (to be filled in by reviewers)

  • Changes to documentation are appropriate (or tick if not required)
  • Changes to tests are appropriate (or tick if not required)
  • Reviews completed

What type of PR is this?

Primary type

  • [build] Changes related to the build system
  • [chore] Changes to the build process or auxiliary tools and libraries such as documentation generation
  • [ci] Changes to the continuous integration configuration
  • [feat] A new feature
  • [fix] A bug fix
  • [perf] A code change that improves performance
  • [refactor] A code change that neither fixes a bug nor adds a feature
  • [revert] A change used to revert a previous commit
  • [style] Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)

Secondary type

  • [docs] Documentation changes
  • [test] Adding missing or correcting existing tests

Does this PR introduce a BREAKING CHANGE?

Yes.
All state names and state ids are changed to the new unique token.

Related issues and/or pull requests

#98 slightly

Describe the changes you're proposing

While creating my first formula using this template, I found it wasn't as straightforward as I'd hoped.
Obviously the word template is used all over this formula and some need changing and some don't.

This is just an idea I had of uniquely marking out the replaceable template by using the token template__ - of course, it could be something else too.

Then a simple global replace can be performed while converting the template to a real formula.

Thoughts before I continue further?

Pillar / config required to test the proposed changes

Debug log showing how the proposed changes work

Documentation checklist

  • Updated the README (e.g. Available states).
  • Updated pillar.example.

Testing checklist

  • Included in Kitchen (i.e. under state_top).
  • Covered by new/existing tests (e.g. InSpec, Serverspec, etc.).
  • Updated the relevant test pillar.

Additional context

@dafyddj dafyddj requested a review from myii November 22, 2019 23:37
@myii
Copy link
Member

myii commented Nov 23, 2019

Thanks for starting this PR, @dafyddj. It's an interesting take on things, definitely worth a discussion. I'd like to start by pulling in other contributors who have experience with conversions using the template-formula (based on previous discussions). Hopefully, we can formulate an effective solution to make this process as efficient as possible.

CC: @saltstack-formulas/wg @xenophonf @GMAzrael.

Some alternatives to compare against:

  1. Provide a script to convert this formula according to cookiecutter-style input after cloning.
  2. Prepare detailed documentation to perform the conversion after cloning.
  3. Have a separate repo that's effectively a "pure" template (not numerous things mixed together, as we have in this repo).

@myii
Copy link
Member

myii commented Nov 25, 2019

@dafyddj Thanks for the ongoing effort here, this will definitely be useful in resolving this problem. I hope others can share their opinions, so that we select the best approach going forwards.

@daks
Copy link
Member

daks commented Nov 26, 2019

I think that in the middle/long term it should be nice to have a tool/script to generate a formula from scratch like other config management tools have. Maybe cookiecutter can be used for it but I don't really know it so I can't judge if it'll work for our needs.
And maybe we already have a certain stability in this formula to work on it already.

In the meantime (until someone take this job or we consider this a priority, maybe we already should?) manual generation (like documented in my PR) can be nice, and if this PR help it, I'm ok with it.

@myii
Copy link
Member

myii commented Nov 26, 2019

@dafyddj The script looks great, this is really taking shape. Some comments:

@myii
Copy link
Member

myii commented Nov 27, 2019

@dafyddj I've started #181, with the plan to propagate using shellcheck to all of the formulas. Ignores are simple enough where required.

@dafyddj dafyddj force-pushed the reusability branch 2 times, most recently from 8ea358a to 42f5fa4 Compare November 27, 2019 20:44
myii pushed a commit to myii/ssf-formula that referenced this pull request Nov 27, 2019
# [1.63.0](v1.62.0...v1.63.0) (2019-11-27)

### Code Refactoring

* **travis:** use pathspecs for `git ls-files` instead of `grep` ([615e3b2](615e3b2)), closes [/github.com/saltstack-formulas/template-formula/pull/181#discussion_r351421463](https://github.com//github.com/saltstack-formulas/template-formula/pull/181/issues/discussion_r351421463)

### Features

* **shellcheck:** apply fixes throughout this repo ([1ea7fbb](1ea7fbb))
* **travis:** run `shellcheck` during lint job ([f52eb37](f52eb37)), closes [/github.com/saltstack-formulas/template-formula/pull/180#issuecomment-558612422](https://github.com//github.com/saltstack-formulas/template-formula/pull/180/issues/issuecomment-558612422)
bin/convert-formula.sh Outdated Show resolved Hide resolved
@dafyddj dafyddj force-pushed the reusability branch 2 times, most recently from b907232 to 703750f Compare November 30, 2019 19:46
@myii
Copy link
Member

myii commented Dec 2, 2019

@dafyddj Thanks for moving over to sh (and for ex!). A quick question, not prescriptive: what are your thoughts on using uppercase TEMPLATE instead of template__? I haven't thought this through but it just occurred to me, so I thought I'd ask.

@dafyddj
Copy link
Contributor Author

dafyddj commented Dec 2, 2019

I'm not particularly attached to template__ and I think TEMPLATE could work because the search/replace is case-sensitive. Would we ever have a legitimate need to use TEMPLATE in the formula? Probably not.

Also, do you agree that this conversion process should be CI tested? I'm thinking, in Travis, clone the repo, run the script, then run at least one of the test suites in that cloned repo. Thoughts?

@myii
Copy link
Member

myii commented Dec 2, 2019

Also, do you agree that this conversion process should be CI tested? I'm thinking, in Travis, clone the repo, run the script, then run at least one of the test suites in that cloned repo. Thoughts?

@dafyddj Definitely useful and worthwhile. A single job would be enough to test that.

@dafyddj
Copy link
Contributor Author

dafyddj commented Dec 5, 2019

@myii this is mostly done as far as I'm concerned.

It could probably do with some documentation. Can you suggest where best to place the docs - and should the script remove that part of the documentation when it's done?

@myii
Copy link
Member

myii commented Dec 5, 2019

@myii this is mostly done as far as I'm concerned.

Great, I'm going to take this for a test drive soon, since I need to make a formula or two. That will help me finalise the review.

It could probably do with some documentation. Can you suggest where best to place the docs - and should the script remove that part of the documentation when it's done?

The README is a good place. A couple of places to consider:

Since the end-user is going to be editing the README for their own purposes, I don't think the script needs to remove this. I'll confirm this after my tests.

Comment on lines +45 to +48
git commit --quiet --all \
--message 'feat: convert `template-formula` to `'"${NEW_NAME}"'-formula`

BREAKING CHANGE: changed all state names and ids'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

  git commit --quiet --all \
    --message 'feat: convert `template-formula` to `'"${NEW_NAME}"'-formula`' \
    --message 'BREAKING CHANGE: changed all state names and ids'

git rm --quiet bin/convert-formula.sh AUTHORS.md CHANGELOG.md
git mv TEMPLATE "${NEW_NAME}"
grep --recursive --files-with-matches --exclude-dir=.git TEMPLATE . \
| xargs -L 1 ex -sc '%s/TEMPLATE/'"${NEW_NAME}"'/g|x'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my first local tests, the script doesn't get past this line. Since this is working in Travis, there's probably something in the way I've patched things together. The only way past it is to comment out line 3, i.e.:

# set -o errexit # If a command fails exit the whole script

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might get some clues by running as (if you haven't already done so):
DEBUG=true bin/convert-formula.sh ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I started with that and then tried all sorts, including removing all of the quiet or silent flags but to no avail. Even when I get it running with this line commented out, there are no warning given. Not sure what's happening with that ex command to cause an error status...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dafyddj This sounds a little strange but I found a solution (using -u NONE) based on this reference:

So that's:

  grep --recursive --files-with-matches --exclude-dir=.git TEMPLATE . \
    | xargs -L 1 ex -u NONE -sc '%s/TEMPLATE/'"${NEW_NAME}"'/g|x'
  • This actually worked, with set -o errexit re-enabled.
  • Maybe the end user (like me) could have something strange in their configuration, affecting ex when it exits?

git reset \
"$(echo 'feat: initial commit' \
| git commit-tree 'HEAD^{tree}')"
git rm --quiet bin/convert-formula.sh AUTHORS.md CHANGELOG.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
git rm --quiet bin/convert-formula.sh AUTHORS.md CHANGELOG.md
git rm --quiet bin/convert-formula.sh AUTHORS.md CHANGELOG.md \
docs/_static/css/custom.css docs/AUTHORS.rst docs/CHANGELOG.rst \
docs/conf.py docs/CONTRIBUTING_DOCS.rst docs/index.rst

@myii
Copy link
Member

myii commented Dec 13, 2019

Current status:

  1. Discuss and finalise changes as suggested above.
  2. Add notes to the README, including explaining that git push -f needs to be used and perhaps how to configure Travis to enable semantic-release (e.g. GH_TOKEN, etc.).

A wish-list collection for the long-run, doesn't prevent merging this PR:

  1. README: Update the headings symbols to match the length of the heading itself.
  2. .rubocop.yml: Remove the Metrics/BlockLength section, specific to the template-formula.
  3. .travis.yml: Remove the env: 'Conversion' block.
  4. FORMULA: reset the version to 1.0.0.

@myii myii merged commit 7ad85ae into saltstack-formulas:master Dec 16, 2019
@myii myii changed the title WIP: Ease reusability of the template Ease reusability of the template Dec 16, 2019
@myii
Copy link
Member

myii commented Dec 16, 2019

@dafyddj Merged, the rest of the issues can be covered in a future PR. Thanks for this fantastic PR.

@saltstack-formulas-travis

🎉 This PR is included in version 4.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@dafyddj dafyddj deleted the reusability branch December 17, 2019 14:41
myii added a commit that referenced this pull request Dec 17, 2019
fix(convert-formula.sh): apply remaining suggestions from #180
@dafyddj dafyddj mentioned this pull request Dec 19, 2019
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants