Git Product home page Git Product logo

gha-usage's Introduction

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

gha-usage's People

Contributors

muno92 avatar github-actions[bot] avatar jcwasmx86 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.