Skip to content

Commit

Permalink
Improved structure and cache handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis committed Nov 22, 2024
1 parent 8d3a18c commit f0632a1
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 268 deletions.
20 changes: 15 additions & 5 deletions .github/actions/bootstrap/action.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
name: 'Bootstrap'
description: 'Run bootstrap.sh'

input:
parent:
description: 'Optional input for job dependencies'
required: false

runs:
using: "composite"
steps:

- run: echo "IMAGE=${ImageOS}-${ImageVersion}" >> $GITHUB_ENV
shell: bash

- run: echo "$HOME/.mint/bin" >> $GITHUB_PATH
shell: bash

- name: Cache Mint
uses: actions/cache@v4
id: mint-cache
with:
path: ~/.mint
key: ${{ env.IMAGE }}-mint-${{ hashFiles('**/Mintfile') }}
restore-keys: ${{ env.IMAGE }}-mint-

- name: Cache brew
uses: actions/cache@v4
id: brew-cache
Expand All @@ -27,13 +37,13 @@ runs:
restore-keys: ${{ env.IMAGE }}-brew-
- uses: ./.github/actions/ruby-cache
- uses: ./.github/actions/python-cache
- uses: irgaly/xcode-cache@v1

- name: Xcode Cache
uses: ./.github/actions/dynamic-xcode-cache
with:
key: xcode-cache-deriveddata-${{ github.workflow }}-${{ github.sha }}
restore-keys:
xcode-cache-deriveddata-${{ github.workflow }}-${{ github.sha }}
xcode-cache-deriveddata-${{ github.workflow }}-${{ github.event.number }}
deriveddata-directory: derived_data
sourcepackages-directory: spm_cache
parent: ${{ inputs.parent }}

- run: ./Scripts/bootstrap.sh
shell: bash
43 changes: 43 additions & 0 deletions .github/actions/build-xcframework/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# .github/actions/build-xcframework/action.yml
name: 'Build XCFramework'
description: 'Build an XCFramework using the specified scheme'

inputs:
parent:
description: 'The parent job to use for building the XCFramework'
required: true
scheme:
description: 'The scheme to use for building the XCFramework'
required: true
match_password:
description: 'The password for match'
required: true
appstore_api_key:
description: 'The API key for App Store'
required: true

runs:
using: "composite"
steps:

- name: Checkout repository
uses: actions/[email protected]

- name: Cache Ruby Gems
uses: ./.github/actions/ruby-cache

- name: Cache Xcode Derived Data
uses: irgaly/xcode-cache@v1
with:
key: xcode-15-cache-deriveddata-${{ github.workflow }}-${{ github.sha }}-${{ inputs.scheme }}
restore-keys: |
xcode-15-cache-deriveddata-${{ github.workflow }}-${{ github.event.number }}"-${{ inputs.parent }}
xcode-15-cache-deriveddata-${{ github.workflow }}-${{ github.sha }}-${{ inputs.scheme }}
deriveddata-directory: derived_data
sourcepackages-directory: spm_cache

- name: Build XCFramework
run: bundle exec fastlane build_xcframeworks_concurrent scheme:"${{ inputs.scheme }}"
env:
MATCH_PASSWORD: ${{ inputs.match_password }}
APPSTORE_API_KEY: ${{ inputs.appstore_api_key }}
37 changes: 37 additions & 0 deletions .github/actions/dynamic-xcode-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# .github/actions/dynamic-xcode-cache/action.yml
name: 'Dynamic Xcode Cache'
description: 'Set cache key based on job dependencies and cache Xcode derived data'

inputs:
deriveddata-directory:
description: 'Directory for derived data'
required: true
sourcepackages-directory:
description: 'Directory for source packages'
required: true
parent:
description: 'Optional input for job dependencies'
required: false

runs:
using: "composite"
steps:
- name: Set Cache Key
id: set-cache-key
run: |
if [ -n "${{ inputs.parent }}" ]; then
echo "RESTORE_CACHE_KEY=xcode-cache-deriveddata-${{ github.workflow }}-${{ github.sha }}-${{ inputs.parent }}" >> $GITHUB_ENV
else
echo "RESTORE_CACHE_KEY=xcode-cache-deriveddata-${{ github.workflow }}-${{ github.event.number }}" >> $GITHUB_ENV
fi
shell: bash

- name: Cache Xcode Derived Data
uses: irgaly/xcode-cache@v1
with:
key: xcode-cache-deriveddata-${{ github.workflow }}-${{ github.sha }}-${{ github.job }}
restore-keys: |
${{ env.RESTORE_CACHE_KEY }}
deriveddata-directory: derived_data # enable reading it from the input
sourcepackages-directory: spm_cache # enable reading it from the input

68 changes: 68 additions & 0 deletions .github/actions/failure-handling/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# .github/actions/failure-handling/action.yml
name: 'Failure Handling'
description: 'Handle failure steps including uploading artifacts, sending Slack notifications, and parsing xcresult logs'
inputs:
xcresult-basenames:
description: 'JSON array of base names to xcresult files'
required: true
slack-webhook-url:
description: 'The Slack webhook URL to send notifications to'
required: true

runs:
using: "composite"
steps:
- name: Install jq
run: |
if ! command -v jq &> /dev/null; then
brew install jq
fi
shell: bash

- name: Upload SDK Test Data
uses: actions/upload-artifact@v4
with:
name: SDK Test Data ${{ github.job }}
path: ~/Library/Logs/scan

- name: Send Slack notification
uses: 8398a7/action-slack@v3
if: ${{ github.event_name == 'push' && failure() }}
with:
status: ${{ job.status }}
text: "You shall not pass!"
job_name: ${{ github.job }}
fields: message,commit,author,action,workflow,job,took
env:
SLACK_WEBHOOK_URL: ${{ inputs.slack-webhook-url }}
MATRIX_CONTEXT: ${{ toJson(matrix) }}

# Do we need those?
- name: Install xcparse
run: |
brew install chargepoint/xcparse/xcparse
shell: bash

- name: Parse xcresult
run: |
echo '${{ inputs.xcresult-basenames }}' | jq -r '.[]' | while read basename; do
xcparse logs fastlane/test_output/${basename}.xcresult fastlane/test_output/logs/${basename}
done
shell: bash

- name: Prepare Test Data Content
if: failure()
run: |
PATHS=""
echo '${{ inputs.xcresult-basenames }}' | jq -r '.[]' | while read basename; do
PATHS="$PATHS fastlane/test_output/logs/${basename}/Diagnostics/**/*.txt fastlane/test_output/logs/${basename}/Diagnostics/simctl_diagnostics/DiagnosticReports/*"
done
echo "PATHS=$PATHS" >> $GITHUB_ENV
shell: bash

- name: Upload Test Data
uses: actions/upload-artifact@v4
if: failure()
with:
name: Test Data ${{ github.job }}
path: ${{ env.PATHS }}
Loading

0 comments on commit f0632a1

Please sign in to comment.