๐Ÿ“˜ Programming/Git

[Git] Github Action์œผ๋กœ ์ž๋™์œผ๋กœ ์ž”๋”” ๋งŒ๋“ค์–ด์ฃผ๊ธฐ (Grass Generator Workflow)

ํ•œ์ฝ”๋”ฉ 2023. 9. 12. 17:15
728x90
728x90

์ž๋™์œผ๋กœ ์ž”๋”” ์‹ฌ๋Š” GG (Grass Generator) ๐Ÿคฃ

๋ˆ„๊ตฌ๋‚˜ ์‚ด๋‹ค๋ณด๋ฉด ๋งŒ์‚ฌ๊ฐ€ ๊ท€์ฐฎ์•„์งˆ ๋•Œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.. ๊ทธ๋Ÿผ์—๋„ ๋‹ค์งํ–ˆ๋˜ ๋ชฉํ‘œ๋ฅผ ํ–ฅํ•œ ๋…ธ๋ ฅ์ด ๋ฌด๋„ˆ์งˆ๊นŒ๋ด ๊ฒŒ์œผ๋ฆ„์„ ์ด๊ฒจ๋‚ด๋Š” ์‚ฌ๋žŒ๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ทจ์ค€ ๋‹น์‹œ ๊ฐ€์žฅ ๋ถ€์ง€๋Ÿฐํ•œ ๋ชฉํ‘œ์˜€๋˜ '1์ผ 1์ปค๋ฐ‹'์œผ๋กœ ์ž”๋””๋ฅผ ๋ฌด๋Ÿญ๋ฌด๋Ÿญ ์ž๋ผ๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด ๋ชฉํ‘œ์˜€๋Š”๋ฐ, ์‹œ๊ฐ„์ด ์ง€๋‚˜๊ณ  ํšŒ์‚ฌ ์ผ์— ์น˜์—ฌ์„œ ์ž”๋””๋ฐญ์€ ์ปค๋…• ํƒˆ๋ชจ๊ฐ€ ์™”์Šต๋‹ˆ๋‹ค. 

 

๋ฌผ๋ก  ์—ด์‹ฌํžˆ ํ•ด์•ผํ•˜๋Š”๊ฑธ ์•Œ์ง€๋งŒ ^^ ์ œ๊ฐ€ ๋ฏธ์ณ ์ปค๋ฐ‹ํ•˜์ง€ ๋ชปํ•œ ๋‚ ์ด ๋ฐœ์ƒํ•  ๋•Œ ์ž”๋””๊ฐ€ ๋น ์ ธ์žˆ์ง€ ์•Š๋„๋ก ์ž๋™์œผ๋กœ ์ปค๋ฐ‹ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ์„ ๋งŒ๋“ค๋ฉด ์ฐธ ํŽธํ•˜๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ๋งŒ๋“ค๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฆ„ํ•˜์•ผ... GG...


Github Action Workflow ์ž‘์„ฑํ•˜๊ธฐ

๋นˆ ํ”„๋กœ์ ํŠธ๋ฅผ Github์—์„œ ํŽธํ•˜๊ฒŒ ์•„๋ฌด๋ ‡๊ฒŒ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

set up a workflow yourself ๋ฅผ ๋ˆŒ๋Ÿฌ ๋นˆ yml ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ๋ณธ์ธ์—๊ฒŒ ๋งž๊ฒŒ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

name: Grass Generator

on:
  schedule:
    - cron: "*/5 * * * *"
#   - cron: "0 */12 * * *"

jobs:
  plant_the_grass:
    runs-on: ubuntu-latest
    steps:
      - name: Set up
        uses: actions/checkout@v3
        with:
          repository: ${{ github.repository }}
          token: [github ํ† ํฐ]

      - name: Run script
        run: |
          chmod +x ./scripts/plant_the_grass.sh
          ./scripts/plant_the_grass.sh
        shell: bash

      - name: Commit And push
        run: |
          git add .
          git config --global user.email [๊นƒํ—ˆ๋ธŒ ์ด๋ฉ”์ผ]
          git config --global user.name [๊นƒํ—ˆ๋ธŒ ์ด๋ฆ„]
          git commit -am [์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€]
          git push

 

schedule ๋ถ€๋ถ„์— cron์€ ํ•ด๋‹น action์ด ์–ด๋–ค ์ฃผ๊ธฐ๋กœ ์‹คํ–‰ํ• ์ง€ ์ •ํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํฌ๋ก ํƒญ ๊ด€๋ จ ์ž๋ฃŒ๋ฅผ ํ†ตํ•ด ํ™•์ธํ•ด์ฃผ์„ธ์š”. ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด ์šฐ์„  5๋ถ„ ๊ฐ„๊ฒฉ์œผ๋กœ ์‹คํ–‰๋˜๊ฒŒ ์„ค์ •ํ–ˆ์œผ๋‚˜, 5๋ถ„ ๊ฐ„๊ฒฉ์œผ๋กœ ์ž”๋””๋ฅผ ์‹ฌ๋Š”๊ฑด ๋•…์ด ๋ชป ๊ฒฌ๋”ฅ๋‹ˆ๋‹ค. workflow๊ฐ€ ์ž˜ ์‹คํ–‰๋˜๋Š”์ง€ ํ™•์ธ ํ›„, ์ฃผ๊ธฐ๋ฅผ ์ฃผ์„์ฒ˜๋Ÿผ 12์‹œ๊ฐ„ ๋งˆ๋‹ค or ๊ฐœ์ธ ์ทจํ–ฅ์— ๋งž๊ฒŒ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.

on:
  schedule:
    - cron: "*/5 * * * *"
#   - cron: "0 */12 * * *"

 

[๊ฐœ์ธ์ ์œผ๋กœ ์ฑ„์›Œ์•ผ ํ•˜๋Š” ๋‚ด์šฉ] ๋“ค์„ ๋ชจ๋‘ ์ฑ„์šด ํ›„์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์šฐ๋ฆฌ๋Š” ./script/plant_the_grass.sh ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ์•„๋ž˜ ๋‚ด์šฉ์œผ๋กœ ์ฑ„์›Œ์ค๋‹ˆ๋‹ค. ์œ„์—์„œ ๋งŒ๋“  action์ด ํ•ด๋‹น ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์„ ์‹คํ–‰์‹œํ‚ค๊ณ  ์ถ”๊ฐ€๋œ ๋‚ด์šฉ์„ commit & push๋ฅผ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

#!/bin/bash

current_year=`date +%Y`
current_month=`date +%b`
monthly_file="$current_month.md"

if [ ! -d $current_year ]; then
  mkdir $current_year
fi

cd $current_year
echo -e Today\'s commit date โœจ : `date` \\n >> $monthly_file

 

์ด๋ ‡๊ฒŒ ์„ค์ •ํ•˜๋ฉด ๋ชจ๋‘ ์™„๋ฃŒ! ์ด์ œ ์‹คํ–‰์ด ์ž˜ ๋˜๋Š”์ง€ ํ™•์ธํ•˜์‹  ํ›„์— ๋‹ค์‹œ ์Šค์ผ€์ค„์„ ๋ณ€๊ฒฝํ•ด์„œ ์‚ฌ์šฉํ•˜๋ฉด ๋์ž…๋‹ˆ๋‹ค!

728x90
๋ฐ˜์‘ํ˜•