Skip to content

Commit c729a3a

Browse files
committed
Merge branch 'experimental/swift-format'
2 parents 085f2c2 + d72cf2f commit c729a3a

File tree

6 files changed

+129
-83
lines changed

6 files changed

+129
-83
lines changed

.github/workflows/Format.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ on:
88
jobs:
99
swift_format:
1010
if: |
11-
!startsWith(github.event.head_commit.message, '[ci skip]') &&
12-
!startsWith(github.event.head_commit.message, '[ci skip format]') &&
13-
!startsWith(github.event.head_commit.message, '[ci skip swift_format]')
11+
!contains(github.event.head_commit.message, '[ci skip]') &&
12+
!contains(github.event.head_commit.message, '[ci skip format]')
1413
name: swift-format
1514
runs-on: macos-12
1615
steps:
@@ -21,7 +20,7 @@ jobs:
2120
run: make format
2221
- uses: stefanzweifel/git-auto-commit-action@v4
2322
with:
24-
commit_message: 'ci: swift-format'
23+
commit_message: 'style(ci): run swiftformat'
2524
branch: 'main'
2625
env:
2726
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.swift-format

Lines changed: 0 additions & 56 deletions
This file was deleted.

.swiftformat

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
--acronyms ID,URL,URI,UUID,ULID,SPM,XML,YAML,JSON,IDFA
2+
--allman false
3+
--assetliterals visual-width
4+
--binarygrouping none
5+
--categorymark "MARK: %c"
6+
--classthreshold 0
7+
--closingparen balanced
8+
--closurevoid remove
9+
--commas always
10+
--conflictmarkers reject
11+
--decimalgrouping none
12+
--elseposition same-line
13+
--emptybraces no-space
14+
--enumnamespaces always
15+
--enumthreshold 0
16+
--exponentcase lowercase
17+
--exponentgrouping disabled
18+
--extensionacl on-declarations
19+
--extensionlength 0
20+
--extensionmark "MARK: - %t + %c"
21+
--fractiongrouping disabled
22+
--fragment false
23+
--funcattributes preserve
24+
--generictypes
25+
--groupedextension "MARK: %c"
26+
--guardelse auto
27+
--header ignore
28+
--hexgrouping none
29+
--hexliteralcase uppercase
30+
--ifdef indent
31+
--importgrouping alpha
32+
--indent 2
33+
--indentcase false
34+
--indentstrings false
35+
--lifecycle
36+
--lineaftermarks true
37+
--linebreaks lf
38+
--markcategories true
39+
--markextensions always
40+
--marktypes always
41+
--maxwidth none
42+
--modifierorder
43+
--nevertrailing
44+
--nospaceoperators
45+
--nowrapoperators
46+
--octalgrouping none
47+
--operatorfunc spaced
48+
--organizetypes actor,class,enum,struct
49+
--patternlet hoist
50+
--ranges spaced
51+
--redundanttype infer-locals-only
52+
--self init-only
53+
--selfrequired
54+
--semicolons never
55+
--shortoptionals always
56+
--smarttabs enabled
57+
--someAny true
58+
--stripunusedargs always
59+
--structthreshold 0
60+
--tabwidth unspecified
61+
--trailingclosures
62+
--trimwhitespace always
63+
--typeattributes preserve
64+
--typeblanklines remove
65+
--typemark "MARK: - %t"
66+
--varattributes preserve
67+
--voidtype void
68+
--wraparguments before-first
69+
--wrapcollections before-first
70+
--wrapconditions preserve
71+
--wrapparameters before-first
72+
--wrapreturntype preserve
73+
--wrapternary default
74+
--wraptypealiases preserve
75+
--xcodeindentation disabled
76+
--yodaswap always

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
install_formatter:
2-
./scripts/install_swift-format
2+
@chmod +x ./scripts/install_swift-format.sh
3+
@./scripts/install_swift-format.sh
4+
5+
update_formatter:
6+
@rm ./scripts/.bin/swift-format
7+
@make install_formatter
38

49
format:
5-
./Scripts/.bin/swift-format \
6-
--in-place --recursive \
7-
./Package.swift ./Sources ./Tests
10+
@chmod +x ./scripts/format.sh
11+
@./scripts/format.sh
812

913
test:
10-
swift test --enable-test-discovery
14+
@swift test --enable-test-discovery

Scripts/format.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
_get_parent_dir_abs_path() {
4+
echo "$(cd "$(dirname "$1")" && pwd)"
5+
}
6+
7+
# ––––––––––––––––––––––––– Constants ––––––––––––––––––––––––––
8+
9+
SCRIPT_DIR=$(_get_parent_dir_abs_path $0)
10+
TOOLS_DIR="${SCRIPT_DIR}/.bin/"
11+
TOOL_NAME="swiftformat"
12+
TOOL="${TOOLS_DIR}/${TOOL_NAME}"
13+
14+
# ––––––––––––––––––––––––––– Script –––––––––––––––––––––––––––
15+
16+
cd ${SCRIPT_DIR}
17+
cd ..
18+
19+
${TOOL} . \
20+
--config .swiftformat

