From 89a5839ffb12f0de33c1dc7292655351c686b69b Mon Sep 17 00:00:00 2001 From: Akshat Patel Date: Thu, 12 Dec 2024 19:26:54 +0530 Subject: [PATCH 1/5] Cache and reuse derived data --- preternatural-build/action.yml | 39 +++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/preternatural-build/action.yml b/preternatural-build/action.yml index 90a6557..8673b7b 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: PreternaturalBuild-DerivedData runs: using: 'composite' @@ -33,14 +33,43 @@ runs: brew tap PreternaturalAI/preternatural brew install preternatural + - name: Restore DerivedData Cache + uses: actions/cache/restore@v4 + with: + path: "**/PreternaturalBuild-DerivedData" + 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 }} + + function run_build() { + preternatural build \ + --derived-data-path "$DERIVED_DATA_PATH" \ + --platforms "$PLATFORMS" \ + --configurations "$CONFIGURATIONS" + } - preternatural build \ - --derived-data-path "$DERIVED_DATA_PATH" \ - --platforms "$PLATFORMS" \ - --configurations "$CONFIGURATIONS" + # First attempt + if ! run_build; then + echo "First build attempt failed. Cleaning derived data and retrying..." + rm -rf "$DERIVED_DATA_PATH" + + # Second attempt + if ! run_build; then + echo "Second build attempt failed 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: "**/PreternaturalBuild-DerivedData" + key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data From 781450cdc21d4e98fe623ea20a420e2675791cee Mon Sep 17 00:00:00 2001 From: Akshat Patel Date: Fri, 13 Dec 2024 11:46:03 +0530 Subject: [PATCH 2/5] Update --- preternatural-build/action.yml | 43 ++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/preternatural-build/action.yml b/preternatural-build/action.yml index 8673b7b..ddffe18 100644 --- a/preternatural-build/action.yml +++ b/preternatural-build/action.yml @@ -46,25 +46,48 @@ runs: 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 }} - - function run_build() { - preternatural build \ - --derived-data-path "$DERIVED_DATA_PATH" \ - --platforms "$PLATFORMS" \ - --configurations "$CONFIGURATIONS" + + function check_derived_data() { + echo "Checking DerivedData folder at: $DERIVED_DATA_PATH" + if [ -d "$DERIVED_DATA_PATH" ]; then + echo "DerivedData folder exists. Contents:" + ls -la "$DERIVED_DATA_PATH" + echo "Total size of DerivedData:" + du -sh "$DERIVED_DATA_PATH" + else + echo "DerivedData folder does not exist" + fi } + + # Construct the command as a string + PRETERNATURAL_CMD="preternatural build --derived-data-path \"$DERIVED_DATA_PATH\" --platforms $PLATFORMS --configurations $CONFIGURATIONS" + + echo "Constructed preternatural build command:" + echo "${PRETERNATURAL_CMD}" + + check_derived_data # First attempt - if ! run_build; then - echo "First build attempt failed. Cleaning derived data and retrying..." + set +e # Don't exit on error + eval ${PRETERNATURAL_CMD} 2>&1 + BUILD_STATUS=$? + set -e # Return to exit on error + + if [ $BUILD_STATUS -ne 0 ]; then + echo "First build attempt failed (status: $BUILD_STATUS). Cleaning derived data and retrying..." rm -rf "$DERIVED_DATA_PATH" + check_derived_data # Second attempt - if ! run_build; then - echo "Second build attempt failed after cleaning derived data. Failing the workflow." + 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 From 0c0d457eba3e26b4d46e999e47d6395324708180 Mon Sep 17 00:00:00 2001 From: Akshat Patel Date: Fri, 13 Dec 2024 12:14:07 +0530 Subject: [PATCH 3/5] Parent directory derived data --- preternatural-build/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/preternatural-build/action.yml b/preternatural-build/action.yml index ddffe18..73004cb 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: PreternaturalBuild-DerivedData + default: "../Preternatural-DerivedData" runs: using: 'composite' @@ -36,7 +36,7 @@ runs: - name: Restore DerivedData Cache uses: actions/cache/restore@v4 with: - path: "**/PreternaturalBuild-DerivedData" + path: "**/Preternatural-DerivedData" key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data - name: Execute preternatural build command @@ -94,5 +94,5 @@ runs: if: steps.build.outputs.build_succeeded == 'true' uses: actions/cache/save@v4 with: - path: "**/PreternaturalBuild-DerivedData" + path: "**/Preternatural-DerivedData" key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data From 0fc3cd2dc2e9e60b5f534c5201aff30c40b9307b Mon Sep 17 00:00:00 2001 From: Akshat Patel Date: Fri, 13 Dec 2024 14:13:44 +0530 Subject: [PATCH 4/5] Use script --- preternatural-build/action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/preternatural-build/action.yml b/preternatural-build/action.yml index 73004cb..364aa01 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: "../Preternatural-DerivedData" + default: "PreternaturalBuild-DerivedData" runs: using: 'composite' @@ -36,7 +36,7 @@ runs: - name: Restore DerivedData Cache uses: actions/cache/restore@v4 with: - path: "**/Preternatural-DerivedData" + path: "PreternaturalBuild-DerivedData" key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data - name: Execute preternatural build command @@ -60,7 +60,7 @@ runs: } # Construct the command as a string - PRETERNATURAL_CMD="preternatural build --derived-data-path \"$DERIVED_DATA_PATH\" --platforms $PLATFORMS --configurations $CONFIGURATIONS" + PRETERNATURAL_CMD="script -q /dev/null preternatural build --derived-data-path \"$DERIVED_DATA_PATH\" --platforms $PLATFORMS --configurations $CONFIGURATIONS" echo "Constructed preternatural build command:" echo "${PRETERNATURAL_CMD}" @@ -94,5 +94,5 @@ runs: if: steps.build.outputs.build_succeeded == 'true' uses: actions/cache/save@v4 with: - path: "**/Preternatural-DerivedData" + path: "PreternaturalBuild-DerivedData" key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data From 3d9c925ec9dfab9d4b0ebab3bb1b9e55e7087f87 Mon Sep 17 00:00:00 2001 From: Akshat Patel Date: Fri, 13 Dec 2024 14:31:39 +0530 Subject: [PATCH 5/5] Update derived data path --- preternatural-build/action.yml | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/preternatural-build/action.yml b/preternatural-build/action.yml index 364aa01..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: "PreternaturalBuild-DerivedData" + default: "preternatural-derived-data" runs: using: 'composite' @@ -36,7 +36,7 @@ runs: - name: Restore DerivedData Cache uses: actions/cache/restore@v4 with: - path: "PreternaturalBuild-DerivedData" + path: "~/preternatural-derived-data" key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data - name: Execute preternatural build command @@ -45,28 +45,14 @@ runs: 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 }} - - function check_derived_data() { - echo "Checking DerivedData folder at: $DERIVED_DATA_PATH" - if [ -d "$DERIVED_DATA_PATH" ]; then - echo "DerivedData folder exists. Contents:" - ls -la "$DERIVED_DATA_PATH" - echo "Total size of DerivedData:" - du -sh "$DERIVED_DATA_PATH" - else - echo "DerivedData folder does not exist" - fi - } + 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 "Constructed preternatural build command:" + echo "Running preternatural build command:" echo "${PRETERNATURAL_CMD}" - - check_derived_data - + # First attempt set +e # Don't exit on error eval ${PRETERNATURAL_CMD} 2>&1 @@ -76,7 +62,7 @@ runs: if [ $BUILD_STATUS -ne 0 ]; then echo "First build attempt failed (status: $BUILD_STATUS). Cleaning derived data and retrying..." rm -rf "$DERIVED_DATA_PATH" - check_derived_data + echo "Cleaned derived data" # Second attempt eval ${PRETERNATURAL_CMD} 2>&1 @@ -94,5 +80,5 @@ runs: if: steps.build.outputs.build_succeeded == 'true' uses: actions/cache/save@v4 with: - path: "PreternaturalBuild-DerivedData" + path: "~/preternatural-derived-data" key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data