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

방문해 주셔서 감사합니다! 댓글,지적,피드백 언제나 환영합니다😊

댓글남기기