Skip to content

Calculate GitHub Actions usage with specified repository and period.

License

Notifications You must be signed in to change notification settings

muno92/gha-usage

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 Actions Usage Calculator

Test

This tool calculate GitHub Actions usage with specified repository and period.

sample usage

You can choose between GitHub Actions and Command Line to exec this tool.

Usage

Warning
This tool can only calculate the usage of less than 1000 workflow runs
(due to GitHub REST API limitations).
So, please change period by workflow run count.

You can see workflow run count with follow command.

./ghausage count --repo REPO --start START_DATE --end END_DATE
# example)
./ghausage count --repo muno92/gha-usage --start 2022-11-01 --end 2022-11-30

GitHub Actions

From GitHub Actions, gha-usage output result to Job Summary.

job summary example

Inputs

  • sub-command
    Subcommand of ghausage. [ sum | count ]
  • repo (required)
    The name of target repository.
    example) muno92/gha-usage
  • start-date (required)
    Start date of calculation period with format 'yyyy-mm-dd'.
    example) 2022-01-01
  • end-date (required)
    Start date of calculation period with format 'yyyy-mm-dd'.
    example) 2022-01-31

Example) Get usage of last month

name: Calculate usage

on:
  schedule:
    - cron:  '5 0 1 * *'
    
jobs:
  calc-usage:
    runs-on: ubuntu-latest
    steps:
      - name: Set Start Date
        run: echo "START_DATE=$(date -d "$(date +'%Y%m01') 1 month ago" +'%Y-%m-%d')" >> $GITHUB_ENV
      - name: Set End Date
        run: echo "END_DATE=$(date -d "$(date +'%Y%m01') 1 days ago" +'%Y-%m-%d')" >> $GITHUB_ENV
      - uses: muno92/gha-usage@v1
        with:
          repo: ${{ github.repository }}
          start-date: ${{ env.START_DATE }}
          end-date: ${{ env.END_DATE }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Example) Get usage of last week

name: Calculate usage

on:
  schedule:
    - cron:  '5 0 * * 0'
    
jobs:
  calc-usage:
    runs-on: ubuntu-latest
    steps:
      - name: Set Start Date
        run: echo "START_DATE=$(date -d '8 days ago' +'%Y-%m-%d')" >> $GITHUB_ENV
      - name: Set End Date
        run: echo "END_DATE=$(date -d '1 days ago' +'%Y-%m-%d')" >> $GITHUB_ENV
      - uses: muno92/gha-usage@v1
        with:
          repo: ${{ github.repository }}
          start-date: ${{ env.START_DATE }}
          end-date: ${{ env.END_DATE }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Command Line

  1. Download binary from release page.
  2. Creating a personal access token.
    When target repository is public, token needs no permission, because token is only for avoid rate limit.
  3. Exec gha-usage
    export GITHUB_TOKEN=YOUR_TOKEN
    ./ghausage sum --repo REPO --start START_DATE --end END_DATE
    # example)
    ./ghausage sum --repo muno92/gha-usage --start 2022-11-01 --end 2022-11-30

About

Calculate GitHub Actions usage with specified repository and period.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages