Skip to content

Commit 4555aea

Browse files
🤖 CI: Add lint workflow
- Lints code using SwiftLint
1 parent 08c7918 commit 4555aea

File tree

4 files changed

+151
-1
lines changed

4 files changed

+151
-1
lines changed

.github/workflows/lint.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 🧹 Lint
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
types: [opened, synchronize]
7+
8+
# push:
9+
# Every push if left empty
10+
11+
jobs:
12+
13+
lint-code:
14+
runs-on: macos-latest
15+
16+
steps:
17+
- name: Check out code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.10'
24+
25+
- name: Check last commit for skip keyword
26+
run: python workflow_scripts/check_latest_commit_for_skip.py >> $GITHUB_ENV
27+
28+
- name: ⏩ SKIPPING REMAINING STEPS 👀
29+
if: env.should_skip == 'true'
30+
run: exit 0
31+
32+
- name: Set up Ruby
33+
if: env.should_skip == 'false'
34+
uses: ruby/setup-ruby@v1
35+
with:
36+
ruby-version: '3.3.5' # latest stable as of 2 November 2024
37+
38+
- name: Install SwiftLint
39+
if: env.should_skip == 'false'
40+
run: brew install swiftlint
41+
42+
- name: Lint code using SwiftLint
43+
if: env.should_skip == 'false'
44+
run: swiftlint --strict

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ xcuserdata/
1010
*.xcworkspacedata
1111
*.DS_Store
1212

13-
*SpotifyConfig.swift
13+
*.build

.swiftlint.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
included:
2+
- Sources
3+
4+
disabled_rules:
5+
- trailing_whitespace
6+
- trailing_comma
7+
- void_function_in_ternary
8+
# - force_cast
9+
10+
opt_in_rules:
11+
- anyobject_protocol
12+
- array_init
13+
- attributes
14+
- closure_end_indentation
15+
- closure_spacing
16+
- collection_alignment
17+
- contains_over_filter_count
18+
- contains_over_filter_is_empty
19+
- contains_over_first_not_nil
20+
- discouraged_object_literal
21+
- empty_count
22+
- empty_string
23+
- empty_xctest_method
24+
- explicit_init
25+
- fallthrough
26+
- file_header
27+
- file_name
28+
- first_where
29+
- flatmap_over_map_reduce
30+
- identical_operands
31+
- joined_default_parameter
32+
- legacy_random
33+
- let_var_whitespace
34+
- last_where
35+
- literal_expression_end_indentation
36+
- lower_acl_than_parent
37+
- modifier_order
38+
- nimble_operator
39+
- nslocalizedstring_key
40+
- number_separator
41+
- object_literal
42+
- operator_usage_whitespace
43+
- overridden_super_call
44+
- override_in_extension
45+
- pattern_matching_keywords
46+
- private_action
47+
- private_outlet
48+
- prohibited_interface_builder
49+
- prohibited_super_call
50+
- quick_discouraged_call
51+
- quick_discouraged_focused_test
52+
- quick_discouraged_pending_test
53+
- reduce_into
54+
- redundant_nil_coalescing
55+
- redundant_type_annotation
56+
- single_test_class
57+
- sorted_first_last
58+
- sorted_imports
59+
- static_operator
60+
- strong_iboutlet
61+
- toggle_bool
62+
- unavailable_function
63+
- unneeded_parentheses_in_closure_argument
64+
- unowned_variable_capture
65+
- untyped_error_in_catch
66+
- vertical_parameter_alignment_on_call
67+
- xct_specific_matcher
68+
- yoda_condition
69+
70+
# Customize line length settings
71+
line_length:
72+
warning: 110
73+
error: 150
74+
ignores_comments: true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import subprocess
2+
import sys
3+
4+
# Define the keyword that should skip the workflow
5+
SKIP_KEYWORDS = ["wip", "skip-ci", "no-build"]
6+
7+
# Function to get the latest commit message
8+
def get_latest_commit_message():
9+
try:
10+
# Use subprocess to run the git command and get the output
11+
commit_message = subprocess.check_output(
12+
["git", "log", "-1", "--pretty=%B"],
13+
text=True
14+
).strip()
15+
return commit_message
16+
except subprocess.CalledProcessError as e:
17+
print(f"Error getting commit message: {e}")
18+
sys.exit(1)
19+
20+
# Function to check if the commit message contains any skip keyword
21+
def contains_skip_keyword(commit_message, keywords):
22+
return any(keyword in commit_message for keyword in keywords)
23+
24+
# Main logic
25+
if __name__ == "__main__":
26+
commit_message = get_latest_commit_message()
27+
28+
# Output values that can be used in the workflow environment
29+
if contains_skip_keyword(commit_message, SKIP_KEYWORDS):
30+
print(f"should_skip={True}")
31+
else:
32+
print(f"should_skip={False}")

0 commit comments

Comments
 (0)