Skip to content

Commit

Permalink
Merge pull request #106 from myii/feat/use-shellcheck
Browse files Browse the repository at this point in the history
feat(travis): run `shellcheck` during lint job
  • Loading branch information
myii authored Nov 27, 2019
2 parents b6d7742 + 615e3b2 commit 213ce9d
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 37 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ jobs:
- language: 'node_js'
node_js: 'lts/*'
env: 'Lint'
name: 'Lint: salt-lint, yamllint, rubocop & commitlint'
name: 'Lint: salt-lint, yamllint, rubocop, shellcheck & commitlint'
before_install: 'skip'
script:
# Install and run `salt-lint`
- pip install --user salt-lint
- git ls-files | grep '\.sls$\|\.jinja$\|\.j2$\|\.tmpl$\|\.tst$'
| xargs salt-lint
- git ls-files -- *.sls *.jinja *.j2 *.tmpl *.tst
| xargs salt-lint
# Install and run `yamllint`
# Need at least `v1.17.0` for the `yaml-files` setting
- pip install --user yamllint>=1.17.0
- yamllint -s .
# Install and run `rubocop`
- gem install rubocop
- rubocop -d
# Run `shellcheck` (already pre-installed in Travis)
- shellcheck --version
- git ls-files -- *.sh *.bash *.ksh
| xargs shellcheck
# Install and run `commitlint`
- npm i -D @commitlint/config-conventional
@commitlint/travis-cli
Expand Down
6 changes: 3 additions & 3 deletions pre-commit_semantic-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ sed -i -e "s_^\(version:\).*_\1 ${1}_" FORMULA
sudo -H pip install m2r

