[Github Action] github CLI ๋ก github action ํธ๋ฆฌ๊ฑฐ ํ๊ธฐ
์นดํ ๊ณ ๋ฆฌ: Github
๊ธฐ์กด workflow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# blogposts.yml
name: Blog post workflow
on:
push:
branches:
- main
schedule:
# Runs every day at
- cron: '0 1 * * *'
jobs:
pull_blog_rss:
name: Update with latest blog posts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get RSS Feed
uses: kohrongying/readme-the-rss@master
with:
feed_url: https://zhtmr.github.io/feed.xml
count: 6 # default 5
- name: Commit file changes
run: |
git config --global user.name 'username'
git config --global user.email 'uesremail'
git add .
git diff --quiet --cached || git commit -m "[auto] $(date -u +"%Y-%m-%d-%r") Blog Posting List Update"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: $
๊ธฐ์กด ๋ธ๋ก๊ทธ ํฌ์คํธ github action ์ cron job ์ผ๋ก ๋งค์ผ ์์นจ 10์์ RSS ๊ธ์ด์์ ๊ธฐ์กด ์ปค๋ฐ ๋ด์ญ๊ณผ ๋น๊ต ํ ๋ฌ๋ผ์ง ๋ด์ฉ(์ถ๊ฐ๋ ๊ฒ์๊ธ ์๋ ๊ฒฝ์ฐ)์ด ์์ ๊ฒฝ์ฐ git commit ๋๋ค.
workflow ํ์ผ ์ค์
1
2
3
4
5
6
7
8
on:
push:
branches:
- main
schedule:
# Runs every day at
- cron: '0 1 * * *'
workflow_dispatch: # workflow๋ฅผ ์๋์ผ๋ก trigger ํ ์ ์๋ ์ต์
์ถ๊ฐ
trigger ์กฐ๊ฑด์ workflow_dispatch
๋ฅผ ์ถ๊ฐํด ์ค๋ค.
Github CLI ์ค์น
๋ก์ปฌ ํฐ๋ฏธ๋์์ workflow ๋ฅผ ์คํ์ํค๊ธฐ ์ํด github cli ๋ฅผ ์ค์นํ๋ค.
1
brew install gh
cli ๋ก workflow ํธ๋ฆฌ๊ฑฐํ๊ธฐ
1
2
# `blogposts.yml` workflow ๋ฅผ `master` ๋ธ๋์น์์ ์คํ ์ํจ๋ค.
gh workflow run blogposts --ref master
๐ซจ
blogposts
์ฒ๋ผ yml ํ์ผ ๋ช ์ผ๋ก ๋ชป์ฐพ๋ ๊ฒฝ์ฐgh workflow list
์น๋ฉด ๋์ค๋ ID ๊ฐ์ ๋ฃ์ด์ค๋ค. ์ฐธ๊ณ
gh login
์คํ ์ค์ ์๋์ ๊ฐ์ ๋ก๊ทธ์ธ ์์ฒญ ์ gh auth login
์
๋ ฅ ํ๋ค.
1
2
To get started with GitHub CLI, please run: gh auth login
Alternatively, populate the GH_TOKEN environment variable with a GitHub API authentication token.
์ฐจ๋ก๋๋ก GitHub.com
, HTTPS
, Y
, Login with a web browser
๋ฅผ ์ ํ ํ ๋ธ๋ผ์ฐ์ ์ one-time code ๋ฅผ ๋ถ์ฌ ๋ฃ๋๋ค.
npm script ์ด์ฉ
๋งค๋ฒ ์ผ์ผ์ด gh workflow run blogposts --ref master
์น๋๊ฒ ๊ท์ฐฎ์ผ๋ฏ๋ก npm init
์ผ๋ก package.json ํ์ผ ๋ง๋ ํ script
ํ๊ทธ ์์ ๋ฃ์ด์ฃผ์.
1
2
3
4
5
6
7
8
9
10
11
12
{
"name": "zhtmr",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"deploy": "gh workflow run ID๊ฐ --ref master"
},
"author": "",
"license": "ISC"
}
npm run deploy ๋ก ์คํํ๋ฉด github action ๋์ํ๋ค.
1
npm run deploy
๋๊ธ๋จ๊ธฐ๊ธฐ