Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions apax-collect-logs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Collect Logs Action

## Overview

The **Collect Logs Action** is designed to gather diagnostic log files from a specified source directory and copy them to a designated destination directory within your GitHub Actions workflow. This is particularly useful for collecting error logs or other diagnostic information when a workflow step fails, making debugging easier.

## Inputs

### Mandatory Parameters

- **`log_source_dir`**:
- **Description**: The absolute path to the directory where log files are searched.
- **Example**: `/github/home/.apax/logs/`

- **`log_dest_dir`**:
- **Description**: The absolute path to the directory where the collected log files should be temporarily stored. If this directory does not exist, it will be created. This directory is typically used to prepare files for subsequent steps, such as uploading them as an artifact.
- **Example**: `/github/workspace/apax-logs/`

## Example Usage

Below is an example of how to integrate the **Collect Logs Action** into a GitHub workflow, typically after a step that might fail, to ensure diagnostic logs are captured.

```yaml
name: My Workflow with Log Collection

on: [push]

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Run potentially failing step
# Replace this with your actual step that might produce logs
run: |
echo "Simulating a failing step..."
mkdir -p /tmp/my-app/logs/
echo "Error: Something went wrong!" > /tmp/my-app/logs/error.log
echo "Warning: Disk space low." > /tmp/my-app/logs/warning.log
exit 1 # Force failure for demonstration

- name: Collect Diagnostic Logs on Failure
if: failure() # This ensures the log collection only runs if a previous step failed
uses: your-org/your-repo/collect-logs@v1 # Replace with the actual path to your action
with:
log_source_dir: /tmp/my-app/logs/ # Example source directory
log_dest_dir: /github/workspace/collected-app-logs/ # Example destination directory

- name: Upload Collected Logs as Artifact
if: always() # Use always() to upload logs even if the collection step had issues
uses: actions/upload-artifact@v4
with:
name: diagnostic-app-logs
path: /github/workspace/collected-app-logs/ # Path must match log_dest_dir
# retention-days: 5 # Optional: how long to keep the artifact
```

### Failure Scenarios
The action will provide informative messages in the workflow output under the following conditions:

1. Source Directory Does Not Exist: If the log_source_dir specified does not exist, a message will indicate that no logs can be copied.
2. No Log Files Found: If the log_source_dir exists but contains no files, a message will indicate that no log files were found to copy.

---
[Back to main page](../README.md)
39 changes: 39 additions & 0 deletions apax-collect-logs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "Collect logs"
description: "collect the diagnost files"
inputs:
log_source_dir:
description: "The directory where log files are searched"
required: true
log_dest_dir:
description: "The name of the directory where the log files should be temporarily stored. If it doesn't exist, it will be created. It should then be passed as an artifact."
required: true
runs:
using: "composite"
steps:
- name: Collect diagnostic files
shell: bash
run: |
echo "🔍 Check for log files in the folder ${{ inputs.log_source_dir }}"

if [ -d "${{ inputs.log_source_dir }}" ]; then
if find "${{ inputs.log_source_dir }}" -maxdepth 1 -type f -print -quit | grep -q .; then
echo "✅ log files found!"

if [ ! -d "${{ inputs.log_dest_dir }}" ]; then
echo "📂 Destination directory ${{ inputs.log_dest_dir }} does not exist yet. Creating it..."
mkdir -p "${{ inputs.log_dest_dir }}"
else
echo "📂 Destination directory ${{ inputs.log_dest_dir }} already exists."
fi

echo "📋 Copying all log files to ${{ inputs.log_dest_dir }}..."
cp "${{ inputs.log_source_dir }}"/* "${{ inputs.log_dest_dir }}"/
echo "🎉 All log files successfully copied."
echo "Contents of the destination directory:"
ls -l "${{ inputs.log_dest_dir }}"
else
echo "ℹ No log files found in ${{ inputs.log_source_dir }}."
fi
else
echo "ℹ The apax log directory ${{ inputs.log_source_dir }} does not exist. No logs to copy."
fi
Loading