LoginSignup
8
3

More than 3 years have passed since last update.

GitHub Actions v2 の LINE Notify アクションを作ってみた

Posted at

はじめに

GitHub Actions を用いて issue が更新されたら LINE に通知する方法 - Qiita
こちらの記事を見て LINE Notify を知り、習作にちょうど良さそうだったのでアクションを自作してみました。

完成品

ソースコードはこちら。
snow-actions/line-notify: LINE Notify for GitHub Actions

Marketplace にも公開していますので良かったらご利用ください。
LINE Notify · Actions · GitHub Marketplace

使い方

.github/workflows/example.yml
name: LINE Notify example
on:
  issues:
    types: opened
jobs:
  notify:
    runs-on: ubuntu-latest
    steps:
      - uses: snow-actions/line-notify@v1.0.0
        with:
          access_token: ${{ secrets.LINE_ACCESS_TOKEN }}
          message: ${{ github.event.issue.title }}

Settings > Secrets に LINE Notify で取得したアクセストークンを LINE_ACCESS_TOKEN を設定してください。

作り方

アクションのビルド - GitHub ヘルプ に説明があります。
今回は JavaScript で作ります。

アクションの作成

JavaScript アクションを作成する - GitHub ヘルプ に従って作ります。
リポジトリを作ってクローンして npm init -y しておきます。
Node.js 12.x が必要です。
action.yml, index.js を作成。

JavaScript テンプレートも公開されているのでそちらから作っても良いです。
Use this template ボタンを押すとリポジトリが作られます。
他にも TypeScriptDocker のテンプレートがあります。

node modules

今回は HTTP リクエストで API を叩きたいので @action/core に加えて request をインストールします。

npm install @action/core
npm install request

node_modules ディレクトリもリポジトリに含めておく必要があるので .gitignore から外しておきます。

Marketplace へ公開

image.png
Draft a release ボタンを押すと新規リリース作成画面へ飛ばされます。
公開するには規約への同意とアカウントが2ファクタ認証している必要があります。
指示されるのでそれに従えば良いです。

存在しているタグを選ぶか新規にタグを作成します。
リリースのタイトルや説明を入力します。

branding の設定をしておくことを推奨します。
README.md がそのまま Marketplace の説明に使われます。

審査もなくリリースを作成したらすぐに Marketplace へ公開されました。

おわりに

アクションは簡単に自作して公開まで出来るので欲しいアクションがあったら作ってみるのもいいかもしれません。
LINE Notify API Document を見ると message 以外にも情報を付加できそうなので Pull Request も歓迎です。

8
3
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
8
3