Skip to content

Commit 5a4d985

Browse files
🤖 CI: Add lint workflow
- Lints code using SwiftLint
1 parent c4b8565 commit 5a4d985

File tree

4 files changed

+149
-1
lines changed

4 files changed

+149
-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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ xcuserdata/
77
*.xcuserdatad
88
*.xcbkptlist
99
*.xcsettings
10+
*.xcscheme
1011
*.xcworkspacedata
1112
*.DS_Store
1213

13-
*SpotifyConfig.swift
14+
*.build

.swiftlint.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
included:
2+
- Sources
3+
4+
line_length:
5+
warning: 110
6+
error: 150
7+
ignores_comments: true
8+
9+
disabled_rules:
10+
- trailing_whitespace
11+
- trailing_comma
12+
- void_function_in_ternary
13+
14+
opt_in_rules:
15+
- array_init
16+
- attributes
17+
- closure_end_indentation
18+
- closure_spacing
19+
- collection_alignment
20+
- contains_over_filter_count
21+
- contains_over_filter_is_empty
22+
- contains_over_first_not_nil
23+
- discouraged_object_literal
24+
- empty_count
25+
- empty_string
26+
- empty_xctest_method
27+
- explicit_init
28+
- fallthrough
29+
- file_header
30+
- file_name
31+
- first_where
32+
- flatmap_over_map_reduce
33+
- identical_operands
34+
- joined_default_parameter
35+
- legacy_random
36+
- let_var_whitespace
37+
- last_where
38+
- literal_expression_end_indentation
39+
- lower_acl_than_parent
40+
- modifier_order
41+
- nimble_operator
42+
- nslocalizedstring_key
43+
- number_separator
44+
- object_literal
45+
- operator_usage_whitespace
46+
- overridden_super_call
47+
- override_in_extension
48+
- pattern_matching_keywords
49+
- private_action
50+
- private_outlet
51+
- prohibited_interface_builder
52+
- prohibited_super_call
53+
- quick_discouraged_call
54+
- quick_discouraged_focused_test
55+
- quick_discouraged_pending_test
56+
- reduce_into
57+
- redundant_nil_coalescing
58+
- redundant_type_annotation
59+
- single_test_class
60+
- sorted_first_last
61+
- sorted_imports
62+
- static_operator
63+
- strong_iboutlet
64+
- toggle_bool
65+
- unavailable_function
66+
- unneeded_parentheses_in_closure_argument
67+
- unowned_variable_capture
68+
- untyped_error_in_catch
69+
- vertical_parameter_alignment_on_call
70+
- xct_specific_matcher
71+
- yoda_condition
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)