Skip to content

Commit 2552a7c

Browse files
authored
Merge pull request #18 from perl-actions/bash-refactoring
Bash refactoring
2 parents 63162a8 + f78614b commit 2552a7c

File tree

8 files changed

+179
-65
lines changed

8 files changed

+179
-65
lines changed

.github/Contributing.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Bash Style Conventions
2+
3+
The most important thing re coding style (as with any contribution) is to
4+
follow the style conventions in place for the existing code.
5+
6+
Here are some basics:
7+
8+
* Use spaces for indentation.
9+
No tabs please.
10+
* Use 4 space indent.
11+
* Keep lines under 80 chars if possible.
12+
* Always use `[[ ... ]]`, not `[ ... ]` form.
13+
* Don't use `-n`.
14+
* Don't quote things that don't need quotes.
15+
* Unless it really adds to readability.
16+
* If script is long, break into functions and use a `main` function at top.
17+
* Function names should be `foo-bar` not `foo_bar`.
18+
* Define functions `foo-bar() ( ... )`, not `function foo-bar ( ... )`.
19+
20+
21+
## Testing
22+
23+
* Run `make test`.

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
SHELL := bash
2+
3+
4+
default:
5+
6+
7+
test: shellcheck bats
8+
9+
shellcheck:
10+
@echo
11+
ifneq (,$(shell command -v shellcheck))
12+
shellcheck bin/*
13+
@echo 'All bin/* files passed shellcheck'
14+
else
15+
$(warning 'shellcheck' not installed)
16+
endif
17+
18+
19+
bats:
20+
@echo
21+
ifneq (,$(shell command -v bats))
22+
bats t/
23+
else
24+
$(warning 'bats' not installed)
25+
endif
26+
27+
28+
clean:
29+
find t/test-data \
30+
-name 'MANIFEST*.bak' \
31+
-o -name 'MYMETA*' \
32+
-o -name 'Makefile' \
33+
-o -name 'blib' \
34+
-o -name 'build_dir' \
35+
-o -name 'pm_to_blib' \
36+
-o -name '_build' \
37+
-o -name 'Build' | \
38+
xargs $(RM) -r
39+
$(RM) t/test-data/extutils-makemaker-module-with-manifest.skip/MANIFEST
40+
$(RM) t/test-data/module-build_module/MANIFEST

bin/auto-build-and-test-dist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
set -eux
3+
set -e -u -o pipefail
44

5-
BUILD_DIR=${BUILD_DIR:='build_dir'}
5+
: "${BUILD_DIR:=build_dir}"
66

77
cpan-install-build-deps
88
build-dist

bin/build-dist

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,66 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
set -eux
3+
set -e -u -o pipefail
44

5-
BUILD_DIR=${BUILD_DIR:='build_dir'}
5+
: "${BUILD_DIR:=build_dir}"
66

7-
if [[ -e dist.ini ]]; then
7+
main() (
8+
if [[ -e dist.ini ]]; then dzil-build
9+
elif [[ -e minil.toml ]]; then minil-build
10+
elif [[ -e Build.PL ]]; then build-pl
11+
elif [[ -e Makefile.PL ]]; then std-perl-build
12+
fi
13+
)
14+
15+
dzil-build() (
816
dzil build --no-tgz --in "$BUILD_DIR"
9-
elif [[ -e minil.toml ]]; then
17+
)
18+
19+
minil-build() (
1020
rm -rf "$BUILD_DIR"
1121
minil build
1222

1323
# TODO: It looks like minil doesn't accept a build directory name, so we
1424
# just find the last created dir and use that.
1525
# shellcheck disable=SC2012
16-
DIR=$(ls -td -- */ | head -n 1 | cut -d'/' -f1)
17-
mv "$DIR" "$BUILD_DIR"
18-
elif [[ -e Build.PL ]]; then
26+
dir=$(
27+
ls -td -- */ |
28+
head -n 1 |
29+
cut -d'/' -f1
30+
)
31+
mv "$dir" "$BUILD_DIR"
32+
)
33+
34+
build-pl() (
1935
rm -rf "$BUILD_DIR"
36+
2037
perl Build.PL
2138
./Build clean
2239
./Build manifest
2340
./Build distdir
2441

2542
# Module::Build does not support a build directory, so we have to find
2643
# the last created dir and use that.
27-
DIR="$(perl -MModule::Build -e'print Module::Build->resume->dist_dir;')"
28-
mv "$DIR" "$BUILD_DIR"
29-
elif [[ -e Makefile.PL ]]; then
44+
dir=$(perl -MModule::Build -e 'print Module::Build->resume->dist_dir;')
45+
mv "$dir" "$BUILD_DIR"
46+
)
47+
48+
std-perl-build() (
3049
rm -rf "$BUILD_DIR"
3150
perl Makefile.PL
3251
make
33-
if [[ -e MANIFEST.SKIP ]]; then
52+
[[ -e MANIFEST.SKIP ]] &&
3453
make manifest
35-
fi
3654
make distdir
3755

3856
# same as with minil
3957
# shellcheck disable=SC2012
40-
DIR=$(ls -td -- */ | head -n 1 | cut -d'/' -f1)
41-
mv "$DIR" "$BUILD_DIR"
42-
fi
58+
dir=$(
59+
ls -td -- */ |
60+
head -n 1 |
61+
cut -d'/' -f1
62+
)
63+
mv "$dir" "$BUILD_DIR"
64+
)
4365

