Skip to content

Commit 0dd3e71

Browse files
authored
Lock access to keyPathToName in key path printing. (#76)
* Lock access to keyPathToName for key path printing. * slack release * modernize
1 parent adef407 commit 0dd3e71

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
- '*'
1010
workflow_dispatch:
1111

12+
concurrency:
13+
group: ci-${{ github.ref }}
14+
cancel-in-progress: true
15+
1216
jobs:
1317
macos:
1418
name: macOS (Xcode ${{ matrix.xcode }})

.github/workflows/documentation.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
- published
66
workflow_dispatch:
77

8+
concurrency:
9+
group: documentation-${{ github.ref }}
10+
cancel-in-progress: true
11+
812
jobs:
913
build:
1014
runs-on: ubuntu-latest

.github/workflows/format.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
branches:
66
- main
77

8+
concurrency:
9+
group: format-${{ github.ref }}
10+
cancel-in-progress: true
11+
812
jobs:
913
swift_format:
1014
name: swift-format

.github/workflows/release.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Release
2+
on:
3+
release:
4+
types: [published]
5+
workflow_dispatch:
6+
jobs:
7+
project-channel:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Dump Github context
11+
env:
12+
GITHUB_CONTEXT: ${{ toJSON(github) }}
13+
run: echo "$GITHUB_CONTEXT"
14+
- name: Slack Notification on SUCCESS
15+
if: success()
16+
uses: tokorom/action-slack-incoming-webhook@main
17+
env:
18+
INCOMING_WEBHOOK_URL: ${{ secrets.SLACK_PROJECT_CHANNEL_WEBHOOK_URL }}
19+
with:
20+
text: swift-custom-dump ${{ github.event.release.tag_name }} has been released.
21+
blocks: |
22+
[
23+
{
24+
"type": "header",
25+
"text": {
26+
"type": "plain_text",
27+
"text": "swift-custom-dump ${{ github.event.release.tag_name}}"
28+
}
29+
},
30+
{
31+
"type": "section",
32+
"text": {
33+
"type": "mrkdwn",
34+
"text": ${{ toJSON(github.event.release.body) }}
35+
}
36+
},
37+
{
38+
"type": "section",
39+
"text": {
40+
"type": "mrkdwn",
41+
"text": "${{ github.event.release.html_url }}"
42+
}
43+
}
44+
]
45+
46+
releases-channel:
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Dump Github context
50+
env:
51+
GITHUB_CONTEXT: ${{ toJSON(github) }}
52+
run: echo "$GITHUB_CONTEXT"
53+
- name: Slack Notification on SUCCESS
54+
if: success()
55+
uses: tokorom/action-slack-incoming-webhook@main
56+
env:
57+
INCOMING_WEBHOOK_URL: ${{ secrets.SLACK_RELEASES_WEBHOOK_URL }}
58+
with:
59+
text: swift-custom-dump ${{ github.event.release.tag_name }} has been released.
60+
blocks: |
61+
[
62+
{
63+
"type": "header",
64+
"text": {
65+
"type": "plain_text",
66+
"text": "swift-custom-dump ${{ github.event.release.tag_name}}"
67+
}
68+
},
69+
{
70+
"type": "section",
71+
"text": {
72+
"type": "mrkdwn",
73+
"text": ${{ toJSON(github.event.release.body) }}
74+
}
75+
},
76+
{
77+
"type": "section",
78+
"text": {
79+
"type": "mrkdwn",
80+
"text": "${{ github.event.release.html_url }}"
81+
}
82+
}
83+
]

Sources/CustomDump/Conformances/KeyPath.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Foundation
2+
13
extension AnyKeyPath: CustomDumpStringConvertible {
24
public var customDumpDescription: String {
35
#if swift(>=5.8)
@@ -6,6 +8,9 @@ extension AnyKeyPath: CustomDumpStringConvertible {
68
}
79
#endif
810
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
11+
keyPathToNameLock.lock()
12+
defer { keyPathToNameLock.unlock() }
13+
914
guard let name = keyPathToName[self] else {
1015
func reflectName() -> String {
1116
var namedKeyPaths = Reflection.allNamedKeyPaths(forUnderlyingTypeOf: Self.rootType)
@@ -36,6 +41,7 @@ extension AnyKeyPath: CustomDumpStringConvertible {
3641
}
3742

3843
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
44+
private var keyPathToNameLock = NSRecursiveLock()
3945
private var keyPathToName: [AnyKeyPath: String] = [:]
4046

4147
// The source code below was extracted from the "KeyPath Reflection" branch of Apple's

0 commit comments

Comments
 (0)