diff --git a/.github/workflows/cicd-1.yaml b/.github/workflows/cicd-1.yaml new file mode 100644 index 000000000..a13f766b7 --- /dev/null +++ b/.github/workflows/cicd-1.yaml @@ -0,0 +1,29 @@ +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 + + 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] + 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..f584dff5d --- /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..b56c3b287 --- /dev/null +++ b/.github/workflows/part1/issue_comment.yaml @@ -0,0 +1,16 @@ +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..733aee6f2 --- /dev/null +++ b/.github/workflows/part1/multiple_event.yaml @@ -0,0 +1,18 @@ +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..686efa5ed --- /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 "job1 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" + diff --git a/.github/workflows/part1/pull_request.yaml b/.github/workflows/part1/pull_request.yaml new file mode 100644 index 000000000..e1fd1f83a --- /dev/null +++ b/.github/workflows/part1/pull_request.yaml @@ -0,0 +1,13 @@ +name: pull-request-workflow 1 +on: pull_request + +jobs: + push-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/push.yaml b/.github/workflows/part1/push.yaml new file mode 100644 index 000000000..23731e816 --- /dev/null +++ b/.github/workflows/part1/push.yaml @@ -0,0 +1,13 @@ +name: push-workflow 2 +on: push + +jobs: + push-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/workflow_dispatch.yaml b/.github/workflows/part1/workflow_dispatch.yaml new file mode 100644 index 000000000..0d18c10a7 --- /dev/null +++ b/.github/workflows/part1/workflow_dispatch.yaml @@ -0,0 +1,33 @@ +name: workflow-dispatch +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 + - qa + - prod + +jobs: + workflow-disptch-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..e0b79bdde --- /dev/null +++ b/.github/workflows/part2/artifact.yaml @@ -0,0 +1,26 @@ +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 diff --git a/.github/workflows/part2/branch_filter.yaml b/.github/workflows/part2/branch_filter.yaml new file mode 100644 index 000000000..5a8d6fffa --- /dev/null +++ b/.github/workflows/part2/branch_filter.yaml @@ -0,0 +1,10 @@ +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..5847c575f --- /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: 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 diff --git a/.github/workflows/part2/checkout.yaml b/.github/workflows/part2/checkout.yaml new file mode 100644 index 000000000..de170b944 --- /dev/null +++ b/.github/workflows/part2/checkout.yaml @@ -0,0 +1,17 @@ +name: checkout +on: workflow_dispatch + +jobs: + no-checkout: + runs-on: ubuntu-latest + steps: + - name: check file list + run: cat README.md + checkout: + runs-on: ubuntu-latest + steps: + - name: use checkout action + uses: actions/checkout@v4 + - name: check file list + run: cat README.md + diff --git a/.github/workflows/part2/context.yaml b/.github/workflows/part2/context.yaml new file mode 100644 index 000000000..34b2dcf3b --- /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 }} diff --git a/.github/workflows/part2/create_repo.yaml b/.github/workflows/part2/create_repo.yaml new file mode 100644 index 000000000..8a59d2b1d --- /dev/null +++ b/.github/workflows/part2/create_repo.yaml @@ -0,0 +1,40 @@ +name: create-repo +on: + workflow_dispatch: + inputs: + prefix: + description: 'set repo prefix' + required: true + default: 'service' + type: choice + options: + - example + - service + - hello + 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 # Step에 ID 추가 + run: | + gh repo create ghactions-practice/${{ inputs.prefix }}-${{ inputs.name }} --public --add-readme ## 레포 생성 + - name: slack + if: always() + uses: slackapi/slack-github-action@v1.24.0 + with: + payload: | + { + "text": "Repository: ${{ inputs.prefix }}-${{ inputs.name }} ${{ job.status }}" + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/part2/environment.yaml b/.github/workflows/part2/environment.yaml new file mode 100644 index 000000000..873465d0b --- /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 }} diff --git a/.github/workflows/part2/if-1.yaml b/.github/workflows/part2/if-1.yaml new file mode 100644 index 000000000..decbcb512 --- /dev/null +++ b/.github/workflows/part2/if-1.yaml @@ -0,0 +1,27 @@ +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" diff --git a/.github/workflows/part2/if-2.yaml b/.github/workflows/part2/if-2.yaml new file mode 100644 index 000000000..e7c232f49 --- /dev/null +++ b/.github/workflows/part2/if-2.yaml @@ -0,0 +1,17 @@ +name: if-2 +on: push + +jobs: + job1: + runs-on: ubuntu-latest + steps: + - name: exit 1 + run: exit 1 + - name: echo + run: echo hello + job2: + needs: [job1] + runs-on: ubuntu-latest + steps: + - name: echo + run: echo hello diff --git a/.github/workflows/part2/issue_notify.yaml b/.github/workflows/part2/issue_notify.yaml new file mode 100644 index 000000000..bf4bdc885 --- /dev/null +++ b/.github/workflows/part2/issue_notify.yaml @@ -0,0 +1,57 @@ +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 }} + 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/.github/workflows/part2/matrix.yaml b/.github/workflows/part2/matrix.yaml new file mode 100644 index 000000000..c7d1d0620 --- /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 }} diff --git a/.github/workflows/part2/output.yaml b/.github/workflows/part2/output.yaml new file mode 100644 index 000000000..cc2faf6b6 --- /dev/null +++ b/.github/workflows/part2/output.yaml @@ -0,0 +1,22 @@ +name: output +on: push + +jobs: + create-output: + runs-on: ubuntu-latest + outputs: + test: ${{ steps.check-output.outputs.test }} # 그럼 다른 job 에서도 이 output 사용 가능 + 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 }} diff --git a/.github/workflows/part2/path_filter.yaml b/.github/workflows/part2/path_filter.yaml new file mode 100644 index 000000000..4d18e2877 --- /dev/null +++ b/.github/workflows/part2/path_filter.yaml @@ -0,0 +1,12 @@ +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 diff --git a/.github/workflows/part2/secrets.yaml b/.github/workflows/part2/secrets.yaml new file mode 100644 index 000000000..52295bc80 --- /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 }} diff --git a/.github/workflows/part2/string-function.yaml b/.github/workflows/part2/string-function.yaml new file mode 100644 index 000000000..041b31c57 --- /dev/null +++ b/.github/workflows/part2/string-function.yaml @@ -0,0 +1,30 @@ +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', 'test') + run: echo "test" + + + diff --git a/.github/workflows/part2/tag_filter.yaml b/.github/workflows/part2/tag_filter.yaml new file mode 100644 index 000000000..0bfe3decc --- /dev/null +++ b/.github/workflows/part2/tag_filter.yaml @@ -0,0 +1,12 @@ +name: tag-filter +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' # v1.0.0 or v2.2.2 만 가능. 예를들어 v1.0 or 1.0.0 은 안됨. + +jobs: + tag-filter: + runs-on: ubuntu-latest + steps: + - name: echo + run: echo hello diff --git a/.github/workflows/part2/var-1.yaml b/.github/workflows/part2/var-1.yaml new file mode 100644 index 000000000..8ca70b7eb --- /dev/null +++ b/.github/workflows/part2/var-1.yaml @@ -0,0 +1,40 @@ +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 }}" + + diff --git a/.github/workflows/part2/var-2.yaml b/.github/workflows/part2/var-2.yaml new file mode 100644 index 000000000..feb6629b8 --- /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 }} diff --git a/keyword-list.txt b/keyword-list.txt new file mode 100644 index 000000000..3662bab5a --- /dev/null +++ b/keyword-list.txt @@ -0,0 +1,2 @@ +critical +normal diff --git a/my-app/src/App.js b/my-app/src/App.js index 725bc9db5..a5105428d 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 test