Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GitHub ActionsのActionを作る
Search
meil
September 20, 2019
Programming
450
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GitHub ActionsのActionを作る
meil
September 20, 2019
More Decks by meil
See All by meil
クラシルの開発で使ってるGitHub Actions
meilcli
0
210
プログラミング言語(?)を自作した話
meilcli
0
900
GitHub Actions入門
meilcli
0
470
Azure Pipelinesのすゝめ
meilcli
0
340
Other Decks in Programming
See All in Programming
Android CLI
fornewid
0
220
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
1.1k
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
310
ソフトウェアエンジニアにとっての生成AI - 特性を知って使い倒す / generative ai for software enginner
kishida
5
1.8k
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
280
数百円から始めるRuby電子工作
tarosay
0
160
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
180
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
650
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
470
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
150
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
1
140
Featured
See All Featured
Writing Fast Ruby
sferik
630
63k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
390
Music & Morning Musume
bryan
47
7.3k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
960
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
710
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
990
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
Transcript
GitHub ActionsのActionを作る Mobile Act OSAKA #11
自己紹介 • Twitter: @penguin_sharp • GitHub: MeilCli • Blog: https://blog.meilcli.net/
• Skill: C#, Kotlin, Android, Azure Pipelines • Work: Fenrir Inc. ◦ Android Application Engineer ◦ 発言は個人の見解であり所属する組織の公式見解ではありません
GitHub Actions軽くまとめ • ベータ版 ◦ https://twitter.com/natfriedman/status/1174158823877042177 • Azure Pipelinesのクローン •
Windows, Linux, macOSで動作 • 1つの構成単位としてworkflow、1つの実行ステップ単位としてactionがある
Actionを作るには • 作り方は2種類 ◦ Docker container ◦ JavaScript(Node.js) ← 今回試すのはこっち
• Docker containerはLinuxでのみ対応
注意: 今回作るものはあくまで学習目 的です そして、Dangerのactionを作り ます
そもそもDangerとは • コードレビューを自動化するためのツールみたいなもの ◦ https://github.com/danger/danger • 今回はRuby版を使用
Actionを作る • Node.jsをインストール • Visual Studio Codeを用意 • リポジトリーの作成 ◦
npm init -y ◦ npm install -g typescript ◦ tsc -init ◦ npm install @actions/core --save ◦ npm install @actions/io --save ◦ npm install @actions/exec --save ◦ etc..
Actionを作る まずはactionの実行コードを書いていく import * as core from '@actions/core'; async function
run() { try { } catch (error) { core.setFailed(error.message); } } run();
Actionを作る action外でDangerを動かすための環境がセット アップされている前提にする import * as io from '@actions/io'; async
function checkEnvironment() { await io.which("ruby", true); await io.which("bundle", true); }
Actionを作る actionに渡された引数を取得する interface Option { readonly dangerVersion: string; readonly pluginsFile:
string | null; readonly dangerFile: string; readonly dangerId: string; } async function getOption(): Promise<Option> { return { dangerVersion: core.getInput( "danger_version" , { required: true }), pluginsFile: core.getInput( "plugins_file" ), dangerFile: core.getInput( "danger_file" , { required: true }), dangerId: core.getInput( "danger_id" , { required: true }) } }
Actionを作る Dangerをインストール import * as exec from '@actions/exec' ; async
function installDanger(option: Option) { await exec.exec( `gem install danger --version "${option.dangerVersion }"`, undefined , { failOnStdErr: true } ); if (option.pluginsFile != null) { await exec.exec( `bundle install --gemfile= ${option.pluginsFile }`, undefined , { failOnStdErr: true } ); } }
Actionを作る Danger実行 async function runDanger(option: Option) { await exec.exec( `danger
--dangerfile=${option.dangerFile} --danger_id=${option.dangerId}`, undefined, { failOnStdErr: true } ); }
Actionを作る action.ymlを書く name: 'Danger action' description : 'run danger' author:
'MeilCli' inputs: danger_version : description : 'danger version' default: '~> 6.0' plugins_file : description : 'gemfile for danger plugin' danger_file : description : 'dangerfile for danger' required : true danger_id : description : 'danger id, set identifier string' required : true runs: using: 'node12' main: 'lib/main.js'
Actionを使う workflowのymlを書く • action.ymlのinputsに対してwithで値を渡す • usesにアカウント名/レポジトリ名を指定 ◦ @のあとはバージョン情報 ◦ ここではTagを指定
jobs: danger: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - uses: actions/setup-ruby@v1 with: ruby-version: '2.6' - uses: MeilCli/danger-action@v1 with: plugins_file: 'Gemfile' danger_file: 'Dangerfile' danger_id: 'danger-pr' env: DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Actionを使う WorkflowやDangerfileなどをセットアップしておく と、PullRequestでこのようなコメントが送られてくる ようになる
Actionを公開する • 基本的にリポジトリーを公開しておくだけでOK ◦ 注意点として.jsファイルとそれが参照する node_modulesも公開しておく必要がある • Marketplaceにも公開できる ◦ https://github.com/marketplace?type=actions
◦ Marketplaceに公開する場合はaction.ymlに必要な情報を記述しておく必要あり ▪ 名前、説明、アイコンなど
おわりに • まとめ ◦ GitHub ActionのactionはTypeScriptで簡単に作ることができる ◦ だからみんなもどんどん作っていってくれ~~ • 今回作ったもの
◦ https://github.com/MeilCli/danger-action ◦ https://github.com/marketplace/actions/danger-action • 解説 ◦ https://blog.meilcli.net/2019/09/15/155447