Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Examples

This directory contains example programs demonstrating how to use the github-release-version-checker library in your own Go applications.

Prerequisites

All examples require a GitHub token to avoid rate limiting:

export GITHUB_TOKEN="your_github_token_here"

Running Examples

Each example is a standalone Go program. To run an example:

cd examples/basic
go run main.go

Examples

1. Basic Usage (basic/)

Demonstrates the fundamental usage of the library:

  • Creating a GitHub client
  • Setting up a days-based policy
  • Analysing a version
  • Interpreting results
cd examples/basic
go run main.go

2. Version-Based Policy (version-based-policy/)

Shows how to use version-based policies (e.g., for Kubernetes):

  • Creating a version-based policy (support N minor versions)
  • Checking if a version is within the support window
  • Handling version-based expiry
cd examples/version-based-policy
go run main.go

3. Custom Repository (custom-repository/)

Demonstrates checking any GitHub repository:

  • Parameterized owner/repo/version
  • Disabling cache for custom repos
  • Displaying newer releases
cd examples/custom-repository
go run main.go hashicorp terraform 1.5.0

4. JSON Output (json-output/)

Shows how to use the built-in JSON marshalling:

  • Encoding analysis results as JSON
  • Error handling with JSON output
  • Structured data for automation
cd examples/json-output
go run main.go

Library Import

To use this library in your own project:

go get github.com/nickromney-org/github-release-version-checker

Then import the packages you need:

import (
 "github.com/nickromney-org/github-release-version-checker/pkg/checker"
 "github.com/nickromney-org/github-release-version-checker/pkg/client"
 "github.com/nickromney-org/github-release-version-checker/pkg/policy"
)

API Overview

Client Package (pkg/client)

// Create a GitHub client
ghClient := client.NewClient(token, owner, repo)

// Fetch releases
releases, err := ghClient.GetAllReleases(ctx)
recentReleases, err := ghClient.GetRecentReleases(ctx, 5)
latest, err := ghClient.GetLatestRelease(ctx)

Policy Package (pkg/policy)

// Days-based policy (e.g., GitHub Actions runners)
daysPolicy := policy.NewDaysPolicy(criticalDays, maxDays)

// Version-based policy (e.g., Kubernetes)
versionPolicy := policy.NewVersionsPolicy(maxMinorVersionsBehind)

Checker Package (pkg/checker)

// Create checker with policy
versionChecker := checker.NewCheckerWithPolicy(ghClient, checker.Config{
 CriticalAgeDays: 12,
 MaxAgeDays: 30,
 NoCache: false,
}, pol)

// Analyse a version
analysis, err := versionChecker.Analyse(ctx, "2.328.0")

// Check status
switch analysis.Status() {
case checker.StatusCurrent:
 // Up to date
case checker.StatusWarning:
 // Behind but within policy
case checker.StatusCritical:
 // Approaching expiry
case checker.StatusExpired:
 // Beyond policy threshold
}

See Also