Last active
August 2, 2021 15:24
-
-
Save cumet04/f123eec1d7318dc77e9c16cf3e0da454 to your computer and use it in GitHub Desktop.
テキストファイル一つだけで頒布可能なアプリケーションを作るテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# syntax=docker/dockerfile:1.3-labs | |
# usage (for gh user): | |
# $ docker build -t usage . | |
# $ docker run -it -e ACCESS_TOKEN=$(cat ~/.config/gh/hosts.yml | grep token | tr -s ' ' | cut -d' ' -f 3) usage your-org-name | |
FROM ruby:3.0 | |
RUN gem install octokit | |
RUN mkdir /app | |
WORKDIR /app | |
RUN cat > main.rb <<EOF | |
require 'octokit' | |
OWNER=ARGV[0] | |
client = Octokit::Client.new(access_token: ENV['ACCESS_TOKEN']) | |
# repos = client.repos(OWNER, per_page: 100).map { |r| r[:name] } # for user | |
repos = client.get("/orgs/#{OWNER}/repos", per_page: 100).map { |r| r[:name] } | |
workflows = repos.map { |repo| | |
client.workflows("#{OWNER}/#{repo}").workflows.map { |w| | |
{ | |
id: w[:id], | |
name: w[:name], | |
repo: repo | |
} | |
} | |
}.flatten | |
usages = workflows.map { |w| | |
timing = client.get("/repos/#{OWNER}/#{w[:repo]}/actions/workflows/#{w[:id]}/timing").to_h | |
w.merge(usage: timing.dig(:billable, :UBUNTU, :total_ms)) | |
} | |
puts usages | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dockerfileにheredocがついたと聞いてやってみた。
スクリプトの中身はgithub actionsのusageを集計するやつ。
usageに書いてるコマンドのハックはtokenをいちいち取得したりhistoryに書いたりするのが嫌な人向けの小ネタ。