Skip to content

Commit b376b8c

Browse files
feat: add monitor_space action (#34)
1 parent 27c9906 commit b376b8c

File tree

6 files changed

+447
-0
lines changed

6 files changed

+447
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This is a monorepo containing a collection of GitHub Actions maintained by Lizar
1010
| Action | Description | Type | Language |
1111
|-------------------------------------------------------|----------------------------------------------|-----------|------------------|
1212
| [facebook_post](actions/facebook_post#readme) | Post to Facebook page/group using Graph API | docker | python |
13+
| [monitor_space](actions/monitor_space#readme) | Monitor and track minimum free disk space | composite | bash |
1314
| [more_space](actions/more_space#readme) | Free up disk space in GitHub Actions runners | composite | bash |
1415
| [release_changelog](actions/release_changelog#readme) | Generate a changelog for the latest release | composite | javascript |
1516
| [release_create](actions/release_create#readme) | Create a new release | composite | bash, javascript |

actions/monitor_space/README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# monitor_space
2+
3+
A reusable action to monitor and track the minimum free disk space during workflow execution. This action can run in the background to continuously monitor disk space usage and report the minimum free space encountered.
4+
5+
## Basic Usage
6+
7+
See [action.yml](action.yml)
8+
9+
### Start Monitoring
10+
```yaml
11+
steps:
12+
- name: Start Space Monitoring
13+
uses: LizardByte/actions/actions/monitor_space@master
14+
with:
15+
mode: start
16+
```
17+
18+
### Stop Monitoring and Get Results
19+
```yaml
20+
steps:
21+
- name: Stop Space Monitoring
22+
uses: LizardByte/actions/actions/monitor_space@master
23+
with:
24+
mode: stop
25+
```
26+
27+
## Complete Workflow Example
28+
29+
```yaml
30+
steps:
31+
# First, free up space using more_space action
32+
- name: Free Disk Space
33+
uses: LizardByte/actions/actions/more_space@master
34+
with:
35+
clean-all: true
36+
37+
# Start monitoring after cleanup
38+
- name: Start Space Monitoring
39+
uses: LizardByte/actions/actions/monitor_space@master
40+
with:
41+
mode: start
42+
43+
# Your workflow steps that consume disk space
44+
- name: Build Application
45+
run: |
46+
# Your build commands here
47+
echo "Building application..."
48+
49+
- name: Run Tests
50+
run: |
51+
# Your test commands here
52+
echo "Running tests..."
53+
54+
# Stop monitoring and get final report
55+
- name: Stop Space Monitoring
56+
id: space-monitor
57+
uses: LizardByte/actions/actions/monitor_space@master
58+
with:
59+
mode: stop
60+
61+
# Use the monitoring results
62+
- name: Display Space Usage
63+
run: |
64+
echo "Current free space: ${{ steps.space-monitor.outputs.current-space }} GB"
65+
echo "Minimum free space: ${{ steps.space-monitor.outputs.minimum-space }} GB"
66+
echo "Maximum space consumed: ${{ steps.space-monitor.outputs.space-consumed }} GB"
67+
echo "Monitoring duration: ${{ steps.space-monitor.outputs.monitoring-duration }} seconds"
68+
```
69+
70+
## Inputs
71+
72+
| Name | Description | Default | Required |
73+
|--------------|-----------------------------------------------------------------------|---------|----------|
74+
| mode | Operation mode: 'start' to begin monitoring, 'stop' to end and report | | `true` |
75+
| storage-path | Path to store monitoring data (default: GitHub workspace temp dir) | `""` | `false` |
76+
77+
## Outputs
78+
79+
| Name | Description |
80+
|---------------------|---------------------------------------------------------|
81+
| current-space | Current free disk space (GB) |
82+
| minimum-space | Minimum free disk space recorded during monitoring (GB) |
83+
| space-consumed | Maximum space consumed during monitoring (GB) |
84+
| monitoring-duration | Duration of monitoring session (seconds) |
85+
86+
## Features
87+
88+
- **Cross-platform**: Works on Linux, Windows, and macOS
89+
- **Background monitoring**: Continuously tracks disk space every 5 seconds
90+
- **Minimum tracking**: Records the lowest free space encountered
91+
- **Safe cleanup**: Automatically stops background processes
92+
- **Detailed reporting**: Provides comprehensive space usage statistics
93+
94+
## How It Works
95+
96+
1. **Start Mode**:
97+
- Records initial free disk space
98+
- Starts a background process that checks disk space every 5 seconds
99+
- Tracks the minimum free space encountered
100+
- Stores monitoring data in a temporary file
101+
102+
2. **Stop Mode**:
103+
- Stops the background monitoring process
104+
- Calculates final statistics including minimum space and duration
105+
- Outputs comprehensive report
106+
- Cleans up temporary monitoring files
107+
108+
## Platform Support
109+
110+
- **Linux**: Uses `df` command to get disk space information
111+
- **macOS**: Uses `df` command with macOS-specific formatting
112+
- **Windows**: Uses PowerShell `Get-WmiObject` to query disk space
113+
114+
## Error Handling
115+
116+
- Validates that monitoring was started before attempting to stop
117+
- Gracefully handles background process cleanup
118+
- Provides clear error messages for invalid usage
119+
- Automatically creates the necessary directories for data storage

actions/monitor_space/action.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
name: "Monitor Space"
3+
description: "Monitor and track the minimum free disk space during workflow execution."
4+
author: "LizardByte"
5+
6+
branding:
7+
icon: activity
8+
color: green
9+
10+
inputs:
11+
mode:
12+
description: "Operation mode: 'start' to begin monitoring, 'stop' to end and report results"
13+
required: true
14+
storage-path:
15+
description: "Path to store monitoring data (default: GitHub workspace temp directory)"
16+
required: false
17+
default: ""
18+
19+
outputs:
20+
current-space:
21+
description: "Current free disk space (GB)"
22+
value: ${{ steps.monitor.outputs.current-space }}
23+
minimum-space:
24+
description: "Minimum free disk space recorded during monitoring (GB)"
25+
value: ${{ steps.monitor.outputs.minimum-space }}
26+
space-consumed:
27+
description: "Maximum space consumed during monitoring (GB)"
28+
value: ${{ steps.monitor.outputs.space-consumed }}
29+
monitoring-duration:
30+
description: "Duration of monitoring session (seconds)"
31+
value: ${{ steps.monitor.outputs.monitoring-duration }}
32+
33+
runs:
34+
using: "composite"
35+
steps:
36+
- name: Make script executable
37+
shell: bash
38+
run: chmod +x "${{ github.action_path }}/monitor.sh"
39+
40+
- name: Monitor disk space
41+
id: monitor
42+
shell: bash
43+
env:
44+
INPUT_MODE: ${{ inputs.mode }}
45+
INPUT_STORAGE_PATH: ${{ inputs.storage-path }}
46+
run: |
47+
"${{ github.action_path }}/monitor.sh" \
48+
--mode="${INPUT_MODE}" \
49+
--storage-path="${INPUT_STORAGE_PATH}"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[
2+
{
3+
"runs-on": "ubuntu-latest",
4+
"with": {
5+
"mode": "stop",
6+
"storage-path": ".monitor_space_ci"
7+
}
8+
},
9+
{
10+
"runs-on": "windows-latest",
11+
"with": {
12+
"mode": "stop",
13+
"storage-path": ".monitor_space_ci"
14+
}
15+
},
16+
{
17+
"runs-on": "macos-latest",
18+
"with": {
19+
"mode": "stop",
20+
"storage-path": ".monitor_space_ci"
21+
}
22+
}
23+
]

0 commit comments

Comments
 (0)