LoginSignup
46
20

More than 3 years have passed since last update.

GitHub Actionsのバッジをリンク付きでREADMEに追加する

Posted at

GitHub Actionsがリリースされしばらくし、結構使われているレポジトリが増えてきています。
さらに、 README にバッジを置いておくとそれだけで見栄えがよくなるのでオススメです。

スクリーンショット 2020-03-25 14.58.31.png

バッジをどこで取得できるかというと、対象のアクションに飛んで (https://github.com/<user>/<repo>/actions?<workflow>) Create status badge をクリックし Copy... ボタンを押すだけです。便利ですね。

スクリーンショット 2020-03-25 13.13.55.png

しかしながら、デフォルトでコピーしただけだとちょっと不便なところがあります。下に2つバッジがありますが、違いがわかりますでしょうか?
上がCopyしただけのバッジです。

test
test

クリックすると明白ですが、上は対象のアクションへのリンクになっていません。そのため、[<ここにコピーしたバッジ>](対象のアクションへのリンク) のように書いてリンクにしてあげる必要があります。

毎回これをするのは面倒なので、簡単なユーザースクリプトを用意しました。

UserScriptを実行する拡張が入っていれば、以下のリンクを開いて、Rowを押すだけでインストールできます。

中身としてこれだけです。

// ==UserScript==
// @name         add badge for action link
// @namespace    https://github.com/akameco
// @version      0.1
// @description  add badge for action link
// @author       akameco (https://github.com/akameco)
// @match        https://github.com/*/*/actions*
// @grant        none
// ==/UserScript==

const el = document.querySelector('#badge-markdown')
el.textContent = `[${el.textContent}](${location.href})`
46
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
46
20