Skip to content

Commit

Permalink
Merge branch 'update-2022-08' into 'main'
Browse files Browse the repository at this point in the history
Update 2022-08

See merge request xebis/shellib!30
  • Loading branch information
bruzina committed Aug 15, 2022
2 parents b6718c8 + 830db83 commit a3e6410
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 22 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
hooks:
- id: gitlint
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.3.0
hooks:
- id: check-added-large-files
args: [--maxkb=1024]
Expand All @@ -25,7 +25,7 @@ repos:
- id: no-commit-to-branch
- id: trailing-whitespace
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.6
rev: 3.0.0
hooks:
- id: check-mailmap
- id: forbid-binary
Expand All @@ -35,11 +35,11 @@ repos:
exclude: .*\.bats$
- id: script-must-not-have-extension
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.31.1
rev: v0.32.1
hooks:
- id: markdownlint
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.26.3
rev: v1.27.1
hooks:
- id: yamllint
args: [--strict]
Expand Down Expand Up @@ -72,6 +72,6 @@ repos:
language: system
types: [shell]
- repo: https://github.com/zricethezav/gitleaks
rev: v8.2.7
rev: v8.10.3
hooks:
- id: gitleaks
9 changes: 7 additions & 2 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ LANG=C
function run_pre_commit() {
# Skip GitLab CI Linter if GitLab Personal Access Token is not set
if [ -z "${GL_TOKEN:-}" ]; then
SKIP=gitlab-ci-linter pre-commit
if [ -z "${SKIP:-}" ]; then
export SKIP=gitlab-ci-linter
else
export SKIP="$SKIP,gitlab-ci-linter"
fi
else
export GITLAB_PRIVATE_TOKEN="$GL_TOKEN"
pre-commit
fi

pre-commit
}