44-
exit 0
66+
main "$@"

bin/cpan-install-build-deps

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
set -eux
3+
set -e -u -o pipefail
44

55
if [[ -e dist.ini ]]; then
66
# Don't return false positives if deps have all been satisfied
7-
dzil authordeps | xargs cpm install -g --show-build-log-on-failure || true
8-
dzil stale | xargs cpm install -g --show-build-log-on-failure || true
7+
dzil authordeps |
8+
xargs cpm install -g --show-build-log-on-failure ||
9+
true
10+
dzil stale |
11+
xargs cpm install -g --show-build-log-on-failure ||
12+
true
913
fi
10-
11-
exit 0

bin/cpan-install-dist-deps

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
set -eux
3+
set -e -u -o pipefail
44

5-
if [[ -e cpanfile ]];then
6-
cpm install -g --cpanfile cpanfile --with-recommends --with-suggests --show-build-log-on-failure "$@"
7-
fi
5+
main() (
6+
[[ -e cpanfile ]] &&
7+
cpm-install "$@"
88

9-
if [[ -e Build.PL ]]; then
9+
[[ -e Build.PL ]] &&
10+
build-and-install-deps
11+
12+
true
13+
)
14+
15+
cpm-install() (
16+
cpm install -g \
17+
--cpanfile cpanfile \
18+
--with-recommends \
19+
--with-suggests \
20+
--show-build-log-on-failure \
21+
"$@"
22+
)
23+
24+
build-and-install-deps() (
1025
# This will install both build and dist deps
1126
perl Build.PL
12-
PERL_MM_USE_DEFAULT=1 ./Build installdeps --cpan_client 'cpm install -g --show-build-log-on-failure' || true
13-
fi
27+
PERL_MM_USE_DEFAULT=1 \
28+
./Build installdeps \
29+
--cpan_client \
30+
'cpm install -g --show-build-log-on-failure' ||
31+
true
32+
)
33+
34+
main "$@"

