diff --git a/.github/workflows/cicd-1.yaml b/.github/workflows/cicd-1.yaml new file mode 100644 index 000000000..dc34b177a --- /dev/null +++ b/.github/workflows/cicd-1.yaml @@ -0,0 +1,29 @@ +name: cicd-1 +on: + pull_request: + type: [opened, synchronize, closed] # close를 정의해야 merge될 때 동작제어 가능 + branches: [dev] + paths: + - 'my-app/**' + +jobs: + test: # ci를 위해 실행하는 job + if: github.event.action == 'opened' || github.event.action == 'synchronize' + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + + image-build: # pr이 merge되면 실행 (cd단계) + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + + deploy: # image-bulid 잡이 성공한 다음 실행 (cd단계) + runs-on: ubuntu-latest + needs: [ image-build ] + steps: + - name: checkout + uses: actions/checkout@v4 diff --git a/.github/workflows/part1/issue.yaml b/.github/workflows/part1/issue.yaml new file mode 100644 index 000000000..5bbda9497 --- /dev/null +++ b/.github/workflows/part1/issue.yaml @@ -0,0 +1,15 @@ +name: issue-workflow +on: + issues: + types: [opened] + +jobs: + issue-job: # 디폴트 브랜치에서만 트리거됨 + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github action diff --git a/.github/workflows/part1/issue_comment.yaml b/.github/workflows/part1/issue_comment.yaml new file mode 100644 index 000000000..155a9a6be --- /dev/null +++ b/.github/workflows/part1/issue_comment.yaml @@ -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 }} diff --git a/.github/workflows/part1/multiple_event.yaml b/.github/workflows/part1/multiple_event.yaml new file mode 100644 index 000000000..ac1ff6659 --- /dev/null +++ b/.github/workflows/part1/multiple_event.yaml @@ -0,0 +1,17 @@ +name: multiple-event-workflow +on: + push: + issues: + types: [opened] + workflow_dispatch: + +jobs: + multiple-event-job: + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github action diff --git a/.github/workflows/part1/needs.yaml b/.github/workflows/part1/needs.yaml new file mode 100644 index 000000000..d9ec24bbb --- /dev/null +++ b/.github/workflows/part1/needs.yaml @@ -0,0 +1,29 @@ +name: needs +on: push + +jobs: + job1: + runs-on: ubuntu-latest + steps: + - name: echo + run: echo "job1 done" + + job2: + runs-on: ubuntu-latest + needs: [job1] + steps: + - name: echo + run: echo "job2 done" + job3: + runs-on: ubuntu-latest + steps: + - name: echo + run: | + echo "job3 failed" + exit 1 + job4: + runs-on: ubuntu-latest + needs: [job3] + steps: + - name: echo + run: echo "job4 done" \ No newline at end of file diff --git a/.github/workflows/part1/pull_request.yaml b/.github/workflows/part1/pull_request.yaml new file mode 100644 index 000000000..ba910be09 --- /dev/null +++ b/.github/workflows/part1/pull_request.yaml @@ -0,0 +1,15 @@ +name: pull-request-workflow 1 +on: + pull_request: + types: [opened] # pull_request가 생성된 시점에만 업데이트 해주고 싶을때 + +jobs: + pull-request-job: + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github action \ 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..5cb67cca0 --- /dev/null +++ b/.github/workflows/part1/push.yaml @@ -0,0 +1,13 @@ +name: push-workflow 2 # 액션창에서 표현될 명칭 (생략가능) +on: push #어떤 이벤트로 인해 깃허브액션을 트리거 시킬지 + +jobs: # 실행시킬 job의 집합 (필수값) + push-job: + runs-on: ubuntu-latest #job 안에 실행시킬 runner 지정 + steps: # step의 집합 + - name: step1 # step의 이름 (생략가능) + run: echo hello world + - name: step2 + run: | # | 사용시 멀티라인 커멘드 사용가능 + echo hello world + echo github action \ No newline at end of file diff --git a/.github/workflows/part1/schedule.yaml b/.github/workflows/part1/schedule.yaml new file mode 100644 index 000000000..407a494b7 --- /dev/null +++ b/.github/workflows/part1/schedule.yaml @@ -0,0 +1,11 @@ +name: schedule-workflow +on: + schedule: + - cron: '15 * * * *' + + jobs: + schedule-job: + runs-on: ubuntu-latest + steps: + - name: schedule test + run: echo hello world \ No newline at end of file diff --git a/.github/workflows/part1/workflow_dispatch.yaml b/.github/workflows/part1/workflow_dispatch.yaml new file mode 100644 index 000000000..04b09c718 --- /dev/null +++ b/.github/workflows/part1/workflow_dispatch.yaml @@ -0,0 +1,33 @@ +name: workflow-dispatch +on: + workflow_dispatch: + inputs: + name: + description: 'set name' # name이라는 input에 대한 설명 + required: true # input의 필수값 여부 + default: 'github-actions' # input의 기본값 + type: string # 사용할 데이터 타입 + environment: + description: 'set env' + required: true + default: 'dev' + type: choice + options: + - dev + - qa + - prod + +jobs: + workflow-dispatch-job: # 디폴트 브랜치에서만 트리거됨 + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github action + - name: echo inputs + run: | + echo ${{ inputs.name }} + echo ${{ inputs.environment }} diff --git a/.github/workflows/part2/artifact.yaml b/.github/workflows/part2/artifact.yaml new file mode 100644 index 000000000..cd7474b76 --- /dev/null +++ b/.github/workflows/part2/artifact.yaml @@ -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@v3 + with: + name: artifact-test + path: ./hello.txt + download-artifact: + runs-on: ubuntu-latest + needs: [upload-artifact] + steps: + - name: download artifact + uses: actions/download-artifact@v3 + with: + name: artifact-test + path: ./ + - name: check + run: cat hello.txt \ No newline at end of file diff --git a/.github/workflows/part2/branch-filter.yaml b/.github/workflows/part2/branch-filter.yaml new file mode 100644 index 000000000..1f319db6b --- /dev/null +++ b/.github/workflows/part2/branch-filter.yaml @@ -0,0 +1,11 @@ +name: branch-filter +on: + push: + branches: ["dev"] + +jobs: + branch-filter: + runs-on: ubuntu-latest + steps: + - name: echo + run: echo hello diff --git a/.github/workflows/part2/cache.yaml b/.github/workflows/part2/cache.yaml new file mode 100644 index 000000000..d1c333236 --- /dev/null +++ b/.github/workflows/part2/cache.yaml @@ -0,0 +1,31 @@ +name: cache +on: + push: + paths: + - 'my-app/**' + +jobs: + cache: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: action/checkout@v4 + - name: setup-node + uses: action/setup-node@v3 + with: + node-version: 18 + - name: Cache Node.js modules + uses: action/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 billd \ No newline at end of file diff --git a/.github/workflows/part2/checkout.yaml b/.github/workflows/part2/checkout.yaml new file mode 100644 index 000000000..6892d8a76 --- /dev/null +++ b/.github/workflows/part2/checkout.yaml @@ -0,0 +1,17 @@ +name: checkout +on: workflow_dispatch + +jobs: + no-checout: + runs-on: ubuntu-latest + steps: + - name: check file list + run: cat README.md + + checout: + runs-on: ubuntu-latest + steps: + - name : use checkout action + uses: actions/checkout@v4 + - name: check file list + run: cat README.md \ No newline at end of file diff --git a/.github/workflows/part2/context.yaml b/.github/workflows/part2/context.yaml new file mode 100644 index 000000000..eae07cfdc --- /dev/null +++ b/.github/workflows/part2/context.yaml @@ -0,0 +1,13 @@ +name: context +on: workflow_dispatch + +jobs: + context: + runs-on: ubuntu-latest + steps: + - name: github context + run: echo '${{ toJSON(github) }}' + - name: check github context + run: | + echo ${{ github.repository }} + echo ${{ github.event_name }} \ No newline at end of file diff --git a/.github/workflows/part2/environment.yaml b/.github/workflows/part2/environment.yaml new file mode 100644 index 000000000..747b78090 --- /dev/null +++ b/.github/workflows/part2/environment.yaml @@ -0,0 +1,20 @@ +name: environment +on: push + +jobs: + get-env: + runs-on: ubuntu-latest + steps: + - name: check env & secret + run: | + echo ${{ vars.level }} + echo ${{ secrets.key }} + + get-env-dev: + runs-on: ubuntu-latest + environment: dev + 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.yaml b/.github/workflows/part2/if-1.yaml new file mode 100644 index 000000000..7cc29af9a --- /dev/null +++ b/.github/workflows/part2/if-1.yaml @@ -0,0 +1,28 @@ +name: if-1 +on: + push: + workflow_dispatch: + +jobs: + job1: + runs-on: ubuntu-latest + if: github.event_name == 'push' + steps: + - name: get event name + run: echo ${{ github.event_name }} + job2: + runs-on: ubuntu-latest + if: github.event_name != 'push' + steps: + - name: get event name + run: echo ${{ github.event_name }} + job3: + runs-on: ubuntu-latest + steps: + - name: get event name + if: github.event_name == 'push' + run: echo "PUSH" + - name: get event name + if: github.event_name != 'push' + run: echo "WORKFLOW_DISPATCH" + \ No newline at end of file diff --git a/.github/workflows/part2/if-2.yaml b/.github/workflows/part2/if-2.yaml new file mode 100644 index 000000000..a077d72c9 --- /dev/null +++ b/.github/workflows/part2/if-2.yaml @@ -0,0 +1,20 @@ +name: if-2 +on: push + +jobs: + job1: + runs-on: ubuntu-latest + steps: + - name: exit 1 + run: exit 1 + - name: echo + if: always() + run: echo hello + + job2: + needs: [job1] + runs-on: ubuntu-latest + if: always() + steps: + - name: echo + run: echo hello \ No newline at end of file diff --git a/.github/workflows/part2/matrix.yaml b/.github/workflows/part2/matrix.yaml new file mode 100644 index 000000000..c0caf7ad2 --- /dev/null +++ b/.github/workflows/part2/matrix.yaml @@ -0,0 +1,15 @@ +name: matrix +on: push + +jobs: + get-matrix: + strategy: + matrix: + os: [windows-latest, ubuntu-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/output.yaml b/.github/workflows/part2/output.yaml new file mode 100644 index 000000000..0a2bb5bdd --- /dev/null +++ b/.github/workflows/part2/output.yaml @@ -0,0 +1,23 @@ +name: output +on: push + +jobs: + create-output: + runs-on: ubuntu-latest + outputs: + test: ${{ steps.check-output.outputs.test }} + steps: + - name: echo output + id: check-output + run: | + echo "test=hello" >> $GITHUB_OUTPUT + - name: check output + run: | + echo ${{ steps.check-output.outputs.test }} + + get-output: + needs: [create-output] + 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/path_filter.yaml b/.github/workflows/part2/path_filter.yaml new file mode 100644 index 000000000..8660ad583 --- /dev/null +++ b/.github/workflows/part2/path_filter.yaml @@ -0,0 +1,13 @@ +name: path-filter +on: + push: + paths: + - '.github/workflows/part1/*' + - '!.github/workflows/part1/push.yaml' # ! 특정파일이나 디렉터리를 제외할 때 + +jobs: + path-filter: + runs-on: ubuntu-latest + steps: + - name: echo hello + run: echo hello \ No newline at end of file diff --git a/.github/workflows/part2/secrets.yaml b/.github/workflows/part2/secrets.yaml new file mode 100644 index 000000000..bbf5432a3 --- /dev/null +++ b/.github/workflows/part2/secrets.yaml @@ -0,0 +1,9 @@ +name: secrets +on: push + +jobs: + get-secrets: + runs-on: ubuntu-latest + steps: + - name: get secrets + run: echo ${{ secrets.level }} \ No newline at end of file diff --git a/.github/workflows/part2/string-function.yaml b/.github/workflows/part2/string-function.yaml new file mode 100644 index 000000000..db721e3da --- /dev/null +++ b/.github/workflows/part2/string-function.yaml @@ -0,0 +1,27 @@ +name: string-function +on: push + +jobs: + string-function: + runs-on: ubuntu-latest + steps: + - name: startswith + if: startsWith('github actions', 'git') + run: echo "git" + - name: startswith + if: startsWith('github actions', 'test') + run: echo "test" + + - name: endswith + if: endsWith('github actions', 'ions') + run: echo "ions" + - name: endsWith + if: endsWith('github actions', 'test') + run: echo "test" + + - name: contains + if: contains('github actions', 'act') + run: echo "contains act" + - name: contains + if: contains('github, actions', 'git') + run: echo "contains git" \ No newline at end of file diff --git a/.github/workflows/part2/tag_filter.yaml b/.github/workflows/part2/tag_filter.yaml new file mode 100644 index 000000000..4a24d0fae --- /dev/null +++ b/.github/workflows/part2/tag_filter.yaml @@ -0,0 +1,12 @@ +name: tag-filter # push 이벤트에서만 사용 가능 +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' # v1.0.0의 패턴 + +jobs: + tag-filter: + runs-on: ubuntu-latest + steps: + - name: echo + run: echo hello \ No newline at end of file diff --git a/.github/workflows/part2/timeout.yaml b/.github/workflows/part2/timeout.yaml new file mode 100644 index 000000000..02fc0d364 --- /dev/null +++ b/.github/workflows/part2/timeout.yaml @@ -0,0 +1,19 @@ +name: timeout +on: push + +jobs: + timeout: + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - name: loop + run: | + count=0 + while true; do + echo "seconds: $count" + count=$((count+1)) + sleep 1 + done + timeout-minutes: 1 + - name: echo + run: echo hello \ No newline at end of file diff --git a/.github/workflows/part2/var-1.yaml b/.github/workflows/part2/var-1.yaml new file mode 100644 index 000000000..7d29f393b --- /dev/null +++ b/.github/workflows/part2/var-1.yaml @@ -0,0 +1,41 @@ +name: var-1 +on: push + +env: + level: workflow + +jobs: + get-env-1: + runs-on: ubuntu-latest + steps: + - name: check env + run: echo "LEVEL ${{ env.level }}" + + get-env-2: + runs-on: ubuntu-latest + env: + level: job + steps: + - name: check env + run: echo "LEVEL ${{ env.level }}" + + get-env-3: + runs-on: ubuntu-latest + env: + level: job + steps: + - name: check env + run: echo "LEVEL ${{ env.level }}" + env: + level: step + + get-env: + runs-on: ubuntu-latest + steps: + - name: create 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.yaml b/.github/workflows/part2/var-2.yaml new file mode 100644 index 000000000..b8791f216 --- /dev/null +++ b/.github/workflows/part2/var-2.yaml @@ -0,0 +1,9 @@ +name: var-2 +on: push + +jobs: + get-var: + 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.yaml b/.github/workflows/part3/create_repo.yaml new file mode 100644 index 000000000..1a040a823 --- /dev/null +++ b/.github/workflows/part3/create_repo.yaml @@ -0,0 +1,52 @@ +name: create-repo +on: + workflow_dispatch: + inputs: + prefix: + description: 'set repo prefix' + required: true + default: 'service' + 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.PERSONAL_ACCESS_TOKEN }} | gh auth login --with-token + - name: create-repo + id: create-repo + run: | + gh repo create heesun-action/${{ inputs.prefix }}-${{ inputs.name }} --public --add-readme + - name: slack + if: always() + uses: slackapi/slack-github-action@v1.24.0 + with: + payload: | + { + "attachments": [ + { + "pretext": "create repo result", + "color": "28a745", + "fields": [ + { + "title": "create repo result ${{ steps.create-repo.outcome }}", + "short": true, + "value": "${{ inputs.prefix }}-${{ inputs.name }}" + } + ] + } + ] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK \ No newline at end of file diff --git a/.github/workflows/part3/issue_notify.yaml b/.github/workflows/part3/issue_notify.yaml new file mode 100644 index 000000000..190849d28 --- /dev/null +++ b/.github/workflows/part3/issue_notify.yaml @@ -0,0 +1,61 @@ +name: issue-notify + +on: + issues: + types: [opened] + +jobs: + get-keyword: + runs-on: ubuntu-latest + outputs: + level: ${{ steps.get-keyword.outputs.level }} + steps: + - name: checkout + uses: actions/checkout@v4 + - name: get keyword + id: get-keyword + run: | + echo level=Undefined >> $GITHUB_OUTPUT + + keywords=$(cat keyword-list.txt) + for keyword in $keywords; do + if [[ "${{ github.event.issue.title }}" =~ "$keyword" ]]; then + echo level=$keyword >> $GITHUB_OUTPUT + fi + done + - name: get output + run: | + echo ${{ steps.get-keyword.outputs.level }} + + slack: + needs: [get-keyword] + if: needs.get-keyword.outputs.level != 'Undefined' + runs-on: ubuntu-latest + # environment: ${{ needs.get-keyword.outputs.level }} + strategy: + matrix: # 어떤 환경을 사용했는지 파악 가능 + environment: ["${{ needs.get-keyword.outputs.level }}"] + environment: ${{ matrix.environment }} + steps: + - name: slack + uses: slackapi/slack-github-action@v1.24.0 + with: + payload: | + { + "attachments": [ + { + "pretext": "issue alert message", + "color": "28a745", + "fields": [ + { + "title": "Level : ${{ needs.get-keyword.outputs.level }}", + "short": true, + "value": "issue url : ${{ github.event.issue.html_url }}" + } + ] + } + ] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK 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..c86e36bdd --- /dev/null +++ b/keyword-list.txt @@ -0,0 +1,3 @@ +critical +normal +high \ No newline at end of file diff --git a/my-app/src/App.js b/my-app/src/App.js index 725bc9db5..1967100f8 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 cicd1-aws1