Skip to content

Commit ac3f2ad

Browse files
Added build log artifacts for easier debugging of workflow issues
1 parent 86d9baa commit ac3f2ad

File tree

5 files changed

+148
-29
lines changed

5 files changed

+148
-29
lines changed

.github/workflows/carthage.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ jobs:
1515
build:
1616
name: Build
1717
runs-on: macOS-latest
18+
env:
19+
LOGFILE: /tmp/.keyvalueobservation.carthage.xcodebuild.log
20+
1821
steps:
1922
- name: Checkout Code
2023
uses: actions/checkout@v2
2124

25+
- name: Setup Environment
26+
run |
27+
touch "$LOGFILE"
28+
2229
- name: Install Carthage
2330
run: |
2431
brew update
@@ -34,4 +41,11 @@ jobs:
3441
3542
- name: Build
3643
run: |
37-
./scripts/carthage.sh update
44+
./scripts/carthage.sh update --log-path "$LOGFILE"
45+
46+
- name: Upload Logs
47+
uses: actions/upload-artifact@v2
48+
if: always()
49+
with:
50+
name: BuildLog
51+
path: ${{ env.LOGFILE }}

.github/workflows/cocoapods.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ jobs:
2020
name: Lint
2121
runs-on: macOS-latest
2222
env:
23+
LOGSDIR: /tmp/.keyvalueobservation.cocoapods/Logs
2324
LINT_TYPE: ${{ matrix.linttype }}
2425

2526
steps:
2627
- name: Checkout Code
2728
uses: actions/checkout@v2
2829

