Skip to content

GitHub action to check available disk space on remote host

License

Notifications You must be signed in to change notification settings

begoon/diskspace-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

GitHub action "diskspace"

GitHub Action GitHub Action

This GitHub action checks available disk space on a remote host. It can be convenient when you deploy to a remote host from the GitHub action, and you want to make sure that there is enough disk space there.

With this action, you can specify the host and the threshold. The action will connect to the host and check that the available disk space is more than the threshold. If it is less than the threshold, the action will fail.

The action uses ssh to connect to the remote host. The action executes a command to print the available disk space. By default, the df command is used with some flags. Then a regular expression is used to find the number representing the available disk space.

If the number is found, it is compared to the threshold. If the available disk space is less than the threshold, the action will fail. Otherwise, the action will succeed.

If the number representing the available disk is not found by the regular expression, the action will fail as well.

Requirements

ssh must be available on the runner, and ssh keys must be configured.

Usually, linux hosts provide ssh by default, and the @shimataro/ssh-key-action action can be used to configure the keys.

Inputs

Variable Default Description Required
threshold - Minimum available disk space in megabytes. For example, 1000, which means that 1000 megabytes are required. Yes
host - Remote host to check. For example, 1.1.1.1. Yes
user - Remote host user. For example, ec2-user. Yes
ssh ssh SSH command to run the command on the remote host. If necessary to add options or flags for the ssh command, they can be appended to the ssh variable. For example, ssh -q. No
cmd note 1 Command to run on the remote host. No
pattern \d+ Regular expression to find the available disk space in the output of the command. If the regular expression has groups (() are used), the first captured group will be used as the result. No

Note 1

The default values for cmd is df -BM --output=avail /dev/xvda1.

On Amazon Linux this command prints something like:

 Avail
16813M

The default regular expression \d+ matches the sequence of digits.

Example usage

- uses: shimataro/ssh-key-action@v2
  with:
    key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
    known_hosts: "anything"

- run: ssh-keyscan -H ${{ secrets.EC2_SSH_HOST }} >> ~/.ssh/known_hosts    

- uses: begoon/diskspace-action@v1
  with:
      host: ${{ secrets.EC2_SSH_HOST }}
      user: ec2-user
      threshold: 1000

About

GitHub action to check available disk space on remote host

Resources

License

Stars

Watchers

Forks

Packages

No packages published