Skip to content

Commit 8620043

Browse files
committed
Fix swift-format workflow with best practices
- Add ref parameter to checkout to address detached HEAD warning - Add git safe.directory configuration - Replace cache with separate cache/restore and cache/save steps - Use static cache key instead of dynamic hashFiles key - Fixes deprecation warnings and improves reliability
1 parent c559ee9 commit 8620043

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

.github/workflows/swift-format.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,25 @@ jobs:
1717
contents: write
1818
steps:
1919
- uses: actions/checkout@v5
20+
with:
21+
ref: ${{ github.head_ref || github.ref_name }}
22+
23+
- name: Configure git safe directory
24+
run: git config --global --add safe.directory $PWD
2025

2126
- uses: swift-actions/setup-swift@v2
2227
with:
2328
swift-version: '6.0'
2429

25-
- name: Cache swift-format
26-
id: cache-swift-format
27-
uses: actions/cache@v4
30+
- name: Restore swift-format cache
31+
id: cache-swift-format-restore
32+
uses: actions/cache/restore@v4
2833
with:
2934
path: .build/swift-format
30-
key: ${{ runner.os }}-swift-format-${{ hashFiles('.github/workflows/swift-format.yml') }}
35+
key: ${{ runner.os }}-swift-format-main-v1
3136

3237
- name: Build swift-format
33-
if: steps.cache-swift-format.outputs.cache-hit != 'true'
38+
if: steps.cache-swift-format-restore.outputs.cache-hit != 'true'
3439
run: |
3540
git clone --depth 1 --branch main https://github.com/apple/swift-format.git
3641
cd swift-format
@@ -47,3 +52,10 @@ jobs:
4752
with:
4853
commit_message: Run swift-format
4954
branch: 'main'
55+
56+
- name: Save swift-format cache
57+
uses: actions/cache/save@v4
58+
if: steps.cache-swift-format-restore.outputs.cache-hit != 'true'
59+
with:
60+
path: .build/swift-format
61+
key: ${{ runner.os }}-swift-format-main-v1

0 commit comments

Comments
 (0)