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 Custom Actionのレシピ
Search
NearMeの技術発表資料です
PRO
April 04, 2025
67
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GitHub Custom Actionのレシピ
NearMeの技術発表資料です
PRO
April 04, 2025
More Decks by NearMeの技術発表資料です
See All by NearMeの技術発表資料です
Claude Code × git worktree で並列開発 (続き) -差分のサービスだけを併設する-
nearme_tech
PRO
1
50
Claude Code × git worktree で並列開発 — サブモジュール構成のリポジトリで成立させる —
nearme_tech
PRO
0
55
LLM + 強化学習
nearme_tech
PRO
0
31
PosthogのA/Bテスト機能の紹介
nearme_tech
PRO
1
45
AIフレンドリーなプロダクトに向けて
nearme_tech
PRO
2
65
初めてのLean言語
nearme_tech
PRO
0
100
Apache Airflow Workflow orchestration without turning cron into spaghetti
nearme_tech
PRO
2
37
実務で役立つ幾何学 ボロノイ図の基礎から グラフ・ネットワーク応用まで
nearme_tech
PRO
1
76
SQL/ID抽出タスクから考える 実践的なハルシネーション対策
nearme_tech
PRO
1
88
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Embracing the Ebb and Flow
colly
88
5.2k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
340
For a Future-Friendly Web
brad_frost
183
10k
Darren the Foodie - Storyboard
khoart
PRO
3
3.9k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
490
Transcript
0 GitHub Custom Actionのレシピ 2025-04-04 第119回NearMe技術勉強会 @yujiosaka
1 第103回のまとめ:GitHub Custom Actionを公開した https://github.com/marketplace/actions/adr-sync
2 GitHub Custom Actionとは? • パッケージをインストールしなくても、GitHub Actionsのstepsに 数⾏追加するだけでどのレポジトリからでも実⾏できる • withを⽤いて設定できる
こういうやつ
3 実態はただのGitHubレポジトリ https://github.com/actions/checkout
4 ADR Syncの設定 steps: - name: Run ADR Sync Action
uses: yujiosaka/adr-sync@v1 with: github-token: ${{ secrets.GH_TOKEN }}
5 GitHub Custom Actionに必要最低限の設定 action.yml name: "ADR Sync" description: "A
GitHub custom action to synchronize ADRs with GitHub Discussions" author: "Yuji Isobe" inputs: ... github-token: description: "GitHub token with necessary permissions to synchronize ADRs" required: true runs: using: "node20" main: "dist/index.js" Marketplaceのリスティングとオートコンプリートで使⽤される
6 GitHub Custom Actionに必要最低限の設定 action.yml name: "ADR Sync" description: "A
GitHub custom action to synchronize ADRs with GitHub Discussions" author: "Yuji Isobe" inputs: ... github-token: description: "GitHub token with necessary permissions to synchronize ADRs" required: true runs: using: "node20" main: "dist/index.js" withで指定できる設定
7 GitHub Custom Actionに必要最低限の設定 action.yml name: "ADR Sync" description: "A
GitHub custom action to synchronize ADRs with GitHub Discussions" author: "Yuji Isobe" inputs: ... github-token: description: "GitHub token with necessary permissions to synchronize ADRs" required: true runs: using: "node20" main: "dist/index.js" 今のところnode12、node16、node20、 docker、compositeしか指定できない
8 GitHub Custom Actionに必要最低限の設定 action.yml name: "ADR Sync" description: "A
GitHub custom action to synchronize ADRs with GitHub Discussions" author: "Yuji Isobe" inputs: ... github-token: description: "GitHub token with necessary permissions to synchronize ADRs" required: true runs: using: "node20" main: "dist/index.js" 実⾏するファイル
9 nodeを使⽤する時に便利なパッケージ • @actions/core: withで指定した設定を受け取ったり、アウトプットを定義できる • @actions/github: コンテキスト(イベント名やコミットハッシュ等)を受け取れる import *
as core from "@actions/core"; import * as github from "@actions/github"; const context = github.context; const arg1 = core.getInput("arg1"); console.log(`This event is triggered by ${context.eventName} with arg1: ${arg1}`);
10 dockerを使⽤する例 action.yml name: 'Hello World' description: 'Greet someone and
record the time' inputs: who-to-greet: description: 'Who to greet' required: true runs: using: 'docker' image: 'yujiosaka/hello-world' args: - ${{ inputs.who-to-greet }} entrypointに渡す引数
11 dockerを使⽤する例 Dockerfile FROM alpine:3.10 COPY entrypoint.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"]
12 dockerを使⽤する例 entrypoint.sh #!/bin/sh -l echo "Hello $1" time=$(date) echo
"time=$time" >> $GITHUB_OUTPUT action.ymlで渡された引数
13 name: 'Hello World' description: 'Greet someone' inputs: who-to-greet: description:
'Who to greet' required: true runs: using: "composite" steps: - name: Set Greeting run: echo "Hello $INPUT_WHO_TO_GREET." shell: bash env: INPUT_WHO_TO_GREET: ${{ inputs.who-to-greet }} compositeを使⽤する例 通常のactionsと同様に stepsを定義するだけ (shellスクリプトだけで いい時に便利)
14 注意点 Linux MacOS Windows Docker ◯ × × JavaScript
◯ ◯ ◯ Composite △ △ △ Runnerの環境ごとにstepを書き分けなければいけない
15 JavaScriptがおすすめ 15
16 Marketplaceに公開する⼿順 16
17 (GitHub Releaseを作成するために)タグをPushする 個⼈的にはsemantic-releaseがおすすめ(余談) $ git tag v1.0.0 $ git
push origin v1.0.0 https://github.com/semantic-release/semantic-release
18 GitHub Releaseを作成するときにチェックを⼊れるだけ
19 あとは恨み節 19
20 Bun/Deno使わせてよ‧‧‧ • Runnerの環境に依存させないために、他のパッケージやバイナリに依存させられない • npm installやビルドを⾛らせることができないので、ビルド済みのファイルをコミッ トしないといけない • せめてBun/Denoが使えたらTypeScriptを直接実⾏できるのに(Node22から型情報を
無視して実⾏できるオプションが加わるからそれ待ちか?)
21 actions/coreとactions/githubは使えるようにしといてよ‧‧‧ • actions/coreとactions/githubはGitHub Custom Actionを作成するのにほぼ必須だが、 初めから使えるようになっているわけではないので、npm installしないといけない • でも、GitHub
Custom Action実⾏時にnpm installが⾛るわけではないので、 node_modulesごとコミットするか(やりたくない)、パッケージも含めてビルドし て、ビルド後のファイルをコミットしないといけない (当然)こっちにした
22 { "name": "adr-sync", "version": "1.0.0", "description": "A GitHub custom
action to synchronize ADRs with GitHub Discussions.", "type": "module", "scripts": { "build": "ncc build src/index.ts --minify", "check": "biome check .", "check:write": "biome check --write .", "prepare": "husky", "test": "vitest run", "test:watch": "vitest" }, ... } package.json TypeScriptのコンパイル、 パッケージのバンドル、 圧縮して、dist/index.jsを作成 (dist/index.jsもコミット必要)
23 Thank you