mirror of
https://github.com/mas-cli/mas
synced 2025-02-16 12:38:30 +00:00
Improve scripts: bootstrap, build, format, lint, test & version.
Allow them to be run from any directory. Call version from lint & test to create Package.swift with version info. Fail when accessing unset variables. Improve variable names. Fix lint issues. Improve lint & format scripts. Don't require user input to continue linting. Much cleaner lint output. Reorder lint output. Get swift-format from Brewfile instead of from Package.swift: - Speeds up linting. - Properly models dependency (not a code dependency). - swift-format depends on an old version of swift-argument-parser. Will refactor to use SAP soon. Include some improvements from 1.8.7 PR. Other scripts need improvement, too. Resolve #545 Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
parent
622a154fb9
commit
466ea67194
10 changed files with 122 additions and 110 deletions
|
@ -4,13 +4,12 @@
|
|||
#
|
||||
# https://github.com/realm/SwiftLint#configuration
|
||||
#
|
||||
|
||||
---
|
||||
disabled_rules:
|
||||
- non_optional_string_data_conversion
|
||||
- trailing_comma
|
||||
|
||||
excluded:
|
||||
- docs
|
||||
|
||||
opening_brace:
|
||||
allow_multiline_func: true
|
||||
ignore_multiline_function_signatures: true
|
||||
ignore_multiline_statement_conditions: true
|
||||
|
|
1
Brewfile
1
Brewfile
|
@ -1,6 +1,7 @@
|
|||
brew "markdownlint-cli"
|
||||
brew "shellcheck"
|
||||
brew "shfmt"
|
||||
brew "swift-format"
|
||||
brew "swiftformat"
|
||||
|
||||
# Already installed on GitHub Actions runner.
|
||||
|
|
|
@ -64,33 +64,6 @@
|
|||
"version": "2.1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-argument-parser",
|
||||
"repositoryURL": "https://github.com/apple/swift-argument-parser.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "c8ed701b513cf5177118a175d85fbbbcd707ab41",
|
||||
"version": "1.3.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-format",
|
||||
"repositoryURL": "https://github.com/apple/swift-format",
|
||||
"state": {
|
||||
"branch": "release/5.9",
|
||||
"revision": "1323e87eced56bdcfed1bb78af1f16f39274d032",
|
||||
"version": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-syntax",
|
||||
"repositoryURL": "https://github.com/apple/swift-syntax.git",
|
||||
"state": {
|
||||
"branch": "release/5.9",
|
||||
"revision": "9a101b70eee2a9dec04f92d2d47b22ebe57a1aae",
|
||||
"version": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "Version",
|
||||
"repositoryURL": "https://github.com/mxcl/Version.git",
|
||||
|
|
|
@ -75,30 +75,3 @@ let package = Package(
|
|||
],
|
||||
swiftLanguageVersions: [.v5]
|
||||
)
|
||||
|
||||
// https://github.com/apple/swift-format#matching-swift-format-to-your-swift-version-swift-57-and-earlier
|
||||
#if compiler(>=5.8)
|
||||
package.dependencies += [
|
||||
.package(url: "https://github.com/apple/swift-format", .branch("release/5.9"))
|
||||
]
|
||||
#elseif compiler(>=5.7)
|
||||
package.dependencies += [
|
||||
.package(url: "https://github.com/apple/swift-format", .branch("release/5.7"))
|
||||
]
|
||||
#elseif compiler(>=5.6)
|
||||
package.dependencies += [
|
||||
.package(url: "https://github.com/apple/swift-format", .branch("release/5.6"))
|
||||
]
|
||||
#elseif compiler(>=5.5)
|
||||
package.dependencies += [
|
||||
.package(url: "https://github.com/apple/swift-format", .branch("swift-5.5-branch"))
|
||||
]
|
||||
#elseif compiler(>=5.4)
|
||||
package.dependencies += [
|
||||
.package(url: "https://github.com/apple/swift-format", .branch("swift-5.4-branch"))
|
||||
]
|
||||
#elseif compiler(>=5.3)
|
||||
package.dependencies += [
|
||||
.package(url: "https://github.com/apple/swift-format", .branch("swift-5.3-branch"))
|
||||
]
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash -e
|
||||
#!/bin/bash -eu
|
||||
#
|
||||
# script/bootstrap
|
||||
# mas
|
||||
|
@ -6,10 +6,17 @@
|
|||
# Installs development dependencies and builds project dependencies.
|
||||
#
|
||||
|
||||
mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")"
|
||||
|
||||
if ! cd -- "${mas_dir}"; then
|
||||
printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
main() {
|
||||
script/clean
|
||||
|
||||
echo "==> 👢 Bootstrapping"
|
||||
printf $'==> 👢 Bootstrapping\n'
|
||||
|
||||
# Install Homebrew tools
|
||||
rm -f Brewfile.lock.json
|
||||
|
|
15
script/build
15
script/build
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash -e
|
||||
#!/bin/bash -eu
|
||||
#
|
||||
# script/build
|
||||
# mas
|
||||
|
@ -6,9 +6,16 @@
|
|||
# Builds the Swift Package.
|
||||
#
|
||||
|
||||
mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")"
|
||||
|
||||
if ! cd -- "${mas_dir}"; then
|
||||
printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build for the host architecture by default.
|
||||
ARCH=()
|
||||
if [[ "$1" == '--universal' ]]; then
|
||||
if [[ "${#}" -gt 1 && "${1}" == '--universal' ]]; then
|
||||
ARCH=(--arch arm64 --arch x86_64)
|
||||
fi
|
||||
|
||||
|
@ -21,6 +28,6 @@ fi
|
|||
echo "==> 🏗️ Building mas ($(script/version))"
|
||||
swift build \
|
||||
--configuration release \
|
||||
"${ARCH[@]}" \
|
||||
"${ARCH[@]+"${ARCH[@]}"}" \
|
||||
--disable-sandbox \
|
||||
"${CACHE[@]}"
|
||||
"${CACHE[@]+"${CACHE[@]}"}"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash -e
|
||||
#!/bin/bash -eu
|
||||
#
|
||||
# script/format
|
||||
# mas
|
||||
|
@ -6,34 +6,42 @@
|
|||
# Linting checks for development and CI.
|
||||
#
|
||||
# Automatically formats and fixes style violations using various tools.
|
||||
# Additionally runs `lint` to report any remaining style violations.
|
||||
#
|
||||
# Please keep in sync with script/lint.
|
||||
#
|
||||
|
||||
echo "==> 🚨 Formatting mas"
|
||||
mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")"
|
||||
|
||||
for LINTER in markdownlint shfmt swiftformat swiftlint; do
|
||||
if ! cd -- "${mas_dir}"; then
|
||||
printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf $'==> 🚨 Formatting mas\n'
|
||||
|
||||
for LINTER in markdownlint shfmt swift-format swiftformat swiftlint; do
|
||||
if [[ ! -x "$(command -v ${LINTER})" ]]; then
|
||||
echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'."
|
||||
printf $'error: %s is not installed. Run \'script/bootstrap\' or \'brew install %s\'.\n' "${LINTER}" "${LINTER}"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
echo "--> 🖊 Markdown"
|
||||
markdownlint --config .markdownlint.json --fix .github .
|
||||
|
||||
echo
|
||||
echo "--> 🕊️ Swift"
|
||||
for SOURCE in Package.swift Sources Tests; do
|
||||
swiftformat ${SOURCE}
|
||||
swift run swift-format format --in-place --recursive ${SOURCE}
|
||||
swiftlint lint --fix --strict ${SOURCE}
|
||||
printf -- $'--> 🕊 %s swift-format\n' "${SOURCE}"
|
||||
swift-format format --in-place --recursive "${SOURCE}"
|
||||
printf -- $'--> 🕊 %s swiftformat\n' "${SOURCE}"
|
||||
swiftformat "${SOURCE}"
|
||||
printf -- $'--> 🕊 %s swiftlint\n' "${SOURCE}"
|
||||
swiftlint --fix --strict "${SOURCE}"
|
||||
done
|
||||
|
||||
echo
|
||||
echo "--> 📜 Bash"
|
||||
shfmt -i 2 -l -w contrib/ script/
|
||||
printf -- $'--> 📜 Bash shfmt\n'
|
||||
shfmt \
|
||||
--write \
|
||||
--list \
|
||||
--indent 2 \
|
||||
--case-indent \
|
||||
contrib/ script/
|
||||
|
||||
script/lint
|
||||
printf -- $'--> 〽️ Markdown\n'
|
||||
markdownlint --config .markdownlint.json --fix .github .
|
||||
|
|
75
script/lint
75
script/lint
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash -e
|
||||
#!/bin/bash -u
|
||||
#
|
||||
# script/lint
|
||||
# mas
|
||||
|
@ -10,32 +10,63 @@
|
|||
# Please keep in sync with script/format.
|
||||
#
|
||||
|
||||
echo "==> 🚨 Linting mas"
|
||||
set -o pipefail
|
||||
|
||||
for LINTER in git markdownlint periphery shfmt swiftformat swiftlint; do
|
||||
if [[ ! -x "$(command -v ${LINTER})" ]]; then
|
||||
echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'."
|
||||
mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")"
|
||||
|
||||
if ! cd -- "${mas_dir}"; then
|
||||
printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf $'==> 🚨 Linting mas (%s)\n' "$(script/version)"
|
||||
|
||||
for linter in git markdownlint periphery shellcheck shfmt swift-format swiftformat swiftlint; do
|
||||
if [[ ! -x "$(command -v ${linter})" ]]; then
|
||||
printf $'error: %s is not installed. Run \'script/bootstrap\' or \'brew install %s\'.\n' "${linter}" "${linter}"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "--> 🌳 Git"
|
||||
git diff --check
|
||||
|
||||
echo
|
||||
echo "--> 🖊 Markdown"
|
||||
markdownlint --config .markdownlint.json .github .
|
||||
|
||||
echo
|
||||
echo "--> 🕊️ Swift"
|
||||
for SOURCE in Package.swift Sources Tests; do
|
||||
swiftformat --lint ${SOURCE}
|
||||
swift run swift-format lint --recursive ${SOURCE}
|
||||
swiftlint lint --strict ${SOURCE}
|
||||
exit_code=0
|
||||
for source in Package.swift Sources Tests; do
|
||||
printf -- $'--> 🕊 %s swift-format\n' "${source}"
|
||||
swift-format lint --strict --recursive "${source}"
|
||||
((exit_code |= "${?}"))
|
||||
printf -- $'--> 🕊 %s swiftformat\n' "${source}"
|
||||
script -q /dev/null swiftformat --lint --strict "${source}" |
|
||||
(grep -vxE $'Running SwiftFormat\\.\\.\\.\r|\\(lint mode - no files will be changed\\.\\)\r|Reading (?:config|swift-version) file at .*|\033\[32mSwiftFormat completed in \\d+\\.\\d+s\\.\033\\[0m\r|0/\\d+ files require formatting\\.\r' || true)
|
||||
((exit_code |= "${?}"))
|
||||
printf -- $'--> 🕊 %s swiftlint\n' "${source}"
|
||||
swiftlint --strict --quiet "${source}" 2> \
|
||||
>((grep -vxF $'warning: Configuration option \'allow_multiline_func\' in \'opening_brace\' rule is deprecated. Use the option \'ignore_multiline_function_signatures\' instead.' || true) >&2)
|
||||
((exit_code |= "${?}"))
|
||||
done
|
||||
periphery scan
|
||||
|
||||
echo
|
||||
echo "--> 📜 Bash"
|
||||
printf -- $'--> 🐚 Bash shellcheck\n'
|
||||
shellcheck --shell=bash script/*
|
||||
shfmt -d -i 2 -l contrib/ script/
|
||||
((exit_code |= "${?}"))
|
||||
|
||||
printf -- $'--> 📜 Bash shfmt\n'
|
||||
shfmt \
|
||||
--diff \
|
||||
--list \
|
||||
--indent 2 \
|
||||
--case-indent \
|
||||
contrib/ script/
|
||||
((exit_code |= "${?}"))
|
||||
|
||||
printf -- $'--> 〽️ Markdown\n'
|
||||
markdownlint --config .markdownlint.json .github .
|
||||
((exit_code |= "${?}"))
|
||||
|
||||
printf -- $'--> 🌳 Git\n'
|
||||
PAGER='cat' git diff --check
|
||||
((exit_code |= "${?}"))
|
||||
|
||||
printf -- $'--> 🌀 Periphery\n'
|
||||
script -q /dev/null periphery scan --strict --quiet --disable-update-check |
|
||||
(grep -vxF $'\033[0;1;32m* \033[0;0m\033[0;1mNo unused code detected.\033[0;0m\r\n' || true)
|
||||
((exit_code |= "${?}"))
|
||||
|
||||
exit "${exit_code}"
|
||||
|
|
12
script/test
12
script/test
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash -e
|
||||
#!/bin/bash -eu
|
||||
#
|
||||
# script/test
|
||||
# mas
|
||||
|
@ -6,5 +6,13 @@
|
|||
# Runs mas tests.
|
||||
#
|
||||
|
||||
echo "==> ✅ Testing"
|
||||
mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")"
|
||||
|
||||
if ! cd -- "${mas_dir}"; then
|
||||
printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf $'==> ✅ Testing mas (%s)\n' "$(script/version)"
|
||||
|
||||
swift test
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash -e
|
||||
#!/bin/bash -eu
|
||||
#
|
||||
# script/version
|
||||
# mas
|
||||
|
@ -9,12 +9,17 @@
|
|||
# This no longer works with MARKETING_VERSION build setting in Info.plist
|
||||
# agvtool what-marketing-version -terse1
|
||||
|
||||
mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")"
|
||||
|
||||
if ! cd -- "${mas_dir}"; then
|
||||
printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VERSION=$(git describe --abbrev=0 --tags)
|
||||
VERSION=${VERSION#v}
|
||||
|
||||
SCRIPT_PATH=$(dirname "$(which "$0")")
|
||||
|
||||
cat <<EOF >"${SCRIPT_PATH}/../Sources/MasKit/Package.swift"
|
||||
cat <<EOF >"Sources/MasKit/Package.swift"
|
||||
// Generated by: script/version
|
||||
enum Package {
|
||||
static let version = "${VERSION}"
|
||||
|
|
Loading…
Add table
Reference in a new issue