Publish:

ํƒœ๊ทธ: ,

์นดํ…Œ๊ณ ๋ฆฌ:

๊ธฐ์กด 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 ๋ฅผ ๋ถ™์—ฌ ๋„ฃ๋Š”๋‹ค. img_1.png

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

reference

๋ฐฉ๋ฌธํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๋Œ“๊ธ€,์ง€์ ,ํ”ผ๋“œ๋ฐฑ ์–ธ์ œ๋‚˜ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค๐Ÿ˜Š

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