diff --git a/preternatural-build/action.yml b/preternatural-build/action.yml index 90a6557..b4a5961 100644 --- a/preternatural-build/action.yml +++ b/preternatural-build/action.yml @@ -16,7 +16,7 @@ inputs: derived_data_path: description: 'The path to the derived data folder' required: false - default: DerivedData/ProjectBuild + default: "preternatural-derived-data" runs: using: 'composite' @@ -33,14 +33,52 @@ runs: brew tap PreternaturalAI/preternatural brew install preternatural + - name: Restore DerivedData Cache + uses: actions/cache/restore@v4 + with: + path: "~/preternatural-derived-data" + key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data + - name: Execute preternatural build command + id: build shell: bash run: | PLATFORMS=$(echo '${{ inputs.platforms }}' | tr -d '[]' | sed 's/, /,/g') CONFIGURATIONS=$(echo '${{ inputs.configurations }}' | tr -d '[]' | sed 's/, /,/g') - DERIVED_DATA_PATH=${{ github.workspace }}/${{ inputs.derived_data_path }} + DERIVED_DATA_PATH=$HOME/${{ inputs.derived_data_path }} + + # Construct the command as a string + PRETERNATURAL_CMD="script -q /dev/null preternatural build --derived-data-path \"$DERIVED_DATA_PATH\" --platforms $PLATFORMS --configurations $CONFIGURATIONS" + + echo "Running preternatural build command:" + echo "${PRETERNATURAL_CMD}" + + # First attempt + set +e # Don't exit on error + eval ${PRETERNATURAL_CMD} 2>&1 + BUILD_STATUS=$? + set -e # Return to exit on error - preternatural build \ - --derived-data-path "$DERIVED_DATA_PATH" \ - --platforms "$PLATFORMS" \ - --configurations "$CONFIGURATIONS" + if [ $BUILD_STATUS -ne 0 ]; then + echo "First build attempt failed (status: $BUILD_STATUS). Cleaning derived data and retrying..." + rm -rf "$DERIVED_DATA_PATH" + echo "Cleaned derived data" + + # Second attempt + eval ${PRETERNATURAL_CMD} 2>&1 + RETRY_STATUS=$? + + if [ $RETRY_STATUS -ne 0 ]; then + echo "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: Save DerivedData Cache + if: steps.build.outputs.build_succeeded == 'true' + uses: actions/cache/save@v4 + with: + path: "~/preternatural-derived-data" + key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data