mirror of
https://github.com/saltstack-formulas/template-formula.git
synced 2025-04-17 10:10:28 +00:00
Merge pull request #207 from dafyddj/fix/convert-dash-underscore
fix(convert-formulas.sh): add -_ to allowed chars in formula name
This commit is contained in:
commit
4be96d3618
6 changed files with 54 additions and 12 deletions
10
.travis.yml
10
.travis.yml
|
@ -139,9 +139,13 @@ jobs:
|
|||
- env: 'Conversion'
|
||||
name: 'Test: bin/convert-formula.sh'
|
||||
script:
|
||||
- git clone . tmp/converted-formula
|
||||
- cd tmp/converted-formula
|
||||
- DEBUG=true bin/convert-formula.sh converted
|
||||
- export CONVERTED=test-the-use_this_template-button
|
||||
- git clone . tmp/"$CONVERTED"-formula
|
||||
- cd tmp/"$CONVERTED"-formula
|
||||
- pyenv global 3.8
|
||||
- pip install pre-commit==2.7.1
|
||||
- bin/install-hooks
|
||||
- DEBUG=true bin/convert-formula.sh "$CONVERTED"
|
||||
- '[ $(git rev-list HEAD --count) -eq 2 ]'
|
||||
# Quick visual check that correct files have been updated
|
||||
- git show --pretty="" --name-status
|
||||
|
|
|
@ -46,7 +46,9 @@
|
|||
)
|
||||
%}
|
||||
|
||||
{#- <REMOVEME #}
|
||||
{#- Change **TEMPLATE** to match with your formula's name and then remove this line #}
|
||||
{#- REMOVEME> #}
|
||||
{%- set TEMPLATE = config %}
|
||||
|
||||
{#- Post-processing for specific non-YAML customisations #}
|
||||
|
|
|
@ -10,7 +10,8 @@ usage() {
|
|||
echo "usage: $(basename "$0") <new-formula-name>" 1>&2
|
||||
echo 1>&2
|
||||
echo "Convert template-formula to <new-formula-name>-formula." 1>&2
|
||||
echo "<new-formula-name> should be a string of lowercase characters and numbers only." 1>&2
|
||||
echo "<new-formula-name> should be a string of lowercase characters, numbers or '-',\
|
||||
'_' only." 1>&2
|
||||
echo "<new-formula-name> should not be any of 'bin' 'docs' 'test'." 1>&2
|
||||
}
|
||||
|
||||
|
@ -30,7 +31,8 @@ args() {
|
|||
exit 1
|
||||
fi
|
||||
NEW_NAME=$1
|
||||
if echo "$NEW_NAME" | grep -E --quiet --invert-match '^[a-z0-9]+$'; then
|
||||
NEW_NAME_PYSAFE=$(echo "$NEW_NAME" | sed 's/-/__/g')
|
||||
if echo "$NEW_NAME" | grep -E --quiet --invert-match '^[a-z0-9_-]+$'; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
@ -50,22 +52,51 @@ convert_formula() {
|
|||
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
|
||||
git mv TEMPLATE "${NEW_NAME}"
|
||||
tag_out=$(git tag --list | xargs git tag --delete)
|
||||
if [ "${DEBUG:-false}" = "true" ]; then
|
||||
echo "$tag_out"
|
||||
fi
|
||||
|
||||
git mv TEMPLATE "$NEW_NAME"
|
||||
|
||||
# Replace TEMPLATE within sls and jinja files with py-safe formula name
|
||||
# due to python limitations on identifier names (no hyphen)
|
||||
# including when specifying jinja context variables
|
||||
git ls-files -- '*.sls' '*.jinja' \
|
||||
| while read -r filename; do
|
||||
sedi "s/\({[{%#].*\)TEMPLATE/\1${NEW_NAME_PYSAFE}/" "$filename"
|
||||
sedi "s/\([[:space:]]\{1,\}\)TEMPLATE:/\1${NEW_NAME_PYSAFE}:/" "$filename"
|
||||
done
|
||||
|
||||
# Replace all other instances of TEMPLATE with the regular new formula name
|
||||
grep --recursive --files-with-matches --exclude-dir=.git TEMPLATE . \
|
||||
| while read -r filename; do
|
||||
sedi 's/TEMPLATE/'"${NEW_NAME}"'/g' "${filename}"
|
||||
done
|
||||
| while read -r filename; do
|
||||
sedi "s/TEMPLATE/${NEW_NAME}/g" "$filename"
|
||||
done
|
||||
|
||||
# Miscellaneous other replacements
|
||||
sedi 's/^\(version:\).*/\1 1.0.0/' FORMULA
|
||||
sedi 's/^\(*[[:space:]]\{1,\}\)@saltstack-formulas\/wg/\1@NONE/' CODEOWNERS
|
||||
|
||||
# Deleting lines between two patterns
|
||||
sedi '/<REMOVEME/,/REMOVEME>/d' .travis.yml .rubocop.yml
|
||||
git ls-files -- '.travis.yml' '.rubocop.yml' '*/map.jinja' \
|
||||
| while read -r filename; do
|
||||
sedi '/<REMOVEME/,/REMOVEME>/d' "$filename"
|
||||
done
|
||||
# shellcheck disable=SC1004 # This backslash+linefeed is literal (sed: replace text)
|
||||
sedi '/<REMOVEME/,/REMOVEME>/c \
|
||||
None
|
||||
' docs/README.rst
|
||||
|
||||
# Produce a commitlint-safe commit message (line length)
|
||||
if [ "${#NEW_NAME}" -gt 25 ]; then
|
||||
NEW_NAME_SHORT=$(echo "$NEW_NAME" | cut -c 1-23)'..'
|
||||
else
|
||||
NEW_NAME_SHORT="$NEW_NAME"
|
||||
fi
|
||||
# shellcheck disable=SC2016 # Expressions don't expand in single quotes
|
||||
git commit --quiet --all \
|
||||
--message 'feat: convert `template-formula` to `'"${NEW_NAME}"'-formula`' \
|
||||
--message 'feat: convert `template-formula` to `'"$NEW_NAME_SHORT"'-formula`' \
|
||||
--message 'BREAKING CHANGE: changed all state names and ids'
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ Special notes
|
|||
Using this template
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The easiest way to use this template formula as a base for a new formula is to use GitHub's **Use this template** button to create a new repository. For consistency with the rest of the formula ecosystem, name your formula repository following the pattern ``<formula theme>-formula``, where ``<formula theme>`` consists of lower-case alphabetic characters and numbers.
|
||||
The easiest way to use this template formula as a base for a new formula is to use GitHub's **Use this template** button to create a new repository. For consistency with the rest of the formula ecosystem, name your formula repository following the pattern ``<formula theme>-formula``, where ``<formula theme>`` consists of lower-case alphabetic characters, numbers, '-' or '_'.
|
||||
|
||||
In the rest of this example we'll use ``example`` as the ``<formula theme>``.
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ control 'TEMPLATE configuration' do
|
|||
its('content') { should include '"pkg": {"name": "' }
|
||||
its('content') { should include '"service": {"name": "' }
|
||||
its('content') do
|
||||
# rubocop:disable Lint/RedundantCopDisableDirective
|
||||
# rubocop:disable Layout/LineLength
|
||||
should include(
|
||||
'"tofs": {"files_switch": ["any/path/can/be/used/here", "id", '\
|
||||
'"roles", "osfinger", "os", "os_family"], "source_files": '\
|
||||
|
@ -28,6 +30,8 @@ control 'TEMPLATE configuration' do
|
|||
'"TEMPLATE-subcomponent-config-file-file-managed": '\
|
||||
'["subcomponent-example.tmpl.jinja"]}'
|
||||
)
|
||||
# rubocop:enable Layout/LineLength
|
||||
# rubocop:enable Lint/RedundantCopDisableDirective
|
||||
end
|
||||
its('content') { should include '"arch": "amd64"' }
|
||||
its('content') { should include '"winner": "pillar"}' }
|
||||
|
|
|
@ -5,6 +5,7 @@ name: default
|
|||
title: TEMPLATE formula
|
||||
maintainer: SaltStack Formulas
|
||||
license: Apache-2.0
|
||||
# yamllint disable-line rule:line-length
|
||||
summary: Verify that the TEMPLATE formula is setup and configured correctly
|
||||
depends:
|
||||
- name: share
|
||||
|
|
Loading…
Add table
Reference in a new issue