-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
144 lines (124 loc) · 4.88 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: 'Preternatural Build Action'
description: 'Run Preternatural build command on repositories with a specified Xcode version'
inputs:
xcode-version:
description: 'Xcode version to use'
required: false
default: '16.2'
platforms:
description: 'Target platforms (array of: iOS, macOS, tvOS, watchOS, visionOS, all)'
required: false
default: '["macOS"]'
configurations:
description: 'Build configurations (array of: debug, release)'
required: false
default: '["debug"]'
working-directory:
description: 'Directory to run the preternatural command from'
required: false
default: ''
fuck-swift-syntax:
description: 'Enable the --fuck-swift-syntax flag for the build command'
required: false
default: true
type: boolean
build-for-testing:
description: 'Build for testing'
required: false
default: false
type: boolean
runs:
using: 'composite'
steps:
- name: Setup Xcode
if: ${{ !env.ACT }}
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ inputs.xcode-version }}
- name: Check macOS Version
shell: bash
run: sw_vers
- name: Check Xcode Version
shell: bash
run: xcodebuild -version
- name: Check Available SDKs
shell: bash
run: xcodebuild -showsdks
- name: Install Preternatural
if: ${{ !env.ACT }}
shell: bash
run: |-
echo "::group::Installing Preternatural via Homebrew"
brew tap PreternaturalAI/preternatural
brew install preternatural
echo "::endgroup::"
- name: Restore DerivedData Cache
if: ${{ !env.ACT }}
uses: cirruslabs/cache/restore@v4
with:
path: "~/Library/Developer/Xcode/DerivedData"
key: ${{ runner.os }}-${{ github.repository }}-${{ github.workflow }}-${{ github.ref_name }}-derived-data-${{ hashFiles('**/*') }}
restore-keys: |
${{ runner.os }}-${{ github.repository }}-${{ github.workflow }}-${{ github.ref_name }}-derived-data
- name: Execute preternatural build command
continue-on-error: true
id: build
shell: bash
run: |-
echo "::group::Preparing Build Command"
PLATFORMS=$(echo '${{ inputs.platforms }}' | tr -d '[]' | sed 's/, /,/g')
CONFIGURATIONS=$(echo '${{ inputs.configurations }}' | tr -d '[]' | sed 's/, /,/g')
# Change directory if working-directory is provided
if [ ! -z "${{ inputs.working-directory }}" ]; then
cd "${{ inputs.working-directory }}"
echo "Changed working directory to: ${{ inputs.working-directory }}"
fi
# Construct the command as a string
PRETERNATURAL_CMD="script -q /dev/null preternatural build --platforms $PLATFORMS --configurations $CONFIGURATIONS --update-developer-team"
if [ "${{ inputs.build-for-testing }}" == "true" ]; then
PRETERNATURAL_CMD="$PRETERNATURAL_CMD --build-for-testing"
fi
if [ "${{ inputs.fuck-swift-syntax }}" == "true" ]; then
PRETERNATURAL_CMD="$PRETERNATURAL_CMD --fuck-swift-syntax"
fi
echo "Prepared command: ${PRETERNATURAL_CMD}"
echo "::endgroup::"
echo "::group::First Build Attempt"
# First attempt
set +e # Don't exit on error
eval ${PRETERNATURAL_CMD} 2>&1
BUILD_STATUS=$?
set -e # Return to exit on error
echo "::endgroup::"
if [ $BUILD_STATUS -ne 0 ]; then
echo "::group::Cleaning DerivedData and Retrying"
echo "First build attempt failed (status: $BUILD_STATUS). Cleaning derived data and retrying..."
rm -rf "$DERIVED_DATA_PATH"
echo "Cleaned derived data"
echo "::endgroup::"
echo "::group::Second Build Attempt"
# Second attempt
eval ${PRETERNATURAL_CMD} 2>&1
RETRY_STATUS=$?
echo "::endgroup::"
if [ $RETRY_STATUS -ne 0 ]; then
echo "::error::Second build attempt failed (status: $RETRY_STATUS) after cleaning derived data. Failing the workflow."
exit 1
fi
fi
echo "build_succeeded=true" >> $GITHUB_OUTPUT
- name: Upload logs
if: ${{ !env.ACT }}
uses: PreternaturalAI/preternatural-github-actions/preternatural-upload-logs@main
- name: Save DerivedData Cache
if: ${{ steps.build.outputs.build_succeeded == 'true' && env.ACT != 'true' }}
uses: cirruslabs/cache/save@v4
with:
path: "~/Library/Developer/Xcode/DerivedData"
key: ${{ runner.os }}-${{ github.repository }}-${{ github.workflow }}-${{ github.ref_name }}-derived-data-${{ hashFiles('**/*') }}
- name: Check build status and fail if necessary
if: steps.build.outputs.build_succeeded != 'true'
shell: bash
run: |-
echo "::error::Build failed earlier in the workflow"
exit 1