# Copy and then convert the `.md` docs
cp *.md docs/
cd docs/
m2r --overwrite *.md
cp ./*.md docs/
cd docs/ || exit
m2r --overwrite ./*.md

# Change excess `H1` headings to `H2` in converted `CHANGELOG.rst`
sed -i -e '/^=.*$/s/=/-/g' CHANGELOG.rst
Expand Down
4 changes: 2 additions & 2 deletions ssf/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ ssf_node_anchors:
# An alternative method could be to use:
# `git describe --abbrev=0 --tags`
# yamllint disable rule:line-length
title: 'ci(travis): use default matrix after `centos-6` image fix'
body: '* Automated using https://github.com/myii/ssf-formula/pull/105'
title: 'ci(travis): run `shellcheck` during lint job [skip ci]'
body: '* Automated using https://github.com/myii/ssf-formula/pull/106'
# yamllint enable rule:line-length
github:
owner: 'saltstack-formulas'
Expand Down
12 changes: 8 additions & 4 deletions ssf/files/default/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ fast_finish: true

{#- Prepare variables used for linters #}
{%- set comment_linters = '# Run all of the linters in a single job' %}
{%- set name_linters = 'Lint: salt-lint, yamllint, rubocop & commitlint' %}
{%- set name_linters = 'Lint: salt-lint, yamllint, rubocop, shellcheck & commitlint' %}
{%- if not travis.use_single_job_for_linters %}
{%- set comment_linters = comment_linters ~ ' (except `rubocop`)' %}
{%- set name_linters = 'Lint: salt-lint, yamllint & commitlint' %}
{%- set name_linters = 'Lint: salt-lint, yamllint, shellcheck & commitlint' %}
{%- endif %}
{#- Prepare variable used for `saltcheck` #}
{%- set use_saltcheck = False %}
Expand Down Expand Up @@ -128,15 +128,19 @@ jobs:
{%- endif %}
# Install and run `salt-lint`
- {{ pip_cmd }} install --user salt-lint
- git ls-files | grep '\.sls$\|\.jinja$\|\.j2$\|\.tmpl$\|\.tst$'
| xargs salt-lint
- git ls-files -- *.sls *.jinja *.j2 *.tmpl *.tst
| xargs salt-lint
# Install and run `yamllint`
# Need at least `v1.17.0` for the `yaml-files` setting
- {{ pip_cmd }} install --user yamllint>=1.17.0
- yamllint -s .
{%- if travis.use_single_job_for_linters %}
{{- format_rubocop_linter() }}
{%- endif %}
# Run `shellcheck` (already pre-installed in Travis)
- shellcheck --version
- git ls-files -- *.sh *.bash *.ksh
| xargs shellcheck
# Install and run `commitlint`
- npm i -D @commitlint/config-conventional
@commitlint/travis-cli
Expand Down
18 changes: 10 additions & 8 deletions ssf/files/default/git/git_10_prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ COMMENT='Command `'${STATE}'` run'
# Check if PR branch already exists
BRANCH=$(git branch -l "${BRANCH_PR}")
COMMIT=
if [ ! -z "${BRANCH}" ]; then
git checkout ${BRANCH_PR}
if [ -n "${BRANCH}" ]; then
git checkout "${BRANCH_PR}"
# This may end up as blank as well, so that's why a separate `if` is required below
COMMIT=$(git log -n1 | grep "${COMMIT_GREP}")
fi

# Perform actions depending on if a commit was found or not
if [ ! -z "${COMMIT}" ]; then
if [ -n "${COMMIT}" ]; then
CHANGED='False'
else
git checkout ${BRANCH_UPSTREAM}
git checkout "${BRANCH_UPSTREAM}"
git pull
git status
# If the branch existed but not the commit, assume the branch is stale (i.e. previous PR merged)
# Remove it, ready to be recreated at the latest upstream commit
if [ ! -z "${BRANCH}" ]; then
git branch -d ${BRANCH_PR}
if [ -n "${BRANCH}" ]; then
git branch -d "${BRANCH_PR}"
fi
# TODO: Improve this part, should be able to remove with the duplication with the right solution
# Don't want to resort to using `git branch -D` above, since that could be premature in certain situations
Expand All @@ -40,8 +40,10 @@ else
if [ -z "${BRANCH}" ]; then
NEW_BRANCH='-b'
fi
git checkout ${NEW_BRANCH} ${BRANCH_PR}
git merge ${BRANCH_UPSTREAM}
# Disabling `SC2086` where double-quoting an empty variable introduces an error
# shellcheck disable=SC2086
git checkout ${NEW_BRANCH} "${BRANCH_PR}"
git merge "${BRANCH_UPSTREAM}"
fi

# Write the state line
Expand Down
22 changes: 13 additions & 9 deletions ssf/files/default/git/git_20_commit_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ COMMIT_GREP=${4}
COMMIT_TITLE=${5}
COMMIT_BODY=${6}
COMMIT_OPTIONS=${7}
PUSH_ACTIVE=$(echo ${8} | tr "[:upper:]" "[:lower:]")
PUSH_VIA_PR=$(echo ${9} | tr "[:upper:]" "[:lower:]")
PUSH_ACTIVE=$(echo "${8}" | tr "[:upper:]" "[:lower:]")
PUSH_VIA_PR=$(echo "${9}" | tr "[:upper:]" "[:lower:]")
REMOTE_FORK_NAME=${10}
REMOTE_FORK_BRANCH=${11}
# Currently unused but leaving here as a placeholder
# REMOTE_FORK_BRANCH=${11}
REMOTE_UPSTREAM_NAME=${12}
REMOTE_UPSTREAM_BRANCH=${13}
# Prepare initial state line variables
Expand All @@ -22,7 +23,7 @@ COMMENT='Command `'${STATE}'` run'

# Prepare git options depending on if a commit was found or not
COMMIT=$(git log -n1 | grep "${COMMIT_GREP}")
if [ ! -z "${COMMIT}" ]; then
if [ -n "${COMMIT}" ]; then
AMEND='--amend'
FORCE='-f'
else
Expand All @@ -31,15 +32,18 @@ else
fi

# Perform actions
# Disabling `SC2086` where double-quoting an empty variable introduces errors
# shellcheck disable=SC2086
git commit ${AMEND} "${COMMIT_OPTIONS}" -m "${COMMIT_TITLE}" -m "${COMMIT_BODY}"
if ${PUSH_ACTIVE}; then
if ${PUSH_VIA_PR}; then
git push ${FORCE} -u ${REMOTE_FORK_NAME} ${BRANCH_PR}
# shellcheck disable=SC2086
git push ${FORCE} -u "${REMOTE_FORK_NAME}" "${BRANCH_PR}"
else
git checkout ${BRANCH_UPSTREAM}
git merge ${BRANCH_PR}
git push ${REMOTE_UPSTREAM_NAME} HEAD:${REMOTE_UPSTREAM_BRANCH}
git branch -d ${BRANCH_PR}
git checkout "${BRANCH_UPSTREAM}"
git merge "${BRANCH_PR}"
git push "${REMOTE_UPSTREAM_NAME}" "HEAD:${REMOTE_UPSTREAM_BRANCH}"
git branch -d "${BRANCH_PR}"
fi
fi

Expand Down
10 changes: 5 additions & 5 deletions ssf/files/default/git/git_30_create_PR.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ COMMENT='Command `'${STATE}'` run'

# Only create the PR if it doesn't already exist
# If it already exists, the `git push` done earlier will have updated the PR already
PR_EXISTS=$(curl -i https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls | grep "${GH_USER}:${BRANCH_PR}")
if [ ! -z "${PR_EXISTS}" ]; then
PR_EXISTS=$(curl -i "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls" | grep "${GH_USER}:${BRANCH_PR}")
if [ -n "${PR_EXISTS}" ]; then
CHANGED='False'
else
curl -H "Authorization: bearer ${GH_TOKEN}" -d '
{
"title": "'"${COMMIT_TITLE}"'",
"body": "'"${COMMIT_BODY}"'",
"head": "'${GH_USER}':'${BRANCH_PR}'",
"base": "'${REPO_BRANCH}'"
"head": "'"${GH_USER}"':'"${BRANCH_PR}"'",
"base": "'"${REPO_BRANCH}"'"
}
' https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls >> ${FILE_API_RESPONSE}
' "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls" >> "${FILE_API_RESPONSE}"
fi

# Write the state line
Expand Down
6 changes: 3 additions & 3 deletions ssf/files/default/pre-commit_semantic-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ sed -i -e "s_^\(version:\).*_\1 ${1}_" FORMULA
sudo -H pip install m2r

# Copy and then convert the `.md` docs
cp *.md docs/
cd docs/
m2r --overwrite *.md
cp ./*.md docs/
cd docs/ || exit
m2r --overwrite ./*.md

# Change excess `H1` headings to `H2` in converted `CHANGELOG.rst`
sed -i -e '/^=.*$/s/=/-/g' CHANGELOG.rst
Expand Down

0 comments on commit 213ce9d

Please sign in to comment.