From 87f1f58313f5c47778141409b3e056b02406b18d Mon Sep 17 00:00:00 2001 From: Paul Schmiedmayer Date: Sat, 25 Feb 2023 14:56:44 -0800 Subject: [PATCH] Self-Hosted Github Action Runner Detection & Make Caching Configurable (#6) --- .github/workflows/xcodebuild-or-fastlane.yml | 33 +++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/.github/workflows/xcodebuild-or-fastlane.yml b/.github/workflows/xcodebuild-or-fastlane.yml index 637daa0..b918b8f 100644 --- a/.github/workflows/xcodebuild-or-fastlane.yml +++ b/.github/workflows/xcodebuild-or-fastlane.yml @@ -20,7 +20,7 @@ on: description: 'JSON-based collection of labels indicating which type of github runner should be chosen' required: false type: string - default: '["macos-12"]' + default: '["macos-latest"]' scheme: description: 'The scheme in the Xcode project. Either use `scheme` to use xcodebuild, `fastlanelane` to use fastlane, or a custom command using `customcommand`' required: false @@ -46,6 +46,11 @@ on: required: false type: boolean default: false + cacheDerivedData: + description: 'Cache the derived data folder for a build using xcodebuild' + required: false + type: boolean + default: false setupfirebaseemulator: description: 'Setup the Firebase Emulator' required: false @@ -62,21 +67,19 @@ jobs: steps: - uses: actions/checkout@v3 - uses: maxim-lobanov/setup-xcode@v1 - if: "!contains(inputs.runsonlabels, 'self-hosted')" + if: "!env.selfhosted" with: xcode-version: latest-stable - name: Check environment run: | xcodebuild -version swift --version - echo "inputs.path: ${{ inputs.path }}" - echo "inputs.runsonlabels: ${{ inputs.runsonlabels }}" - echo "inputs.scheme: ${{ inputs.scheme }}" - echo "inputs.setupsigning: ${{ inputs.setupsigning }}" + echo "env.selfhosted: ${{ env.selfhosted }}" - name: Install xcpretty - if: "!contains(inputs.runsonlabels, 'self-hosted') && inputs.scheme != ''" + if: "!env.selfhosted && inputs.scheme != ''" run: gem install xcpretty - name: Cache .derivedData folder + if: "inputs.cacheDerivedData" uses: actions/cache@v3 with: path: .derivedData @@ -84,22 +87,22 @@ jobs: restore-keys: | ${{ runner.os }}-${{ runner.arch }}-derivedData- - name: Cache Firebase Emulators - if: "!contains(inputs.runsonlabels, 'self-hosted') && inputs.setupfirebaseemulator" + if: "!env.selfhosted && inputs.setupfirebaseemulator" uses: actions/cache@v3 with: path: ~/.cache/firebase/emulators key: ${{ runner.os }}-${{ runner.arch }}-firebase-emulators-${{ hashFiles('~/.cache/firebase/emulators/**') }} - name: Setup NodeJS - if: "!contains(inputs.runsonlabels, 'self-hosted') && inputs.setupfirebaseemulator" + if: "!env.selfhosted && inputs.setupfirebaseemulator" uses: actions/setup-node@v3 - name: Setup Java - if: "!contains(inputs.runsonlabels, 'self-hosted') && inputs.setupfirebaseemulator" + if: "!env.selfhosted && inputs.setupfirebaseemulator" uses: actions/setup-java@v3 with: distribution: 'microsoft' java-version: '17' - name: Install Firebase CLI Tools - if: "!contains(inputs.runsonlabels, 'self-hosted') && inputs.setupfirebaseemulator" + if: "!env.selfhosted && inputs.setupfirebaseemulator" run: npm install -g firebase-tools - name: Install the Apple certificate and provisioning profile if: ${{ inputs.setupsigning }} @@ -115,8 +118,8 @@ jobs: KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db # import certificate and provisioning profile from secrets - echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode --output $CERTIFICATE_PATH - echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode --output $PP_PATH + echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH + echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode -o $PP_PATH # create temporary keychain security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH @@ -156,7 +159,7 @@ jobs: | xcpretty - name: Fastlane if: ${{ inputs.fastlanelane != '' }} - run: bundler install && bundle exec fastlane ${{ inputs.fastlanelane }} + run: fastlane ${{ inputs.fastlanelane }} env: APP_STORE_CONNECT_API_KEY_ID: ${{ secrets.APP_STORE_CONNECT_API_KEY_ID }} APP_STORE_CONNECT_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_ISSUER_ID }} @@ -169,7 +172,7 @@ jobs: name: ${{ inputs.artifactname }} path: ${{ inputs.artifactname }} - name: Clean up keychain and provisioning profile - if: "(inputs.setupsigning && contains(inputs.runsonlabels, 'self-hosted')) || failure()" + if: "(inputs.setupsigning && env.selfhosted) || failure()" run: | security delete-keychain $RUNNER_TEMP/app-signing.keychain-db rm ~/Library/MobileDevice/Provisioning\ Profiles/build_pp.mobileprovision