Scripts/install_swift-format renamed to Scripts/install_swift-format.sh

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,34 @@ _get_parent_dir_abs_path() {
66

77
# ––––––––––––––––––––––––––– Config –––––––––––––––––––––––––––
88

9-
TOOL_NAME="swift-format"
10-
TOOL_OWNER="apple"
11-
TOOL_VERSION="0.50600.1"
9+
TOOL_NAME="swiftformat"
10+
TOOL_OWNER="nicklockwood"
11+
TOOL_VERSION="0.50.5"
1212

1313
# ––––––––––––––––––––––––– Constants ––––––––––––––––––––––––––
1414

1515
SCRIPT_DIR=$(_get_parent_dir_abs_path $0)
1616
TOOLS_INSTALL_PATH="${SCRIPT_DIR}/.bin"
1717
TOOL_INSTALL_PATH="${TOOLS_INSTALL_PATH}/${TOOL_NAME}"
18-
TEMP_INSTALL_PATH="${TOOLS_INSTALL_PATH}/install-${TOOL_NAME}"
18+
TOOL_DOWNLOAD_DIR="${TOOLS_INSTALL_PATH}/_${TOOL_NAME}"
19+
20+
TOOL=${TOOL_INSTALL_PATH}
21+
TOOL_REPO="https://github.com/${TOOL_OWNER}/${TOOL_NAME}"
22+
ARCHIVE_NAME="${TOOL_NAME}.artifactbundle"
23+
ARCHIVE_URL="${TOOL_REPO}/releases/download/${TOOL_VERSION}/${ARCHIVE_NAME}.zip"
1924

2025
# ––––––––––––––––––––––––––– Steps ––––––––––––––––––––––––––––
2126

2227
tool_fetch() {
23-
git clone "https://github.com/${TOOL_OWNER}/${TOOL_NAME}.git"
24-
cd "${TOOL_NAME}"
25-
git checkout "tags/${TOOL_VERSION}"
28+
curl -L ${ARCHIVE_URL} -o "${TOOL_DOWNLOAD_DIR}/${ARCHIVE_NAME}.zip"
2629
}
2730

28-
tool_build() {
29-
swift build --product="${TOOL_NAME}" -c release --disable-sandbox --build-path '.build'
31+
tool_extract() {
32+
unzip "${TOOL_DOWNLOAD_DIR}/${ARCHIVE_NAME}.zip" -d ${TOOL_DOWNLOAD_DIR}
3033
}
3134

3235
tool_install() {
33-
install "${TEMP_INSTALL_PATH}/${TOOL_NAME}/.build/release/${TOOL_NAME}" "${TOOLS_INSTALL_PATH}"
36+
install "${TOOL_DOWNLOAD_DIR}/${ARCHIVE_NAME}/${TOOL_NAME}-${TOOL_VERSION}-macos/bin/${TOOL_NAME}" "${TOOLS_INSTALL_PATH}"
3437
}
3538

3639
# ––––––––––––––––––––––––––– Script –––––––––––––––––––––––––––
@@ -42,20 +45,20 @@ log() {
4245
printf "\n$1 ${set_bold}$2${set_normal}\n"
4346
}
4447

45-
_trap_exit() {
46-
rm -rf "${TEMP_INSTALL_PATH}"
48+
clean_up() {
49+
rm -rf "${TOOL_DOWNLOAD_DIR}"
4750
}
4851

4952
set -e
50-
trap _trap_exit err exit SIGTERM SIGINT
53+
trap clean_up err exit SIGTERM SIGINT
5154

5255
if [ -f "${TOOL_INSTALL_PATH}" ]; then
5356
log "⚠️" " ${TOOL_NAME} already installed"
5457
exit 0
5558
fi
5659

57-
if [ ! -d "${TEMP_INSTALL_PATH}" ]; then
58-
mkdir -p "${TEMP_INSTALL_PATH}"
60+
if [ ! -d "${TOOL_DOWNLOAD_DIR}" ]; then
61+
mkdir -p "${TOOL_DOWNLOAD_DIR}"
5962
fi
6063

6164
cd "${TEMP_INSTALL_PATH}"
@@ -64,16 +67,16 @@ log "⬇️" " Fetching ${TOOL_NAME}...\n"
6467

6568
tool_fetch
6669

67-
log "🔨" "Building ${TOOL_NAME}...\n"
70+
log "📦" " Extracting ${TOOL_NAME}...\n"
6871

69-
tool_build
72+
tool_extract
7073

7174
log "♻️" " Installing ${TOOL_NAME}..."
7275

7376
tool_install
7477

7578
log "💧" "Performing cleanup..."
76-
rm -rf "${TEMP_INSTALL_PATH}"
79+
clean_up
7780

7881
if [ -f "${TOOL_INSTALL_PATH}" ]; then
7982
log "" "${TOOL_NAME} successfully installed"

0 commit comments

Comments
 (0)