diff --git a/.github/workflows/cicd-1.yaml b/.github/workflows/cicd-1.yaml new file mode 100644 index 000000000..bdbdf36cf --- /dev/null +++ b/.github/workflows/cicd-1.yaml @@ -0,0 +1,28 @@ +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/\bworkflow_dispatch.yaml" "b/.github/workflows/part1/\bworkflow_dispatch.yaml" new file mode 100644 index 000000000..4c77a6854 --- /dev/null +++ "b/.github/workflows/part1/\bworkflow_dispatch.yaml" @@ -0,0 +1,27 @@ +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 ${{ inputs.name }} + - name: step2 + run: echo ${{ inputs.environment }} diff --git a/.github/workflows/part1/issue.yaml b/.github/workflows/part1/issue.yaml new file mode 100644 index 000000000..4fbbb32aa --- /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 actions diff --git a/.github/workflows/part1/issue_comment.yaml b/.github/workflows/part1/issue_comment.yaml new file mode 100644 index 000000000..920c244ce --- /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_events.yaml b/.github/workflows/part1/multiple_events.yaml new file mode 100644 index 000000000..60bd15895 --- /dev/null +++ b/.github/workflows/part1/multiple_events.yaml @@ -0,0 +1,17 @@ +name: multiple-events-workflow +on: + push: + issues: + types: [opened] + workflow_dispatch: + +jobs: + multiple-events-job: + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github actions diff --git a/.github/workflows/part1/needs.yaml b/.github/workflows/part1/needs.yaml new file mode 100644 index 000000000..630da5ede --- /dev/null +++ b/.github/workflows/part1/needs.yaml @@ -0,0 +1,40 @@ +name: needs +on: push + +jobs: + job1: + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github actions + job2: + needs: [job1] + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github actions + job3: + runs-on: ubuntu-latest + steps: + - name: step1 + run: | + echo "job3 failed" + exit 1 + job4: + needs: [job3] + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github actions diff --git a/.github/workflows/part1/pull_request.yaml b/.github/workflows/part1/pull_request.yaml new file mode 100644 index 000000000..21c179226 --- /dev/null +++ b/.github/workflows/part1/pull_request.yaml @@ -0,0 +1,14 @@ +name: pull-request-workflow-hello +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 actions diff --git a/.github/workflows/part1/push.yaml b/.github/workflows/part1/push.yaml new file mode 100644 index 000000000..c1f96da0f --- /dev/null +++ b/.github/workflows/part1/push.yaml @@ -0,0 +1,12 @@ +name: push-workflow-hello3 +on: push +jobs: + push-job: + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github actions diff --git a/.github/workflows/part1/re-run.yaml b/.github/workflows/part1/re-run.yaml new file mode 100644 index 000000000..669438912 --- /dev/null +++ b/.github/workflows/part1/re-run.yaml @@ -0,0 +1,14 @@ +name: re-run +on: push +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: step1 + run: echo hello world + - name: step2 + run: | + echo hello world + echo github actions + - name: cat readme + run: cat README.md diff --git a/.github/workflows/part2/artifact.yaml b/.github/workflows/part2/artifact.yaml new file mode 100644 index 000000000..7887120c4 --- /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 diff --git a/.github/workflows/part2/branch_filter.yaml b/.github/workflows/part2/branch_filter.yaml new file mode 100644 index 000000000..e6c10bea3 --- /dev/null +++ b/.github/workflows/part2/branch_filter.yaml @@ -0,0 +1,4 @@ +name: branch-filter +on: + push: + branches: ["dev"] diff --git a/.github/workflows/part2/cache.yaml b/.github/workflows/part2/cache.yaml new file mode 100644 index 000000000..796c54f8a --- /dev/null +++ b/.github/workflows/part2/cache.yaml @@ -0,0 +1,30 @@ +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: 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..beb76ff51 --- /dev/null +++ b/.github/workflows/part2/checkout.yaml @@ -0,0 +1,17 @@ +name: checkout_workflow +on: workflow_dispatch + +jobs: + no-checkout-job: + runs-on: ubuntu-latest + steps: + - name: check file list + run: cat README.md + + checkout-job: + runs-on: ubuntu-latest + steps: + - name: use checkout action + uses: actions/checkout@v2 + - 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..237754907 --- /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: step1 + run: echo '${{ toJSON(github) }}' + - name: check github context + run: | + echo ${{ github.repository }} + echo ${{ github.event_name }} diff --git a/.github/workflows/part2/if-1.yaml b/.github/workflows/part2/if-1.yaml new file mode 100644 index 000000000..30dc133c5 --- /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: step1 + run: echo hello world + job2: + runs-on: ubuntu-latest + if: github.event_name != 'push' + steps: + - name: step1 + run: echo hello world + + job3: + runs-on: ubuntu-latest + steps: + - name: echo PUSH + if: github.event_name == 'push' + run: echo PUSH + - name: echo WORKFLOW_DISPATCH + 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..dafc6e2f7 --- /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 hello world + if: always() + run: echo hello world + + job2: + needs: [job1] + runs-on: ubuntu-latest + if: always() + steps: + - name: echo hello world + run: echo hello world diff --git a/.github/workflows/part2/matrix.yaml b/.github/workflows/part2/matrix.yaml new file mode 100644 index 000000000..4d0ba5580 --- /dev/null +++ b/.github/workflows/part2/matrix.yaml @@ -0,0 +1,15 @@ +name: matrix +on: push + +jobs: + get-matrix: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + node: [12, 14] + runs-on: ${{ matrix.os }} + steps: + - name: check matrix + run: | + echo ${{ matrix.os }} + echo ${{ matrix.node }} diff --git a/.github/workflows/part2/output.yaml b/.github/workflows/part2/output.yaml new file mode 100644 index 000000000..57f34e631 --- /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: + runs-on: ubuntu-latest + needs: create-output + steps: + - name: check 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..8f9c31499 --- /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: + push-filter: + runs-on: ubuntu-latest + steps: + - name: echo + run: echo "This is a push event with path filter" diff --git a/.github/workflows/part2/string-function.yaml b/.github/workflows/part2/string-function.yaml new file mode 100644 index 000000000..50d8ab0b2 --- /dev/null +++ b/.github/workflows/part2/string-function.yaml @@ -0,0 +1,10 @@ +name: string-function +on: push + +jobs: + string-function: + runs-on: ubuntu-latest + steps: + - name: startswith + if: startsWith('github actions','git') + run: echo "The string starts with 'git'" diff --git a/.github/workflows/part2/tag.yaml b/.github/workflows/part2/tag.yaml new file mode 100644 index 000000000..8af0894ac --- /dev/null +++ b/.github/workflows/part2/tag.yaml @@ -0,0 +1,11 @@ +name: tag_filter.yaml +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" +jobs: + tag-filter: + runs-on: ubuntu-latest + steps: + - name: echo + run: echo "This is a push event with tag filter" diff --git a/.github/workflows/part2/timeout.yaml b/.github/workflows/part2/timeout.yaml new file mode 100644 index 000000000..b7871a315 --- /dev/null +++ b/.github/workflows/part2/timeout.yaml @@ -0,0 +1,21 @@ +name: timeout +on: push + +jobs: + timeout: + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - name: step1 + run: | + count=0 + while true; do + echo "Hello $count" + count=$((count+1)) + sleep 1 + done + timeout-minutes: 1 + - name: step2 + run: | + echo hello world + echo ${{ github.repository }} diff --git a/.github/workflows/part2/var-1.yaml b/.github/workflows/part2/var-1.yaml new file mode 100644 index 000000000..6fb9d6c31 --- /dev/null +++ b/.github/workflows/part2/var-1.yaml @@ -0,0 +1,38 @@ +name: var-1 +on: push + +env: + level: workflow + +jobs: + get-env-1: + runs-on: ubuntu-latest + steps: + - name: check 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: create env + run: echo "level=job" >> $GITHUB_ENV + - name: check env + run: echo ${{ env.level }} diff --git a/.github/workflows/part3/create_repo.yaml b/.github/workflows/part3/create_repo.yaml new file mode 100644 index 000000000..2c9e52c0d --- /dev/null +++ b/.github/workflows/part3/create_repo.yaml @@ -0,0 +1,61 @@ +name: create-repo +on: + workflow_dispatch: + inputs: + prefix: + description: "Prefix for the repository name" + required: true + default: "service" + type: choice + options: + - exmaple + - 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 june-github-action-practice/${{ inputs.prefix }}-${{ inputs.name }} --public --add-readme + - name: Set color based on outcome + if: always() + id: set-color + run: | + if [ "${{ steps.create-repo.outcome }}" == "success" ]; then + echo "slack_color=#36a64f" >> $GITHUB_ENV + else + echo "slack_color=#FF0000" >> $GITHUB_ENV + fi + - name: Slack message + if: always() + uses: slackapi/slack-github-action@v1.26.0 + with: + # This data can be any valid JSON from a previous step in the GitHub Action + payload: | + { + "attachments": [{ + "pretext": "A new repository has been created", + "color": "${{ env.slack_color }}", + "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/my-app/src/App.js b/my-app/src/App.js index 725bc9db5..b40d400dd 100644 --- a/my-app/src/App.js +++ b/my-app/src/App.js @@ -1,5 +1,5 @@ -import logo from './logo.svg'; -import './App.css'; +import logo from "./logo.svg"; +import "./App.css"; function App() { return ( @@ -7,7 +7,7 @@ function App() {
logo

- Edit src/App.js and save to reload. + Edit src/App.js and savddde to reload.

- Learn GithubAction cicd + Learn GitHub Action cicd
+ Let's go~~~