diff --git a/.github/workflows/cicd1-1.yml b/.github/workflows/cicd1-1.yml new file mode 100644 index 000000000..88930a820 --- /dev/null +++ b/.github/workflows/cicd1-1.yml @@ -0,0 +1,118 @@ +name: cicd-1 +on: + pull_request: + types: [opened,synchronize,closed] + branches: [dev] + paths: + - 'my-app/**' +jobs: + test: # 테스트 작업 + if: github.event.action == 'opened' || github.event.action == 'synchronize' + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + - name: setup-node + uses: actions/setup-node@v3 + with: + node-version: '18' + - name: Cache Node.js modules + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install Dependencies + run: | + cd my-app + npm ci + - name: npm build + run: | + cd my-app + npm run build + + + image-build: # 이미지 빌드 작업 + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + permissions: # 권한 설정 + id-token: write + contents: read + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: aws + id: credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-region: ${{vars.AWS_REGION}} + role-to-assume: ${{secrets.AWS_ROLE_TO_ASSUME}} + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + with: + mask-password: 'true' + - name: docker build & push + run: | + docker build -f Dockerfile -tag ${{secrets.REGISTRY}}/${{vars.REPOSITORY}}:${{github.sha}} . + docker push ${{secrets.REGISTRY}}/${{vars.REPOSITORY}}:${{github.sha}} + + + deploy: # 배포 작업 + runs-on: ubuntu-latest + needs: [image-build] # image-build 스텝이 성공적으로 완료되면 실행 + # 권한 설정 + permissions: + id-token: write + contents: read + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: aws + id: credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-region: ${{vars.AWS_REGION}} + role-to-assume: ${{secrets.AWS_ROLE_TO_ASSUME}} + - name: setup kubectl + uses: azure/setup-kubectl@v3 + with: + version: latest + - name: setup helm + uses: azure/setup-helm@v3 + with: + version: v3.11.1 + + - name: access kubernetes + run: | + aws eks update-kubeconfig --name ${{vars.EKS_CLUSTER_NAME}} + - name: deploy + id: status + run: | + helm upgrade --install my-app kube/my-app --create-namespace --namespace my-app-${{vars.SUFFIX}} \ + --set image.tag=${{github.sha}} \ + --set image.repository=${{vars.REPOSITORY}}/${{vars.REPOSITORY}} + - name: notify + if: always() + # slack 알림 + uses: slackapi/slack-github-action@v2.0.0 + with: + webhook: ${{ secrets.SLACK_KEY }} + webhook-type: incoming-webhook + payload-templated: true + payload: | + { + "text":"message", + "blocks":[ + { + "type":"section", + "text":{ + "type":"mrkdwn", + "text":"Environment : dev, Deployed : ${{steps.status.outcome}}, Repository : ${{github.repository}}" + } + } + ] + } \ No newline at end of file diff --git a/.github/workflows/part1/issue.yml b/.github/workflows/part1/issue.yml new file mode 100644 index 000000000..aa2e70a5d --- /dev/null +++ b/.github/workflows/part1/issue.yml @@ -0,0 +1,15 @@ +name: issue-workflow +on: + issues: + types: [opened] # issue가 열릴 때만 workflow 실행 + +jobs: + issue-job: #이슈가 트리거 되면 작동 + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo "hello world" + - name: step2 + run: | + echo "hello world2" + echo "hello world3" \ No newline at end of file diff --git a/.github/workflows/part1/issue_comment.yml b/.github/workflows/part1/issue_comment.yml new file mode 100644 index 000000000..168286f1d --- /dev/null +++ b/.github/workflows/part1/issue_comment.yml @@ -0,0 +1,17 @@ +name: issue-comment-workflow +on: issue_comment + +jobs: + pr-comment: + if: ${{github.event.issue.pull_request}} + runs-on: ubuntu-latest + steps: + - name: pr comment + run: echo ${{github.event.issue.pull_request}} + + issue-comment: + if: ${{!github.event.issue.pull_request}} + runs-on: ubuntu-latest + steps: + - name: issue comment + run: echo ${{github.event.issue.pull_request}} \ No newline at end of file diff --git a/.github/workflows/part1/mutiple_event.yml b/.github/workflows/part1/mutiple_event.yml new file mode 100644 index 000000000..eae071f7e --- /dev/null +++ b/.github/workflows/part1/mutiple_event.yml @@ -0,0 +1,18 @@ +name: mulitple-event-workflow +on: + push: + issues: + types: [opened] + # 푸쉬, 이슈,수동 트리거에서도 작동 + workflow_dispatch: + +jobs: + mulitple-event-job: + runs-on: ubuntu-latest + steps: + - name: mulitple event + run: echo "hello world" + - name: step2 + run: | + echo hello world + echo gihub action \ No newline at end of file diff --git a/.github/workflows/part1/needs.yml b/.github/workflows/part1/needs.yml new file mode 100644 index 000000000..60707fe3c --- /dev/null +++ b/.github/workflows/part1/needs.yml @@ -0,0 +1,30 @@ +name: needs +on: push + +jobs: + job1: + runs-on: ubuntu-latest + steps: + - name: job1 + run: echo "job1" + + job2: + runs-on: ubuntu-latest + needs: [job1] # 종속성 설정 + steps: + - name: job2 + run: echo "job2" + + job3: + runs-on: ubuntu-latest + steps: + - name: job3 # 동시에 실행 + run: | + echo "job3 failed" + exit 1 + job4: + runs-on: ubuntu-latest + needs: [job3] # 종속성 설정 job3이 실패하면 실행 안됨 + steps: + - name: job4 + run: echo "job4" diff --git a/.github/workflows/part1/pull_request.yaml b/.github/workflows/part1/pull_request.yaml new file mode 100644 index 000000000..9875bb9e0 --- /dev/null +++ b/.github/workflows/part1/pull_request.yaml @@ -0,0 +1,15 @@ +name: pull_request-workflow +on: + pull_request: + #types: [opened, synchronize] # pull_request가 열리거나 업데이트 될 때 workflow 실행 + types: [opened] # pull_request가 열릴 때만 workflow 실행 +jobs: + push-job: + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo "hello world" + - name: step2 + run: | + echo "hello world2" + echo "hello world3" \ No newline at end of file diff --git a/.github/workflows/part1/push.yaml b/.github/workflows/part1/push.yaml new file mode 100644 index 000000000..689ac3f26 --- /dev/null +++ b/.github/workflows/part1/push.yaml @@ -0,0 +1,13 @@ + name: push-workflow + on: push #push 이벤트가 발생할 때 workflow 실행 + + jobs: # 잡 필수(하나 이상 필요) + push-job: + runs-on: ubuntu-latest # 실행 환경 + steps: + - name: step1 # 단계 이름 + run: echo "hello world" # 실행할 명령어 + - name: step2 # 단계 이름 + run: | # 여러 줄의 명령어 실행 + echo "hello world2" + echo "hello world3" \ No newline at end of file diff --git a/.github/workflows/part1/re-run.yml b/.github/workflows/part1/re-run.yml new file mode 100644 index 000000000..3500bdc89 --- /dev/null +++ b/.github/workflows/part1/re-run.yml @@ -0,0 +1,13 @@ +name: re-run +on: push + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: test + uses: actions/checkout@v4 # checkout 액션 사용 + - name: test2 + run: | + echo "test2" + cat README.md \ No newline at end of file diff --git a/.github/workflows/part1/workflow_dispatch.yml b/.github/workflows/part1/workflow_dispatch.yml new file mode 100644 index 000000000..3ac594e25 --- /dev/null +++ b/.github/workflows/part1/workflow_dispatch.yml @@ -0,0 +1,33 @@ +name: workflow_dispatch-workflow +on: + workflow_dispatch: + inputs: + name: + description: 'set name' + required: true # 필수냐? + default: 'github-actions' + type: string + environment: + description: 'set env' + required: true + default: 'dev' + type: choice + options: + - dev + - prod + - qa + +jobs: + workflow_dispatch-job: + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo "hello world" + - name: step2 + run: | + echo "hello world2" + echo "hello world3" + - name: echo inputs + run: | + echo ${{ inputs.name }} # 입력받은 name 출력 + echo ${{ inputs.environment }} # 입력받은 environment 출력 \ No newline at end of file diff --git a/.github/workflows/part2/artifact.yml b/.github/workflows/part2/artifact.yml new file mode 100644 index 000000000..238aad6a9 --- /dev/null +++ b/.github/workflows/part2/artifact.yml @@ -0,0 +1,25 @@ +name: artifact +on: push +jobs: + upload-artifact: + runs-on: ubuntu-latest + steps: + - name: echo + run: echo hello-world > hello.txt + - name: upload artifact + uses: actions/upload-artifact@v4 # artifact 업로드 액션 사용 + with: + name: artifact-test + path: ./hello.txt + + download-artifact: + needs: [upload-artifact] # upload-artifact 잡이 성공적으로 완료되어야만 실행 + runs-on: ubuntu-latest + steps: + - name: download artifact + uses: actions/download-artifact@v4 # artifact 다운로드 액션 사용 + with: + name: artifact-test + path: ./ # 현재 디렉토리에 다운로드 + - name: cat + run: cat hello.txt \ No newline at end of file diff --git a/.github/workflows/part2/branch_filter.yml b/.github/workflows/part2/branch_filter.yml new file mode 100644 index 000000000..bd3ea7c54 --- /dev/null +++ b/.github/workflows/part2/branch_filter.yml @@ -0,0 +1,11 @@ +name: branch-filter +on: + push: # push 이벤트 발생 시 + branches: ["dev"] # dev 브래치에만 적용 + +jobs: + branch-filter: + runs-on: ubuntu-latest + steps: + - name: branch-filter + run: echo "branch-filter" \ No newline at end of file diff --git a/.github/workflows/part2/cacha.yml b/.github/workflows/part2/cacha.yml new file mode 100644 index 000000000..48fa98f52 --- /dev/null +++ b/.github/workflows/part2/cacha.yml @@ -0,0 +1,32 @@ +name: cache +on: + push: + paths: + - 'my-app/**' # myapp 디렉토리 내 파일이 변경되었을 때만 workflow 실행 + +jobs: + cache: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 # 깃허브에서 제공하는 체크아웃 액션 사용 + - name: setup-node + uses: actions/setup-node@v3 # 노드.js 설정 액션 사용 + with: + node-version: 18 + - name: Cache node.js modules + uses: actions/cache@v3 # 캐시 액션 사용 + with: + path: ~/.npm # npm 패키지 캐시 경로 + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + # {{사용할 os}}-node-{{package-lock.json 파일의 해시값}}으로 키 생성 + restore-keys: | + ${{ runner.os }}-node- + - name: Install dependencies + run: | + cd my-app + npm ci + - name: npm build + run: | + cd my-app + npm run build \ No newline at end of file diff --git a/.github/workflows/part2/checkout.yml b/.github/workflows/part2/checkout.yml new file mode 100644 index 000000000..4e871aa4c --- /dev/null +++ b/.github/workflows/part2/checkout.yml @@ -0,0 +1,20 @@ +name: checkout +on: workflow_dispatch + +jobs: + no-checkout: # github 레포지토리를 가지고 오지 않고 사용 + runs-on: ubuntu-latest + steps: + - name: no-checkout # run 에러(README.md 파일이 없음) + run: | + echo "no-checkout" + cat README.md + checkout: # github 레포지토리를 가지고 와서 사용 + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 # checkout 액션 사용 + - name: checkout2 # checkout 액션을 사용하여 README.md 파일을 가지고 와서 사용 + run: | + echo "checkout2" + cat README.md \ No newline at end of file diff --git a/.github/workflows/part2/context.yml b/.github/workflows/part2/context.yml new file mode 100644 index 000000000..bd298f4fb --- /dev/null +++ b/.github/workflows/part2/context.yml @@ -0,0 +1,14 @@ +name: context +on: workflow_dispatch + +jobs: + context: + runs-on: ubuntu-latest + steps: + - name: github context + run: echo '${{toJSON(github)}}' + # 내 github 내용을 josn으로 변환하여 출력 + - name: check github context + run: | + echo ${{github.repository}} # github 레포지토리 정보 출력 + echo ${{github.event_name}} # github 이벤트 이름 출력 \ No newline at end of file diff --git a/.github/workflows/part2/environment.yml b/.github/workflows/part2/environment.yml new file mode 100644 index 000000000..154d2c5bf --- /dev/null +++ b/.github/workflows/part2/environment.yml @@ -0,0 +1,10 @@ +name: environment +on: push +jobs: + get-env: + runs-on: ubuntu-latest + steps: + - name: check env & secret + run: | + echo ${{vars.level}} + echo ${{secrets.key}} \ No newline at end of file diff --git a/.github/workflows/part2/if-1.yml b/.github/workflows/part2/if-1.yml new file mode 100644 index 000000000..a7ee51fbe --- /dev/null +++ b/.github/workflows/part2/if-1.yml @@ -0,0 +1,27 @@ +name: if-1 +on: + push: # push 발생시 + workflow_dispatch: # 수동 실행 + +jobs: + job1: + runs-on: ubuntu-latest + if: github.event_name == 'push' # push 이벤트 발생시만 실행 + steps: + - name: job1 + run: echo ${{ github.event_name }} + job2: + runs-on: ubuntu-latest + if: github.event_name != 'push' # workflow_dispatch 이벤트 발생시만 실행 + steps: + - name: job2 + run: echo ${{ github.event_name }} + job3: + runs-on: ubuntu-latest + steps: + - name: job3-step1 + if: github.event_name == 'push' # 스탭 단위 + run: echo ${{ github.event_name }} + - name: job3-step2 + if: github.event_name != 'push' # 스탭 단위 + run: echo ${{ github.event_name }} \ No newline at end of file diff --git a/.github/workflows/part2/if-2.yml b/.github/workflows/part2/if-2.yml new file mode 100644 index 000000000..b2e13c7ad --- /dev/null +++ b/.github/workflows/part2/if-2.yml @@ -0,0 +1,18 @@ +name: if-2 +on: push +jobs: + job1: + runs-on: ubuntu-latest + steps: + - name: exit + run: exit 1 + - name: echo + if: always() # 항상 실행 + run: echo "job1" + job2: + needs: job1 + runs-on: ubuntu-latest + if: always() # 항상 실행 + steps: + - name: echo + run: echo "job2" \ No newline at end of file diff --git a/.github/workflows/part2/matrix.yml b/.github/workflows/part2/matrix.yml new file mode 100644 index 000000000..0cdc4c852 --- /dev/null +++ b/.github/workflows/part2/matrix.yml @@ -0,0 +1,14 @@ +name: matrix +on: push +jobs: + get-matrix: # job name + strategy: # matrix 설정 + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + version: [12,14] + runs-on: ${{ matrix.os }} + steps: + - name: check matrix + run: | + echo ${{matrix.os}} + echo ${{matrix.version}} \ No newline at end of file diff --git a/.github/workflows/part2/path_filter.yml b/.github/workflows/part2/path_filter.yml new file mode 100644 index 000000000..26afafb17 --- /dev/null +++ b/.github/workflows/part2/path_filter.yml @@ -0,0 +1,13 @@ +name: path-filter +on: + push: + paths: # 특정 파일이 변경되었을 때만 workflow 실행 + - '.github/workflows/part1/*' # .github/workflows/part1/ 디렉토리 내 파일이 변경되었을 때 + - '!.github/workflows/part1/push.yaml' # .github/workflows/part1/push.yml은 제외 + +jobs: + path-filter: + runs-on: ubuntu-latest + steps: + - name: path-filter + run: echo "path-filter" \ No newline at end of file diff --git a/.github/workflows/part2/secrets.yml b/.github/workflows/part2/secrets.yml new file mode 100644 index 000000000..6497c6eb4 --- /dev/null +++ b/.github/workflows/part2/secrets.yml @@ -0,0 +1,8 @@ +name: secrets +on: push +jobs: + get-secrets: + runs-on: ubuntu-latest + steps: + - name: get secrets + run: echo ${{secrets.mylevel}} \ No newline at end of file diff --git a/.github/workflows/part2/string-function.yml b/.github/workflows/part2/string-function.yml new file mode 100644 index 000000000..74c85ffa8 --- /dev/null +++ b/.github/workflows/part2/string-function.yml @@ -0,0 +1,27 @@ +name: string-function +on: push + +jobs: + string-function: + runs-on: ubuntu-latest + steps: + - name: startswith + if: startsWith('github', 'git') + run: echo "git" + - name: startswith + if: startsWith('github', 'hub') + run: echo "hub" + + - name: endswith + if: endsWith('github', 'hub') + run: echo "hub" + - name: endswith + if: endsWith('github', 'git') + run: echo "git" + + - name: contains + if: contains('github', 'hub') + run: echo "hub" + - name: contains + if: contains('github', 'git') + run: echo "git" \ No newline at end of file diff --git a/.github/workflows/part2/tag_filter.yml b/.github/workflows/part2/tag_filter.yml new file mode 100644 index 000000000..ee86d3075 --- /dev/null +++ b/.github/workflows/part2/tag_filter.yml @@ -0,0 +1,13 @@ +name: tag-filter +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' # v로 시작하고 0-9 사이의 숫자가 3개인 태그가 push될 때만 workflow 실행 + #v1.0.0, v2.0.0, v3.0.0, ...(1, 1.0은 트리거 되지 않음) + +jobs: + tag-filter: + runs-on: ubuntu-latest + steps: + - name: tag-filter + run: echo "tag-filter" diff --git a/.github/workflows/part2/test_output.yml b/.github/workflows/part2/test_output.yml new file mode 100644 index 000000000..7379321b3 --- /dev/null +++ b/.github/workflows/part2/test_output.yml @@ -0,0 +1,16 @@ +name: output +on: push +jobs: + output-job: + runs-on: ubuntu-latest + steps: + - name: echo + id: check1 + run: echo "test=hello" >> "$GITHUB_OUTPUT" + - name: output + id: check2 + run: echo "test=hello2" >> "$GITHUB_OUTPUT" + - name: check + run: | + echo ${{ steps.check1.outputs.test }} + echo ${{ steps.check2.outputs.test }} \ No newline at end of file diff --git a/.github/workflows/part2/test_output2.yml b/.github/workflows/part2/test_output2.yml new file mode 100644 index 000000000..3a98abb89 --- /dev/null +++ b/.github/workflows/part2/test_output2.yml @@ -0,0 +1,22 @@ +name: output2 +on: push +jobs: + create-output: + runs-on: ubuntu-latest + outputs: # 잡 실행 결과를 다른 잡에 전달 + test: ${{steps.check.outputs.test}} + steps: + - name: echo output + id: check + run: | + echo "test=hello" >> "$GITHUB_OUTPUT" + - name: check2 + run: | + echo ${{ steps.check.outputs.test }} + + get-output: + needs: [create-output] # create-job이 성공적으로 완료되어야만 실행 + runs-on: ubuntu-latest + steps: + - name: get output + run: echo ${{needs.create-output.outputs.test}} \ No newline at end of file diff --git a/.github/workflows/part2/timeout.yml b/.github/workflows/part2/timeout.yml new file mode 100644 index 000000000..bd3c9159c --- /dev/null +++ b/.github/workflows/part2/timeout.yml @@ -0,0 +1,19 @@ +name: timeout +on: push + +jobs: + timeout: + runs-on: ubuntu-latest + timeout-minutes: 2 # 2분 후에 workflow 종료 + steps: + - name: loop + run: | + count=0 + while true; do + echo "count: $count" + count=$(($count+1)) + sleep 10 + done + timeout-minutes: 1 # 1분 후에 step 종료 + - name: echo + run: echo "hello world" \ No newline at end of file diff --git a/.github/workflows/part2/var-1.yml b/.github/workflows/part2/var-1.yml new file mode 100644 index 000000000..e1ece5136 --- /dev/null +++ b/.github/workflows/part2/var-1.yml @@ -0,0 +1,34 @@ +name: var-1 +on: push + +env: + level: work +jobs: + get-env-1: + runs-on: ubuntu-latest + steps: + - name: get env + run: echo ${{ env.level }} + get-env-2: + runs-on: ubuntu-latest + env: + level: job + steps: + - name: check env + run: echo ${{ env.level }} + get-env-3: + runs-on: ubuntu-latest + env: + level: job + steps: + - name: check env + run: echo ${{ env.level }} + env: + level: step + get-env: + runs-on: ubuntu-latest + steps: + - name: check env + run: echo "level=job">> $GITHUB_ENV + - name: check env + run: echo "LEVEL ${{env.level}}" \ No newline at end of file diff --git a/.github/workflows/part2/var-2.yml b/.github/workflows/part2/var-2.yml new file mode 100644 index 000000000..314cc5ad7 --- /dev/null +++ b/.github/workflows/part2/var-2.yml @@ -0,0 +1,9 @@ +name: var-2 +on: push + +jobs: + get-ver: + runs-on: ubuntu-latest + steps: + - name: get var + run: echo ${{vars.level}} \ No newline at end of file diff --git a/.github/workflows/part3/create_repo.yml b/.github/workflows/part3/create_repo.yml new file mode 100644 index 000000000..89ca0716e --- /dev/null +++ b/.github/workflows/part3/create_repo.yml @@ -0,0 +1,56 @@ +name: create-repo +on: + workflow_dispatch: + inputs: + prefix: + description: "set repo prefix" + required: true # 필수 입력값라고 설정 + default: "service2" # 기본값 설정(입력값이 없을 때) + type: choice + options: + - example + - service + + name: + description: "set repo name" + required: true + default: "github-actions" + type: string +jobs: + create-repo-automation: + runs-on: ubuntu-latest + steps: + - name: gh auth login + run: | + echo ${{secrets.MYKEY}} | gh auth login --with-token + # 토큰으로 로그인 + - name: create-repo + id: create-repo + run: | + gh repo create r2d2c2/${{inputs.prefix}}-${{inputs.name}} --public --add-readme + # 퍼블릭 레포지토리 생성 + + - name: slack + if: always() + uses: slackapi/slack-github-action@v2.0.0 + with: + webhook: ${{ secrets.SLACK_KEY }} + webhook-type: incoming-webhook + payload-templated: true + payload: | + { + "attachments":[ + { + "pretext":"create repo result", + "color":"#36a64f", + "fields":[ + { + "title":"create repo result ${{steps.create-repo.outcome}}", + "short":true, + "value":"${{inputs.prefix}}-${{inputs.name}}" + } + ] + } + ] + } + diff --git a/.github/workflows/part3/issue_notify.yml b/.github/workflows/part3/issue_notify.yml new file mode 100644 index 000000000..1ca8001c7 --- /dev/null +++ b/.github/workflows/part3/issue_notify.yml @@ -0,0 +1,60 @@ +name: issue-notify # 워크플로우 이름 +on: + issues: + types: [opened] # 이슈가 열릴 때 트리거 + +jobs: + get-keyword: + runs-on: ubuntu-latest # 최신 우분투 환경에서 실행 + outputs: + level: ${{steps.get-keyword.outputs.level}} # get-keyword 스텝의 출력값을 level로 설정 + steps: + - name: checkout + uses: actions/checkout@v4 # 깃헙 레포지토리를 체크아웃 + - name: get keyword + id: get-keyword + run: | + echo level=Undefined>>$GITHUB_OUTPUT # 기본 level 값을 Undefined로 설정 + keywords=$(cat keyword-list.txt) # keyword-list.txt 파일에서 키워드 목록을 읽음 + for keyword in $keywords; do + if [[ "${{github.event.issue.title}}" =~ "$keyword" ]]; then # 이슈 제목에 키워드가 포함되어 있는지 확인 + echo level=$keyword>>$GITHUB_OUTPUT # 포함되어 있으면 level 값을 해당 키워드로 설정 + fi + done + - name: get output + run: | + echo ${{steps.get-keyword.outputs.level}} # level 값을 출력 + +# slack 추가 + slack: + needs: [get-keyword] # get-keyword 스텝이 성공적으로 완료되면 실행 + if: needs.get-keyword.outputs.level != 'Undefined' + # get-keyword 스텝의 level 값이 Undefined가 아닐 때만 실행 + runs-on: ubuntu-latest + strategy: # 매트릭스 전략 사용 + matrix: # 매트릭스 설정 + environment: ["${{needs.get-keyword.outputs.level}}"] # get-keyword 스텝의 level 값으로 환경 설정 + environment: ${{ matrix.environment }} # 매트릭스 환경 설정 + steps: + - name: slack + uses: slackapi/slack-github-action@v2.0.0 # 슬랙 액션 사용 + with: + webhook: ${{ secrets.SLACK_KEY }} # 시크릿에 저장된 슬랙 키 사용 + webhook-type: incoming-webhook + payload-templated: true + payload: | + { + "attachments":[ + { + "pretext":"issue alert message", + "color":"#36a64f", + "fields":[ + { + "title":"Level : ${{needs.get-keyword.outputs.level}}", + "short":true, + "value":"${{github.event.issue.html_url}}" + } + ] + } + ] + } \ No newline at end of file diff --git a/.github/workflows/part4/cicd-1.yml b/.github/workflows/part4/cicd-1.yml new file mode 100644 index 000000000..28572c1d3 --- /dev/null +++ b/.github/workflows/part4/cicd-1.yml @@ -0,0 +1,26 @@ +name: cicd-1 +on: + pull_request: + types: [opened,synchronize,closed] # PR이 열리거나 동기화되거나 닫힐 때 트리거 + branches: [dev] # dev 브랜치에서만 트리거 + paths: + - 'my-app/**' # my-app 디렉토리에서만 트리거 +jobs: + test: # 테스트 작업 + if: github.event.action == 'opened' || github.event.action == 'synchronize' + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + image-build: # 이미지 빌드 작업 + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + deploy: # 배포 작업 + runs-on: ubuntu-latest + needs: [image-build] # image-build 스텝이 성공적으로 완료되면 실행 + steps: + - name: checkout + uses: actions/checkout@v4 \ No newline at end of file diff --git a/README.md b/README.md index ea85d664a..f794ef38f 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# github-actions-setting \ No newline at end of file +# github-actions-setting 1 diff --git a/keyword-list.txt b/keyword-list.txt new file mode 100644 index 000000000..503fe1db0 --- /dev/null +++ b/keyword-list.txt @@ -0,0 +1,2 @@ +critical +normal \ No newline at end of file diff --git a/kubernetes/create-cluster.yaml b/kubernetes/create-cluster.yaml index 7357f45c6..3162ff3d2 100644 --- a/kubernetes/create-cluster.yaml +++ b/kubernetes/create-cluster.yaml @@ -4,7 +4,7 @@ kind: ClusterConfig metadata: name: github-actions-cluster region: ap-northeast-2 - version: "1.29" + version: "1.32" iamIdentityMappings: - arn: arn:aws:iam::${ACCOUNT_ID}:role/github-actions diff --git a/my-app/src/App.js b/my-app/src/App.js index 725bc9db5..17967108c 100644 --- a/my-app/src/App.js +++ b/my-app/src/App.js @@ -15,7 +15,7 @@ function App() { target="_blank" rel="noopener noreferrer" > - Learn GithubAction cicd + Learn GithubAction run cicd1