# Skip execution under test
Expand Down
6 changes: 5 additions & 1 deletion scripts/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ LANG=C
function run_pre_commit() {
# Skip GitLab CI Linter if GitLab Personal Access Token is not set
if [ -z "${GL_TOKEN:-}" ]; then
export SKIP=gitlab-ci-linter
if [ -z "${SKIP:-}" ]; then
export SKIP=gitlab-ci-linter
else
export SKIP="$SKIP,gitlab-ci-linter"
fi
else
export GITLAB_PRIVATE_TOKEN="$GL_TOKEN"
fi
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/bats-assert
2 changes: 1 addition & 1 deletion tests/helpers/bats-file
Submodule bats-file updated 2 files
+1 −1 README.md
+2 −1 src/file.bash
67 changes: 61 additions & 6 deletions tests/pre-commit.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,88 @@ setup() {

@test 'scripts/pre-commit run_pre_commit test' {
function pre-commit() {
if [ -z "${GITLAB_PRIVATE_TOKEN:-}" ]; then
# shellcheck disable=SC2030,SC2031
if [ -z "${GL_TOKEN:-}" ]; then
echo 'Error'
fi
# shellcheck disable=SC2030,SC2031
if [ -n "${SKIP:-}" ]; then
echo "Skipping $SKIP"
fi
echo 'OK'
}
export -f pre-commit

export GITLAB_PRIVATE_TOKEN='secret'
# shellcheck disable=SC2030,SC2031
export GL_TOKEN='secret'
unset SKIP
run run_pre_commit

assert_success
assert_output 'OK'
}

@test 'scripts/pre-commit run_pre_commit with skip hook test' {
@test 'scripts/pre-commit run_pre_commit skipped hook test' {
function pre-commit() {
if [ "${SKIP_HOOK:-}" == 'skipped-hook' ]; then
echo 'Skipping skipped-hook'
# shellcheck disable=SC2030,SC2031
if [ -z "${GL_TOKEN:-}" ]; then
echo 'Error'
fi
# shellcheck disable=SC2030,SC2031
if [ -n "${SKIP:-}" ]; then
echo "Skipping $SKIP"
fi
echo 'OK'
}
export -f pre-commit

export SKIP_HOOK='skipped-hook'
# shellcheck disable=SC2030,SC2031
export GL_TOKEN='secret'
# shellcheck disable=SC2030,SC2031
export SKIP='skipped-hook'
run run_pre_commit

assert_success
assert_line -n 0 'Skipping skipped-hook'
assert_line -n 1 'OK'
}

@test 'scripts/pre-commit run_pre_commit without GitLab token should skip gitlab-ci-linter test' {
function pre-commit() {
# shellcheck disable=SC2030,SC2031
if [ -n "${SKIP:-}" ]; then
echo "Skipping $SKIP"
fi
echo 'OK'
}
export -f pre-commit

unset GL_TOKEN
unset SKIP
run run_pre_commit

assert_success
assert_line -n 0 'Skipping gitlab-ci-linter'
assert_line -n 1 'OK'
}

@test 'scripts/pre-commit run_pre_commit without GitLab token and skipped hook should skip both test' {
function pre-commit() {
# shellcheck disable=SC2030,SC2031
if [ -n "${SKIP:-}" ]; then
# shellcheck disable=SC2030,SC2031
echo "Skipping $SKIP"
fi
echo 'OK'
}
export -f pre-commit

unset GL_TOKEN
# shellcheck disable=SC2030,SC2031
export SKIP='skipped-hook'
run run_pre_commit

assert_success
assert_line -n 0 'Skipping skipped-hook,gitlab-ci-linter'
assert_line -n 1 'OK'
}
64 changes: 58 additions & 6 deletions tests/pre-push.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,93 @@ setup() {
. scripts/pre-push
}

@test 'scripts/pre-push run_pre_commit success test' {
@test 'scripts/pre-push run_pre_commit test' {
function pre-commit() {
# shellcheck disable=SC2030,SC2031
if [ -z "${GITLAB_PRIVATE_TOKEN-}" ]; then
if [ -z "${GL_TOKEN-}" ]; then
echo 'Error'
fi
# shellcheck disable=SC2030,SC2031
if [ -n "${SKIP:-}" ]; then
echo "Skipping $SKIP"
fi
echo 'OK'
}
export -f pre-commit

# shellcheck disable=SC2030,SC2031
export GL_TOKEN='secret'
unset SKIP
run run_pre_commit

assert_success
assert_output 'OK'
}

@test 'scripts/pre-push run_pre_commit with skip hook test' {
@test 'scripts/pre-push run_pre_commit skipped hook test' {
function pre-commit() {
# shellcheck disable=SC2030,SC2031
if [ -z "${GITLAB_PRIVATE_TOKEN-}" ]; then
echo 'Skipping skipped-hook'
if [ -z "${GL_TOKEN:-}" ]; then
echo 'Error'
fi
# shellcheck disable=SC2030,SC2031
if [ -n "${SKIP:-}" ]; then
echo "Skipping $SKIP"
fi
echo 'OK'
}
export -f pre-commit

unset GL_TOKEN
# shellcheck disable=SC2030,SC2031
export GL_TOKEN='secret'
# shellcheck disable=SC2030,SC2031
export SKIP='skipped-hook'
run run_pre_commit

assert_success
assert_line -n 0 'Skipping skipped-hook'
assert_line -n 1 'OK'
}

@test 'scripts/pre-push run_pre_commit without GitLab token should skip gitlab-ci-linter test' {
function pre-commit() {
# shellcheck disable=SC2030,SC2031
if [ -n "${SKIP:-}" ]; then
echo "Skipping $SKIP"
fi
echo 'OK'
}
export -f pre-commit

unset GL_TOKEN
unset SKIP
run run_pre_commit

assert_success
assert_line -n 0 'Skipping gitlab-ci-linter'
assert_line -n 1 'OK'
}

@test 'scripts/pre-push run_pre_commit without GitLab token and skipped hook should skip both test' {
function pre-commit() {
# shellcheck disable=SC2030,SC2031
if [ -n "${SKIP:-}" ]; then
echo "Skipping $SKIP"
fi
echo 'OK'
}
export -f pre-commit

unset GL_TOKEN
# shellcheck disable=SC2030,SC2031
export SKIP='skipped-hook'
run run_pre_commit

assert_success
assert_line -n 0 'Skipping skipped-hook,gitlab-ci-linter'
assert_line -n 1 'OK'
}

@test 'scripts/pre-push run_pre_commit with arguments and stdin test' {
function pre-commit() {
cat <&0
Expand Down

0 comments on commit a3e6410

Please sign in to comment.