30+
- name Setup Environment
31+
run: |
32+
mkdir -p "$LOGSDIR"
33+
2934
- name: Setup Cocoapods
3035
uses: maxim-lobanov/setup-cocoapods@v1
3136
with:
@@ -34,7 +39,14 @@ jobs:
3439
- name: Lint
3540
run: |
3641
if [ "$LINT_TYPE" == "Dynamic" ]; then
37-
pod lib lint
42+
pod lib lint --verbose 2>&1 | tee "$LOGSDIR/PodLint-$LINT_TYPE.log"
3843
else
39-
pod lib lint --use-libraries
44+
pod lib lint --verbose --use-libraries 2>&1 | tee "$LOGSDIR/PodLint-$LINT_TYPE.log"
4045
fi
46+
47+
- name: Upload Logs
48+
uses: actions/upload-artifact@v2
49+
if: always()
50+
with:
51+
name: Logs
52+
path: ${{ env.LOGSDIR }}/*.log

.github/workflows/xcframework.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,11 @@ jobs:
2424

2525
- name: Build
2626
run: |
27-
./scripts/xcframework.sh --output ${TMPDIR}/KeyValueObservation.xcframework
27+
./scripts/xcframework.sh --build-dir "$TMPDIR"
28+
29+
- name: Upload Logs
30+
uses: actions/upload-artifact@v2
31+
if: always()
32+
with:
33+
name: BuildLogs
34+
path: ${{ env.TMPDIR }}/Logs/*.log

.github/workflows/xcodebuild.yml

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@ jobs:
1515
ios:
1616
name: iOS
1717
runs-on: macOS-latest
18+
env:
19+
LOGSDIR: /tmp/.keyvalueobservation.xcodebuild/iOS/Logs
1820

1921
steps:
2022
- name: Checkout Code
2123
uses: actions/checkout@v2
2224

25+
- name Setup Environment
26+
run: |
27+
mkdir -p "$LOGSDIR"
28+
2329
- name: Build iOS
2430
run: |
25-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation" -destination "generic/platform=iOS" -configuration Debug
31+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation" -destination "generic/platform=iOS" -configuration Debug 2>&1 | tee "$LOGSDIR/build-ios.log"
2632
2733
- name: Build iOS Simulator
2834
run: |
29-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation" -destination "generic/platform=iOS Simulator" -configuration Debug
35+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation" -destination "generic/platform=iOS Simulator" -configuration Debug 2>&1 | tee "$LOGSDIR/build-iossimulator.log"
3036
3137
- name: Test
3238
run: |
@@ -35,39 +41,65 @@ jobs:
3541
IOS_SIM = "iPhone 12 Pro" # Fallback Simulator
3642
fi
3743
38-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation" -testPlan "KeyValueObservationTests" -destination "platform=iOS Simulator,name=$IOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test
44+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation" -testPlan "KeyValueObservationTests" -destination "platform=iOS Simulator,name=$IOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test 2>&1 | tee "$LOGSDIR/test-ios.log"
45+
46+
- name: Upload Logs
47+
uses: actions/upload-artifact@v2
48+
if: always()
49+
with:
50+
name: iOSBuildLogs
51+
path: ${{ env.LOGSDIR }}/*.log
3952

4053
maccatalyst:
4154
name: Mac Catalyst
4255
runs-on: macOS-latest
56+
env:
57+
LOGSDIR: /tmp/.keyvalueobservation.xcodebuild/macCatalyst/Logs
4358

4459
steps:
4560
- name: Checkout Code
4661
uses: actions/checkout@v2
4762

63+
- name Setup Environment
64+
run: |
65+
mkdir -p "$LOGSDIR"
66+
4867
- name: Build
4968
run: |
50-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation" -destination "generic/platform=macOS,variant=Mac Catalyst" -configuration Debug
69+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation" -destination "generic/platform=macOS,variant=Mac Catalyst" -configuration Debug 2>&1 | tee "$LOGSDIR/build-maccatalyst.log"
5170
5271
- name: Test
5372
run: |
54-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation" -testPlan "KeyValueObservationTests" -destination "platform=macOS,variant=Mac Catalyst" -configuration Debug ONLY_ACTIVE_ARCH=YES test
73+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation" -testPlan "KeyValueObservationTests" -destination "platform=macOS,variant=Mac Catalyst" -configuration Debug ONLY_ACTIVE_ARCH=YES test 2>&1 | tee "$LOGSDIR/test-maccatalyst.log"
74+
75+
- name: Upload Logs
76+
uses: actions/upload-artifact@v2
77+
if: always()
78+
with:
79+
name: MacCatalystBuildLogs
80+
path: ${{ env.LOGSDIR }}/*.log
5581

5682
macos:
5783
name: macOS
5884
runs-on: macOS-latest
85+
env:
86+
LOGSDIR: /tmp/.keyvalueobservation.xcodebuild/macOS/Logs
5987

6088
steps:
6189
- name: Checkout Code
6290
uses: actions/checkout@v2
6391

92+
- name Setup Environment
93+
run: |
94+
mkdir -p "$LOGSDIR"
95+
6496
- name: Build
6597
run: |
66-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation macOS" -destination "generic/platform=macOS" -configuration Debug
98+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation macOS" -destination "generic/platform=macOS" -configuration Debug 2>&1 | tee "$LOGSDIR/build-macos.log"
6799
68100
- name: Test
69101
run: |
70-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation macOS" -testPlan "KeyValueObservation macOS Tests" -derivedDataPath ".xcodebuild" -configuration Debug ONLY_ACTIVE_ARCH=YES test
102+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation macOS" -testPlan "KeyValueObservation macOS Tests" -derivedDataPath ".xcodebuild" -configuration Debug ONLY_ACTIVE_ARCH=YES test 2>&1 | tee "$LOGSDIR/test-macos.log"
71103
72104
- name: Generate Code Coverage File
73105
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
@@ -84,21 +116,34 @@ jobs:
84116
file: ./codecov.lcov
85117
verbose: true
86118

119+
- name: Upload Logs
120+
uses: actions/upload-artifact@v2
121+
if: always()
122+
with:
123+
name: macOSBuildLogs
124+
path: ${{ env.LOGSDIR }}/*.log
125+
87126
tvos:
88127
name: tvOS
89128
runs-on: macOS-latest
129+
env:
130+
LOGSDIR: /tmp/.keyvalueobservation.xcodebuild/tvOS/Logs
90131

91132
steps:
92133
- name: Checkout Code
93134
uses: actions/checkout@v2
94135

136+
- name Setup Environment
137+
run: |
138+
mkdir -p "$LOGSDIR"
139+
95140
- name: Build tvOS
96141
run: |
97-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation tvOS" -destination "generic/platform=tvOS" -configuration Debug
142+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation tvOS" -destination "generic/platform=tvOS" -configuration Debug 2>&1 | tee "$LOGSDIR/build-tvos.log"
98143
99144
- name: Build tvOS Simulator
100145
run: |
101-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation tvOS" -destination "generic/platform=tvOS Simulator" -configuration Debug
146+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation tvOS" -destination "generic/platform=tvOS Simulator" -configuration Debug 2>&1 | tee "$LOGSDIR/build-tvossimulator.log"
102147
103148
- name: Test
104149
run: |
@@ -107,23 +152,36 @@ jobs:
107152
TVOS_SIM = "Apple TV" # Fallback Simulator
108153
fi
109154
110-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation tvOS" -testPlan "KeyValueObservation tvOS Tests" -destination "platform=tvOS Simulator,name=$TVOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test
155+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation tvOS" -testPlan "KeyValueObservation tvOS Tests" -destination "platform=tvOS Simulator,name=$TVOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test 2>&1 | tee "$LOGSDIR/test-tvos.log"
156+
157+
- name: Upload Logs
158+
uses: actions/upload-artifact@v2
159+
if: always()
160+
with:
161+
name: tvOSBuildLogs
162+
path: ${{ env.LOGSDIR }}/*.log
111163

112164
watchos:
113165
name: watchOS
114166
runs-on: macOS-11
167+
env:
168+
LOGSDIR: /tmp/.keyvalueobservation.xcodebuild/watchOS/Logs
115169

116170
steps:
117171
- name: Checkout Code
118172
uses: actions/checkout@v2
119173

174+
- name Setup Environment
175+
run: |
176+
mkdir -p "$LOGSDIR"
177+
120178
- name: Build watchOS
121179
run: |
122-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation watchOS" -destination "generic/platform=watchOS" -configuration Debug
180+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation watchOS" -destination "generic/platform=watchOS" -configuration Debug 2>&1 | tee "$LOGSDIR/build-watchos.log"
123181
124182
- name: Build watchOS Simulator
125183
run: |
126-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation watchOS" -destination "generic/platform=watchOS Simulator" -configuration Debug
184+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation watchOS" -destination "generic/platform=watchOS Simulator" -configuration Debug 2>&1 | tee "$LOGSDIR/build-watchossimulator.log"
127185
128186
- name: Test
129187
run: |
@@ -132,4 +190,11 @@ jobs:
132190
WATCHOS_SIM = "Apple Watch Series 6 - 44mm" # Fallback Simulator
133191
fi
134192
135-
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation watchOS" -testPlan "KeyValueObservation watchOS Tests" -destination "platform=watchOS Simulator,name=$WATCHOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test
193+
xcodebuild -project KeyValueObservation.xcodeproj -scheme "KeyValueObservation watchOS" -testPlan "KeyValueObservation watchOS Tests" -destination "platform=watchOS Simulator,name=$WATCHOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test 2>&1 | tee "$LOGSDIR/test-watchos.log"
194+
195+
- name: Upload Logs
196+
uses: actions/upload-artifact@v2
197+
if: always()
198+
with:
199+
name: watchOSBuildLogs
200+
path: ${{ env.LOGSDIR }}/*.log

scripts/xcframework.sh

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function printhelp() {
2020
HELP+="xcframework.sh [--help | -h] [--output (<output_framework> | <output_folder>)]\n"
2121
HELP+=" [--configuration <configuration>] [--project-name <project_name>]\n"
2222
HELP+=" [--exclude-dsyms] [--verbose] [--no-clean | --no-clean-on-fail]\n"
23+
HELP+=" [--build-dir <build_dir>]\n"
2324
HELP+="\n"
2425
HELP+="--help, -h) Print this help message and exit.\n"
2526
HELP+="\n"
@@ -48,6 +49,11 @@ function printhelp() {
4849
HELP+="--no-clean-on-fail) Same as --no-clean with the exception that if the succeed\n"
4950
HELP+=" clean up will continue as normal. This is mutually exclusive\n"
5051
HELP+=" with --no-clean, with --no-clean taking precedence.\n"
52+
HELP+="\n"
53+
HELP+="--build-dir) The directory in which to store temporary build artifacts\n"
54+
HELP+=" and logs. The directory will be created if needed. If\n"
55+
HELP+=" specified this directory will not be deleted when the\n"
56+
HELP+=" script finishes running.\n"
5157

5258
IFS='%'
5359
echo -e $HELP 1>&2
@@ -93,6 +99,12 @@ while [[ $# -gt 0 ]]; do
9399
shift # --no-clean-on-fail
94100
;;
95101

102+
--build-dir)
103+
BUILD_DIR="$2"
104+
shift # --build-dir
105+
shift # <build_dir>
106+
;;
107+
96108
--verbose)
97109
VERBOSE=1
98110
shift # --verbose
@@ -139,20 +151,29 @@ if [ -z ${CONFIGURATION+x} ]; then
139151
CONFIGURATION="Release"
140152
fi
141153

142-
# Create Temporary Directory
154+
if [ -z ${BUILD_DIR+x} ]; then
155+
BUILD_DIR="$(mktemp -d -t ".$(echo "$PROJECT_NAME" | tr '[:upper:]' '[:lower:]').xcframework.build")"
156+
BUILD_DIR_IS_TEMP=1
157+
else
158+
mkdir -p "$BUILD_DIR"
159+
EXIT_CODE=$?
143160

144-
TEMP_DIR="$(mktemp -d -t ".$(echo "$PROJECT_NAME" | tr '[:upper:]' '[:lower:]').xcframework.build")"
161+
if [ "$EXIT_CODE" != "0" ]; then
162+
"$SCRIPTS_DIR/printformat.sh" "foreground:red" "Unable to create build directory: $BUILD_DIR"
163+
exit $EXIT_CODE
164+
fi
165+
fi
145166

146167
# Function Declarations
147168

148169
function cleanup() {
149170
cd "$CURRENT_DIR"
150-
if [[ "$VERBOSE" != "1" && ("$NO_CLEAN" == "1" || ("$NO_CLEAN_ON_FAIL" == "1" && "$EXIT_CODE" != "0")) ]]; then
171+
if [[ "$VERBOSE" != "1" && "$BUILD_DIR_IS_TEMP" == "1" && ("$NO_CLEAN" == "1" || ("$NO_CLEAN_ON_FAIL" == "1" && "$EXIT_CODE" != "0")) ]]; then
151172
if [ "$EXIT_CODE" == "0" ]; then
152-
"$SCRIPTS_DIR/printformat.sh" "foreground:yellow" "Build Directory: $TEMP_DIR"
173+
"$SCRIPTS_DIR/printformat.sh" "foreground:yellow" "Build Directory: $BUILD_DIR"
153174
fi
154-
else
155-
rm -rf "$TEMP_DIR"
175+
elif [ "$BUILD_DIR_IS_TEMP" == "1" ]; then
176+
rm -rf "$BUILD_DIR"
156177
fi
157178

158179
#
@@ -176,11 +197,11 @@ function checkresult() {
176197
}
177198

178199
function createlogfile() {
179-
if [ ! -d "$TEMP_DIR/Logs" ]; then
180-
mkdir -p "$TEMP_DIR/Logs"
200+
if [ ! -d "$BUILD_DIR/Logs" ]; then
201+
mkdir -p "$BUILD_DIR/Logs"
181202
fi
182203

183-
local LOG="$TEMP_DIR/Logs/$1.log"
204+
local LOG="$BUILD_DIR/Logs/$1.log"
184205
touch "$LOG"
185206

186207
echo "$LOG"
@@ -264,14 +285,14 @@ for PLATFORM in "iOS" "iOS Simulator" "Mac Catalyst" "macOS" "tvOS" "tvOS Simula
264285
#
265286

266287
if [ "$VERBOSE" == "1" ]; then
267-
xcodebuild -project "${PROJECT_NAME}.xcodeproj" -scheme "$SCHEME" -destination "generic/platform=$PLATFORM" -archivePath "${TEMP_DIR}/$ARCHIVE.xcarchive" -configuration ${CONFIGURATION} SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="$ARCHS" archive
288+
xcodebuild -project "${PROJECT_NAME}.xcodeproj" -scheme "$SCHEME" -destination "generic/platform=$PLATFORM" -archivePath "${BUILD_DIR}/$ARCHIVE.xcarchive" -configuration ${CONFIGURATION} SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="$ARCHS" archive
268289
else
269290
LOG="$(createlogfile "$ARCHIVE-build")"
270291
ERROR_MESSAGE="$(errormessage "$LOG")"
271292

272293
#
273294

274-
xcodebuild -project "${PROJECT_NAME}.xcodeproj" -scheme "$SCHEME" -destination "generic/platform=$PLATFORM" -archivePath "${TEMP_DIR}/$ARCHIVE.xcarchive" -configuration ${CONFIGURATION} SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="$ARCHS" archive > "$LOG" 2>&1
295+
xcodebuild -project "${PROJECT_NAME}.xcodeproj" -scheme "$SCHEME" -destination "generic/platform=$PLATFORM" -archivePath "${BUILD_DIR}/$ARCHIVE.xcarchive" -configuration ${CONFIGURATION} SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="$ARCHS" archive > "$LOG" 2>&1
275296
fi
276297

277298
checkresult $? "$ERROR_MESSAGE"
@@ -285,7 +306,7 @@ fi
285306

286307
ARGUMENTS=(-create-xcframework -output "${OUTPUT}")
287308

288-
for ARCHIVE in ${TEMP_DIR}/*.xcarchive; do
309+
for ARCHIVE in ${BUILD_DIR}/*.xcarchive; do
289310
ARGUMENTS=(${ARGUMENTS[@]} -framework "${ARCHIVE}/Products/Library/Frameworks/${PROJECT_NAME}.framework")
290311

291312
if [ "$EXCLUDE_DSYMS" != "1" ]; then

0 commit comments

Comments
 (0)