diff --git a/.github/workflows/cicd-1.yaml b/.github/workflows/cicd-1.yaml new file mode 100644 index 000000000..f46753eea --- /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 \ No newline at end of file diff --git a/.github/workflows/part1/issue.yaml b/.github/workflows/part1/issue.yaml new file mode 100644 index 000000000..f241f73e2 --- /dev/null +++ b/.github/workflows/part1/issue.yaml @@ -0,0 +1,17 @@ +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~ + + \ No newline at end of file diff --git a/.github/workflows/part1/issue_comment.yaml b/.github/workflows/part1/issue_comment.yaml new file mode 100644 index 000000000..2bbca692f --- /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}} \ No newline at end of file diff --git a/.github/workflows/part1/multiple_event.yaml b/.github/workflows/part1/multiple_event.yaml new file mode 100644 index 000000000..45a89c62e --- /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 \ 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..75142c639 --- /dev/null +++ b/.github/workflows/part1/needs.yml @@ -0,0 +1,28 @@ +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..6bdfad6d8 --- /dev/null +++ b/.github/workflows/part1/pull_request.yaml @@ -0,0 +1,17 @@ +name: pull-request-workflow 1 +on: + pull_request: + types: [opened] + +jobs: + pull-request-job: + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github~ + + \ 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..ea35c7513 --- /dev/null +++ b/.github/workflows/part1/push.yaml @@ -0,0 +1,14 @@ +name: push-workflow 21 +on: push + +jobs: + push-job: + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github~ + diff --git a/.github/workflows/part1/workflow_dispatch.yaml b/.github/workflows/part1/workflow_dispatch.yaml new file mode 100644 index 000000000..a884fbdf3 --- /dev/null +++ b/.github/workflows/part1/workflow_dispatch.yaml @@ -0,0 +1,32 @@ +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-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 }} \ No newline at end of file diff --git a/.github/workflows/part2/artifact.yaml b/.github/workflows/part2/artifact.yaml new file mode 100644 index 000000000..669c2dead --- /dev/null +++ b/.github/workflows/part2/artifact.yaml @@ -0,0 +1,27 @@ +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 + with: + name: artifact-test + path: ./hello.txt + + + download-artifact: + runs-on: ubuntu-latest + needs: [upload-artifact] + steps: + - name: download artifact + uses: actions/download-artifact@v4 + 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..59eace845 --- /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 "branch-filter done" diff --git a/.github/workflows/part2/cache.yaml b/.github/workflows/part2/cache.yaml new file mode 100644 index 000000000..ff16b5cee --- /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-cache + uses: actions/setup-node@v3 + with: + node-version: 20 + - 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..f89000c55 --- /dev/null +++ b/.github/workflows/part2/checkout.yaml @@ -0,0 +1,19 @@ +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..c93ada3db --- /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: ${{github.repository}}" + echo "github.event_name: ${{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..3b0e87d50 --- /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..16394e213 --- /dev/null +++ b/.github/workflows/part2/if-1.yaml @@ -0,0 +1,30 @@ +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 ${{github.event_name}} + - name: get event name + if: github.event_name != 'push' + run: echo ${{github.event_name}} + diff --git a/.github/workflows/part2/if-2.yaml b/.github/workflows/part2/if-2.yaml new file mode 100644 index 000000000..785ddca20 --- /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: + if: always() + needs: [job1] + runs-on: ubuntu-latest + 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..20dbccfae --- /dev/null +++ b/.github/workflows/part2/matrix.yaml @@ -0,0 +1,16 @@ +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..6967f86a3 --- /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..a94be155e --- /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 heelo + 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..edff5f682 --- /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..c26efc66e --- /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 "1" + + - name: endsWith + if: endsWith('github actions', 'ions') + run: echo "2" + + - name: contains + if: contains('github actions', 'test') + run: echo "3" + + - name: contains + if: contains('github actions', 'git') + run: echo "4" + + - name: contains + if: contains('github actions', 'git') + run: echo "5" + \ 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..9c60b7aea --- /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 + +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..fd0385b3b --- /dev/null +++ b/.github/workflows/part2/timeout.yaml @@ -0,0 +1,20 @@ +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 + diff --git a/.github/workflows/part2/var-1.yaml b/.github/workflows/part2/var-1.yaml new file mode 100644 index 000000000..98dba6731 --- /dev/null +++ b/.github/workflows/part2/var-1.yaml @@ -0,0 +1,36 @@ +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: step + steps: + - name: check env + run: 'echo "LEVEL: ${{ env.level }}"' + + 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..9662e3bad --- /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..206584923 --- /dev/null +++ b/.github/workflows/part3/create_repo.yaml @@ -0,0 +1,53 @@ +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 designc-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}}", + "value": "${{inputs.prefix}}-${{inputs.name}}", + "short": true + } + ] + } + ] + } + env: + SLACK_WEBHOOK_URL: ${{secrets.SLACK_WEBHOOK_URL}} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK diff --git a/.github/workflows/part3/issue_notify.yaml b/.github/workflows/part3/issue_notify.yaml new file mode 100644 index 000000000..d1eecd819 --- /dev/null +++ b/.github/workflows/part3/issue_notify.yaml @@ -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}} + 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 outputs + 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/.prettierrc b/.prettierrc new file mode 100644 index 000000000..1e50ff1c8 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "tabWidth": 2 +} \ No newline at end of file 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..a5661513e 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 + cicd test2