app

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2020 License: Apache-2.0 Imports: 11 Imported by: 1

README

delete-artifacts

Command line application to delete artifacts from a GitHub Workflow.

Apache 2.0 License Go Version Go Go Report Card Docker Pulls

From GitHub Workflow's Documentation

Artifacts automatically expire after 90 days, but you can always reclaim used GitHub Actions storage by deleting artifacts before they expire on GitHub.

Wouldn't it be better if you could do this without manually going through every damn workflow to click delete? With delete-artifacts, you can:

  • Delete your largest artifacts only
  • Delete your artifacts for a given run
  • Automate deleting your artifacts according to a schedule
  • Avoid unnecessary costs for your private repositories

Usage

Usage:
  delete-artifacts [OPTIONS]

Application Options:
  -o, --owner=   GitHub Owner/Org name [$GITHUB_ACTOR]
  -r, --repo=    GitHub Repo name [$GITHUB_REPO]
  -i, --run-id=  The workflow run id from which to delete artifacts
      --min=     Minimum size in bytes. Artifacts greater than this size will be deleted. (default: 50000000)
      --max=     Maximum size in bytes. Artifacts less than this size will be deleted
  -n, --name=    Artifact name to be deleted
  -p, --pattern= Regex pattern (POSIX) for matching artifact name to be deleted
  -a, --active=  Consider artifacts as 'active' within this time frame, and avoid deletion. Duration formatted such as 23h59m.
      --dry-run  Dry-run that does not perform deletions
  -v, --version  Display version information

Help Options:
  -h, --help     Show this help message
Examples

First, export GITHUB_TOKEN, then…

# Delete artifacts between 1B and 3MB for Run 229589570 in jimschubert/delete-artifacts-test
delete-artifacts --dry-run --owner=jimschubert --repo=delete-artifacts-test --min=1 --max=3000000 --run-id=229589570
# Delete all artifacts in jimschubert/delete-artifacts-test matching name "delete_me"
delete-artifacts --dry-run --owner=jimschubert --repo=delete-artifacts-test --name delete_me
# Delete all artifacts in jimschubert/delete-artifacts-test matching a specific regex pattern (ending in .bin), note the escape character
delete-artifacts --dry-run --owner=jimschubert --repo=delete-artifacts-test --pattern='\.bin'

Remove --dry-run from examples to perform your delete

Installation

Latest binary releases are available via GitHub Releases.

Via Docker

Pass the required environment variable(s) to Docker and run like so:

docker run -e GITHUB_TOKEN jimschubert/delete-artifacts:latest \
    --dry-run --owner=jimschubert --repo=delete-artifacts-test --pattern='\.bin' --min=0

Build

Build a local distribution for evaluation using goreleaser.

goreleaser release --skip-publish --snapshot --rm-dist

This will create an executable application for your os/architecture under dist:

dist
├── checksums.txt
├── config.yaml
├── delete-artifacts_darwin_amd64
│   └── delete-artifacts
├── delete-artifacts_linux_386
│   └── delete-artifacts
├── delete-artifacts_linux_amd64
│   └── delete-artifacts
├── delete-artifacts_linux_arm64
│   └── delete-artifacts
├── delete-artifacts_linux_arm_6
│   └── delete-artifacts
├── delete-artifacts_v0.0.0-next_Darwin_x86_64.tar.gz
├── delete-artifacts_v0.0.0-next_Linux_arm64.tar.gz
├── delete-artifacts_v0.0.0-next_Linux_armv6.tar.gz
├── delete-artifacts_v0.0.0-next_Linux_i386.tar.gz
├── delete-artifacts_v0.0.0-next_Linux_x86_64.tar.gz
├── delete-artifacts_v0.0.0-next_Windows_x86_64.zip
├── delete-artifacts_windows_amd64
│   └── delete-artifacts.exe
└── goreleaserdocker356495573

Build and execute locally:

  • Get dependencies
go get -d ./...
  • Build
go build cmd/main.go
  • Run
./main

Loggign

Having issues? Set LOG_LEVEL environment variable to one of debug, info, warn, or error.

Log outputs with messages and structured fields. For example:

INFO[0000] delete-artifacts is checking the repo         owner=jimschubert repo=delete-artifacts-test
DEBU[0000] Querying artifacts across all workflows.     
DEBU[0000] Iterating artifact.                           name=artifact.bin size=1048576
DEBU[0000] MinBytes filter has matched.                  MinBytes=0
DEBU[0000] Found a set of artifacts for slated deletion.  count=1
DEBU[0000] Querying artifacts across all workflows.     
DEBU[0000] Zero artifacts remaining for query.          
DEBU[0000] Total number of artifacts to delete.          count=1
INFO[0000] Deleting artifact                             name=artifact.bin size=1048576
INFO[0000] Run complete.                    

License

This project is licensed under Apache 2.0.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Owner          *string
	Repo           *string
	RunId          *int64
	MinBytes       int64
	MaxBytes       *int64
	Name           string
	Pattern        string
	DryRun         bool
	ActiveDuration string
	// contains filtered or unexported fields
}

App is the main application container

func New

func New(owner *string, repo *string, runId *int64, minBytes int64, maxBytes *int64, name string, pattern string, activeDuration string, dryRun bool) (*App, error)

New creates an instance of App

func (*App) Run

func (a *App) Run() error

Run the application

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL