๐Ÿš€ Github Actions: ๋‹ค๋ฅธ ์›Œํฌํ”Œ๋กœ์—์„œ ์›Œํฌํ”Œ๋กœ๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•˜๋Š” ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•

6143 ๋‹จ์–ด githubdevopscodequalitytesting
GitHub Actions๋Š” ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์›Œํฌํ”Œ๋กœ๋ฅผ ์ž๋™ํ™”ํ•˜๋Š” ๊น”๋”ํ•˜๊ณ  ๊น”๋”ํ•œ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

์ž‘์—…์„ ์‚ฌ์šฉํ•˜๋ฉด ๋‹จ์ผ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ๊ฐ„๋‹จํ•œ ๋ช…๋ น์„ ์ •์˜ํ•˜๊ณ  ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ bash ํŒŒ์ผ๋กœ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์ง€๋งŒ GitHub ์ž‘์—…์œผ๋กœ ์ •์˜ํ•˜๋ฉด ํ›จ์”ฌ ๋” ์‰ฝ๊ฒŒ ์‹คํ–‰(๋ฐ ์œ ์ง€ ๊ด€๋ฆฌ)ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๋ฌธ์„œ์—์„œ๋Š” ๊ฐ„๋‹จํ•˜๊ณ  ์‰ฌ์šด ๋ฐฉ๋ฒ•์œผ๋กœ ๋‹ค๋ฅธ ์›Œํฌํ”Œ๋กœ์—์„œ ์›Œํฌํ”Œ๋กœ๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ด…๋‹ˆ๋‹ค.

**

์ „์ œ ์กฐ๊ฑด:



**
๋‹ค๋ฅธ ์›Œํฌํ”Œ๋กœ์—์„œ ์›Œํฌํ”Œ๋กœ๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•˜๋ ค๋ฉด ๋‹ค์Œ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
  • ๋‚ด๋ถ€์— ์ž‘์—…์ด ์ •์˜๋œ ์ €์žฅ์†Œ(repo_01).
  • ์กฐ์น˜๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•ด์•ผ ํ•˜๋Š” ๋‹ค๋ฅธ ์ €์žฅ์†Œ(repo_02).
  • "Secrets"์— ์ถ”๊ฐ€๋  PAT(Personal Access Token).
  • ๋‹ค๋ฅธ ์›Œํฌํ”Œ๋กœ์˜ PAT๊ฐ€ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์˜ PAT๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์›Œํฌํ”Œ๋กœ๋ฅผ ์‹œ์ž‘ํ•˜๋„๋ก ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•˜๋Š” ๋‹จ์ˆœ ๋ช…๋ น์€ repo_01์˜ ์ž‘์—…์„ ํ˜ธ์ถœํ•˜์—ฌ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  • ์ด์ œ ์šฐ๋ฆฌ๊ฐ€ ์ž‘๋™ํ•˜๊ฒŒ ๋งŒ๋“œ๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ฒƒ์ด ๋ฌด์—‡์ธ์ง€ ์•Œ๊ณ  ๋‚˜๋ฉด ์ž‘๋™ํ•˜๋„๋ก ํ•ฉ์‹œ๋‹ค :D

    PAT ์ƒ์„ฑ:

    ์‚ฌ์šฉ์ž ๊ณ„์ •์— ๋Œ€ํ•œ ๊ฐœ์ธ ์•ก์„ธ์Šค ํ† ํฐ์„ ์ƒ์„ฑํ•˜๋ ค๋ฉด ์‚ฌ์šฉ์ž ํ”„๋กœํ•„ ํƒญ์œผ๋กœ ์ด๋™ํ•˜๊ณ  > ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์—์„œ "์„ค์ •"์˜ต์…˜ > ๊ฐœ์ธ ์•ก์„ธ์Šค ํ† ํฐ์„ ์„ ํƒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.



    ์ƒˆ๋กœ "๊ฐœ๋ฐœ์ž ์„ค์ •"์„ ์„ ํƒํ•˜์‹ญ์‹œ์˜ค.



    "์ƒˆ ํ† ํฐ ์ƒ์„ฑ"์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.



    ์„ค๋ช… ๋ฉ”๋ชจ๋ฅผ ์ œ๊ณตํ•˜๊ฑฐ๋‚˜ ๋น„์›Œ๋‘๊ณ  ์›ํ•˜๋Š” PAT ๋ฒ”์œ„๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.



    Note: PAT is secret and should not be shared; this is to prevent unauthorized access to your account and other repos.



    repo_01 ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ๊ถŒํ•œ์˜ secrets ์„น์…˜์— PAT๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    ์ƒ๋‹จ ํƒ์ƒ‰ ๋ฉ”๋‰ด์—์„œ "์„ค์ •"ํƒญ์œผ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.



    ์™ผ์ชฝ ํƒ์ƒ‰ ํŒจ๋„์—์„œ "๋น„๋ฐ€"์„ ํด๋ฆญํ•œ ๋‹ค์Œ "์ž‘์—…"์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.



    ์ด์ œ "์ƒˆ ์ €์žฅ์†Œ ๋น„๋ฐ€"์„ ์„ ํƒํ•˜์‹ญ์‹œ์˜ค.



    ๋น„๋ฐ€ ์ด๋ฆ„์œผ๋กœ "ACTIONS_KEY"๋ฅผ ์ž…๋ ฅํ•˜๊ณ  "๋น„๋ฐ€"ํ•„๋“œ์— "PAT"๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.


    ์›Œํฌํ”Œ๋กœ ๋งŒ๋“ค๊ธฐ:



    ์ด์ œ ๋‘ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ๋Œ€ํ•œ ์›Œํฌํ”Œ๋กœ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

    ๋จผ์ € ์ฒซ ๋ฒˆ์งธ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์˜ "์ž‘์—…"์œผ๋กœ ์ด๋™ํ•˜๊ณ  "์ƒˆ ์›Œํฌํ”Œ๋กœ"๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

    ํ•„์š”์— ๋”ฐ๋ผ "์›Œํฌํ”Œ๋กœ ์ง์ ‘ ์„ค์ •"๋˜๋Š” ์ œ์•ˆ๋œ ์›Œํฌํ”Œ๋กœ ์ค‘ ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    repo_02 ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ๋™์ผํ•œ ๋‹จ๊ณ„๋ฅผ ์ˆ˜ํ–‰ํ•˜์—ฌ ๋‘ ๋ฒˆ์งธ ์›Œํฌํ”Œ๋กœ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

    ๋งˆ์ง€๋ง‰์œผ๋กœ ๋‘ ์›Œํฌํ”Œ๋กœ๊ฐ€ ์„œ๋กœ ํ˜ธ์ถœํ•˜์—ฌ ์„œ๋กœ ์ƒํ˜ธ ์ž‘์šฉํ•˜๋„๋ก ๊ตฌ์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    repo_01(ํŠธ๋ฆฌ๊ฑฐ ํ๋ฆ„)์—์„œ ๋‹ค์Œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

    Replace userName with the Girhub userName and repoName with the actual Repository name name and the related url to the repository.



    
    name: workflow_01
    on:
      workflow_dispatch:
         inputs:
          workflow_02:
            description: 'ู‹Workflow 2 which will be triggered'
            required: true
            default: 'workflow_02'
    
          workflow2_github_account:
            description: 'GitHub Account Owner'
            required: true
            default: ':userName'
    
          workflow2_repo_github:
            description: 'repo-name'
            required: true
            default: ':repoName' 
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
          - name: Test
            run: |
              curl -X POST https://api.github.com/repos/:userName/:repoName/dispatches \
              -H 'Accept: application/vnd.github.everest-preview+json' \
              -u ${{ secrets.ACTIONS_KEY }} \
              --data '{"event_type": "Trigger Workflow", "client_payload": { "repository": "'"$GITHUB_REPOSITORY"'" }}'
          - uses: actions/checkout@v3
    


    ๊ทธ๋ฆฌ๊ณ  repo_02์—์„œ action ํŒŒ์ผ์— ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

    name: workflow_02
    on: [repository_dispatch]
    jobs:
      cypress-run:
        runs-on: ubuntu-latest
        steps:
          - run: echo "Triggering Wokflow 2"
          - name: Checkout
            uses: actions/checkout@v2
    


    ๋งˆ์ง€๋ง‰์œผ๋กœ ์‚ฌ์šฉํ•ด๋ด…์‹œ๋‹ค :D

    repo_01 > ์ž‘์—… > workflow_01 > ์›Œํฌํ”Œ๋กœ ์‹คํ–‰์œผ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.



    ๊ทธ๋ฆฌ๊ณ  ํƒ€๋‹ค! ์šฐ๋ฆฌ๊ฐ€ ํ•ด๋ƒˆ์–ด

    Workflow_02๊ฐ€ ์ด์ œ workflow_01์— ์˜ํ•ด ํŠธ๋ฆฌ๊ฑฐ๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

    workflow_01



    ์›Œํฌํ”Œ๋กœ์šฐ_02



    ๊ทธ๊ฒŒ ๋‹ค์•ผ! ๐ŸŽ‰

    github ํŠธ๋ฆฌ๊ฑฐ ๋ฐ ์ด๋ฒคํŠธ์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๋ฉด:
    https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows

    ์ฐธ์กฐ:

    GitHub
    LetsDevOps

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