bin/test-dist

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
1-
#!/bin/bash
2-
3-
set -eux
4-
5-
AUTHOR_TESTING=${AUTHOR_TESTING:=0}
6-
CIRCLE_BRANCH=${CIRCLE_BRANCH:=""}
7-
CODE_COVERAGE_REPORT=${CODE_COVERAGE_REPORT:=""}
8-
CODECOV_TOKEN=${CODECOV_TOKEN:=""}
9-
CODECOV_ENABLE=${CODECOV_ENABLE:=$CODECOV_TOKEN}
10-
COVERALLS_TOKEN=${COVERALLS_TOKEN:=""}
11-
GITHUB_REF=${GITHUB_REF:=""}
12-
TEST_DIRS=${TEST_DIRS:=t}
13-
14-
if [[ -n $CODECOV_ENABLE || -n $COVERALLS_TOKEN || -n $CODE_COVERAGE_REPORT ]]; then
15-
HARNESS_PERL_SWITCHES=${HARNESS_PERL_SWITCHES:="-MDevel::Cover=+ignore,^local/|^t/|^xt"}
1+
#!/usr/bin/env bash
2+
3+
set -e -u -o pipefail
4+
5+
: "${AUTHOR_TESTING:=0}"
6+
: "${CIRCLE_BRANCH:=""}"
7+
: "${CODE_COVERAGE_REPORT:=""}"
8+
: "${CODECOV_TOKEN:=""}"
9+
: "${CODECOV_ENABLE:=$CODECOV_TOKEN}"
10+
: "${COVERALLS_TOKEN:=""}"
11+
: "${GITHUB_REF:=""}"
12+
: "${TEST_DIRS:=t}"
13+
14+
if [[ $CODECOV_ENABLE ||
15+
$COVERALLS_TOKEN ||
16+
$CODE_COVERAGE_REPORT ]]
17+
then
18+
: "${HARNESS_PERL_SWITCHES:="-MDevel::Cover=+ignore,^local/|^t/|^xt"}"
1619
export HARNESS_PERL_SWITCHES
1720
fi
1821

1922
# remove the changes test if we're testing master
20-
if [[ "$GITHUB_REF" == "refs/heads/master" ]] || [[ "$CIRCLE_BRANCH" == "master" ]]; then
23+
if [[ $GITHUB_REF == refs/heads/master ||
24+
$CIRCLE_BRANCH == master ]]
25+
then
2126
rm -f xt/release/changes_has_content.t || true
22-
perl -pi -e "s|'xt/release/changes_has_content.t'||g" xt/author/* || true
27+
perl -pi -e "s|'xt/release/changes_has_content.t'||g" \
28+
xt/author/* ||
29+
true
2330
fi
2431

25-
if [ "$AUTHOR_TESTING" -ne 0 ] && [ -d xt ]; then
32+
[[ $AUTHOR_TESTING -ne 0 && -d xt ]] &&
2633
TEST_DIRS="$TEST_DIRS xt"
27-
fi
2834

2935
IFS=' ' read -r -a ALL_TEST_DIRS <<<"$TEST_DIRS"
3036

3137
prove -lr --jobs 2 "$@" "${ALL_TEST_DIRS[@]}"
3238

33-
if [[ -n "${CODECOV_ENABLE}" ]]; then
39+
if [[ ${CODECOV_ENABLE} ]]; then
3440
cover -report codecov
3541
fi
3642

37-
if [[ -n "${COVERALLS_TOKEN}" ]]; then
43+
if [[ ${COVERALLS_TOKEN} ]]; then
3844
COVERALLS_REPO_TOKEN=$COVERALLS_TOKEN
3945
export COVERALLS_REPO_TOKEN
4046
cover -report coveralls
4147
fi
42-
43-
exit 0

bin/upgrade-perl-helpers

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
set -eux
3+
set -e -u -o pipefail
44

55
REPO=ci-perl-tester-helpers
66

7-
pushd /tmp
8-
rm -rf $REPO
9-
git clone "https://github.com/perl-actions/$REPO.git" --depth 1
10-
cp $REPO/bin/* /usr/local/bin/
11-
rm -rf $REPO
12-
popd
7+
(
8+
cd /tmp
9+
rm -rf $REPO
10+
git clone --depth 1 \
11+
https://github.com/perl-actions/$REPO.git
12+
cp $REPO/bin/* /usr/local/bin/
13+
rm -rf $REPO
14+
)

0 commit comments

Comments
 (0)