From 9dc9d087b5be93b41096d34334c5b1afbb64f7c9 Mon Sep 17 00:00:00 2001 From: Akshat Patel Date: Mon, 16 Dec 2024 11:27:21 +0530 Subject: [PATCH 1/5] Add xcactivity log parsing and upload --- preternatural-build/action.yml | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/preternatural-build/action.yml b/preternatural-build/action.yml index b4a5961..e622378 100644 --- a/preternatural-build/action.yml +++ b/preternatural-build/action.yml @@ -82,3 +82,69 @@ runs: with: path: "~/preternatural-derived-data" key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data + + - name: Find and copy all xcactivity logs + if: failure() + continue-on-error: true + shell: zsh + run: | + DERIVED_DATA_PATH=$HOME/${{ inputs.derived_data_path }} + echo "Searching for logs in: $DERIVED_DATA_PATH" + + mkdir -p ./artifacts + + # Find all xcactivitylog files and copy them to the artifacts directory + find "$DERIVED_DATA_PATH" -name "*.xcactivitylog" -type f -print0 | while IFS= read -r -d '' log; do + cp "$log" "./artifacts/$(basename "$log")" + echo "Copied $log to ./artifacts/" + done + + # Debug information + echo "List of copied log files:" + ls -l ./artifacts/*.xcactivitylog + echo "Total size of copied logs:" + du -sh ./artifacts + + # Check if any logs were found and copied + if [ -z "$(ls -A ./artifacts)" ]; then + echo "No xcactivitylog files found in $DERIVED_DATA_PATH" + exit 1 + fi + + - name: Install xclogparser + if: failure() + continue-on-error: true + shell: zsh + run: | + brew install xclogparser + + - name: Convert logs to JSON and print + if: failure() + continue-on-error: true + shell: zsh + run: | + mkdir -p ./json_logs + for log in ./artifacts/*.xcactivitylog; do + json_file="./json_logs/$(basename "$log" .xcactivitylog).json" + xclogparser parse --file "$log" --reporter json --output "$json_file" + echo "Contents of $json_file:" + cat "$json_file" + done + + - name: Upload xcactivity logs (JSON) + if: failure() + continue-on-error: true + uses: actions/upload-artifact@v4 + with: + name: xcactivity-logs-json + path: ./json_logs/*.json + if-no-files-found: error + + - name: Upload xcactivity logs (Raw) + if: failure() + continue-on-error: true + uses: actions/upload-artifact@v4 + with: + name: xcactivity-logs-raw + path: ./artifacts/*.xcactivitylog + if-no-files-found: error From a4954859e6f3c9f35478d515fd778812147a1e78 Mon Sep 17 00:00:00 2001 From: Akshat Patel Date: Mon, 16 Dec 2024 11:57:39 +0530 Subject: [PATCH 2/5] Add working directory input --- preternatural-build/action.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/preternatural-build/action.yml b/preternatural-build/action.yml index e622378..536cba9 100644 --- a/preternatural-build/action.yml +++ b/preternatural-build/action.yml @@ -13,6 +13,10 @@ inputs: description: 'Build configurations (array of: debug, release)' required: false default: '["debug", "release"]' + working-directory: + description: 'Directory to run the preternatural command from' + required: false + default: '' derived_data_path: description: 'The path to the derived data folder' required: false @@ -47,6 +51,12 @@ runs: CONFIGURATIONS=$(echo '${{ inputs.configurations }}' | tr -d '[]' | sed 's/, /,/g') DERIVED_DATA_PATH=$HOME/${{ inputs.derived_data_path }} + # 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 --derived-data-path \"$DERIVED_DATA_PATH\" --platforms $PLATFORMS --configurations $CONFIGURATIONS" @@ -83,7 +93,7 @@ runs: path: "~/preternatural-derived-data" key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data - - name: Find and copy all xcactivity logs + - name: Find and copy all xcactivity logs if: failure() continue-on-error: true shell: zsh From a5243426901e1ddd06acc7c4aaaf182264936c5d Mon Sep 17 00:00:00 2001 From: Akshat Patel Date: Mon, 16 Dec 2024 12:23:11 +0530 Subject: [PATCH 3/5] Minor changes --- preternatural-build/action.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/preternatural-build/action.yml b/preternatural-build/action.yml index 536cba9..ca67603 100644 --- a/preternatural-build/action.yml +++ b/preternatural-build/action.yml @@ -44,6 +44,7 @@ runs: key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data - name: Execute preternatural build command + continue-on-error: true id: build shell: bash run: | @@ -94,9 +95,9 @@ runs: key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data - name: Find and copy all xcactivity logs - if: failure() + if: steps.build.outputs.build_succeeded != 'true' continue-on-error: true - shell: zsh + shell: bash run: | DERIVED_DATA_PATH=$HOME/${{ inputs.derived_data_path }} echo "Searching for logs in: $DERIVED_DATA_PATH" @@ -122,16 +123,16 @@ runs: fi - name: Install xclogparser - if: failure() + if: steps.build.outputs.build_succeeded != 'true' continue-on-error: true - shell: zsh + shell: bash run: | brew install xclogparser - name: Convert logs to JSON and print - if: failure() + if: steps.build.outputs.build_succeeded != 'true' continue-on-error: true - shell: zsh + shell: bash run: | mkdir -p ./json_logs for log in ./artifacts/*.xcactivitylog; do @@ -142,7 +143,7 @@ runs: done - name: Upload xcactivity logs (JSON) - if: failure() + if: steps.build.outputs.build_succeeded != 'true' continue-on-error: true uses: actions/upload-artifact@v4 with: @@ -151,7 +152,7 @@ runs: if-no-files-found: error - name: Upload xcactivity logs (Raw) - if: failure() + if: steps.build.outputs.build_succeeded != 'true' continue-on-error: true uses: actions/upload-artifact@v4 with: From 6a1769637bf98233869140451000858809c1e8f4 Mon Sep 17 00:00:00 2001 From: Akshat Patel Date: Mon, 16 Dec 2024 14:50:53 +0530 Subject: [PATCH 4/5] Fail build if preternatural build fails --- preternatural-build/action.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/preternatural-build/action.yml b/preternatural-build/action.yml index ca67603..6a56948 100644 --- a/preternatural-build/action.yml +++ b/preternatural-build/action.yml @@ -159,3 +159,10 @@ runs: name: xcactivity-logs-raw path: ./artifacts/*.xcactivitylog if-no-files-found: error + + - name: Check build status and fail if necessary + if: steps.build.outputs.build_succeeded != 'true' + shell: bash + run: | + echo "Build failed earlier in the workflow" + exit 1 From bca4e79faa46eb1b64a0c26f56bed6b8d362a8c3 Mon Sep 17 00:00:00 2001 From: Akshat Patel Date: Mon, 16 Dec 2024 15:10:07 +0530 Subject: [PATCH 5/5] Also upload xcresult logs --- preternatural-build/action.yml | 80 ++++++++++++++++------------------ 1 file changed, 37 insertions(+), 43 deletions(-) diff --git a/preternatural-build/action.yml b/preternatural-build/action.yml index 6a56948..caceb38 100644 --- a/preternatural-build/action.yml +++ b/preternatural-build/action.yml @@ -94,7 +94,14 @@ runs: path: "~/preternatural-derived-data" key: ${{ runner.os }}-${{ github.repository }}-${{ github.ref_name }}-derived-data - - name: Find and copy all xcactivity logs + - name: Install xclogparser + if: steps.build.outputs.build_succeeded != 'true' + continue-on-error: true + shell: bash + run: | + brew install xclogparser + + - name: Find and process logs if: steps.build.outputs.build_succeeded != 'true' continue-on-error: true shell: bash @@ -102,62 +109,49 @@ runs: DERIVED_DATA_PATH=$HOME/${{ inputs.derived_data_path }} echo "Searching for logs in: $DERIVED_DATA_PATH" - mkdir -p ./artifacts + mkdir -p ./artifacts/xcactivitylogs + mkdir -p ./artifacts/json_logs + mkdir -p ./artifacts/xcresults - # Find all xcactivitylog files and copy them to the artifacts directory + # Find and copy xcactivitylog files find "$DERIVED_DATA_PATH" -name "*.xcactivitylog" -type f -print0 | while IFS= read -r -d '' log; do - cp "$log" "./artifacts/$(basename "$log")" - echo "Copied $log to ./artifacts/" + cp "$log" "./artifacts/xcactivitylogs/$(basename "$log")" + echo "Copied $log to ./artifacts/xcactivitylogs/" + + # Convert to JSON + json_file="./artifacts/json_logs/$(basename "$log" .xcactivitylog).json" + xclogparser parse --file "$log" --reporter json --output "$json_file" + echo "Converted $log to JSON: $json_file" + done + + # Find and copy xcresult bundles + find "$DERIVED_DATA_PATH" -name "*.xcresult" -type d -print0 | while IFS= read -r -d '' result; do + cp -R "$result" "./artifacts/xcresults/" + echo "Copied $result to ./artifacts/xcresults/" done # Debug information - echo "List of copied log files:" - ls -l ./artifacts/*.xcactivitylog - echo "Total size of copied logs:" - du -sh ./artifacts + echo "Contents of artifacts directory:" + ls -R ./artifacts # Check if any logs were found and copied - if [ -z "$(ls -A ./artifacts)" ]; then - echo "No xcactivitylog files found in $DERIVED_DATA_PATH" + if [ -z "$(ls -A ./artifacts/xcactivitylogs)" ] && [ -z "$(ls -A ./artifacts/xcresults)" ]; then + echo "No log files or xcresult bundles found in $DERIVED_DATA_PATH" exit 1 fi + + # Create zip archive + cd ./artifacts + zip -r ../build-artifacts.zip ./* + cd .. - - name: Install xclogparser - if: steps.build.outputs.build_succeeded != 'true' - continue-on-error: true - shell: bash - run: | - brew install xclogparser - - - name: Convert logs to JSON and print - if: steps.build.outputs.build_succeeded != 'true' - continue-on-error: true - shell: bash - run: | - mkdir -p ./json_logs - for log in ./artifacts/*.xcactivitylog; do - json_file="./json_logs/$(basename "$log" .xcactivitylog).json" - xclogparser parse --file "$log" --reporter json --output "$json_file" - echo "Contents of $json_file:" - cat "$json_file" - done - - - name: Upload xcactivity logs (JSON) - if: steps.build.outputs.build_succeeded != 'true' - continue-on-error: true - uses: actions/upload-artifact@v4 - with: - name: xcactivity-logs-json - path: ./json_logs/*.json - if-no-files-found: error - - - name: Upload xcactivity logs (Raw) + - name: Upload build artifacts if: steps.build.outputs.build_succeeded != 'true' continue-on-error: true uses: actions/upload-artifact@v4 with: - name: xcactivity-logs-raw - path: ./artifacts/*.xcactivitylog + name: build-artifacts + path: build-artifacts.zip if-no-files-found: error - name: Check build status and fail if necessary