Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing GitHub Actions

Introducing GitHub Actions

Sobolev Nikita

October 30, 2019
Tweet

More Decks by Sobolev Nikita

Other Decks in Programming

Transcript

  1. У нас был целый склад велосипедов! > Свои боты в

    Gitlab CI > Свои боты в Heroku + Cron > Свои боты, которые слушали вебхуки 5
  2. name: Python package on: [push] jobs: build: runs-on: ubuntu-latest strategy:

    max-parallel: 4 matrix: python-version: [2.7, 3.5, 3.6, 3.7] steps: # ...
  3. name: Python package on: [push] jobs: build: runs-on: ubuntu-latest strategy:

    max-parallel: 4 matrix: python-version: [2.7, 3.5, 3.6, 3.7] steps: # ...
  4. name: Python package on: [push] jobs: build: runs-on: ubuntu-latest strategy:

    max-parallel: 4 matrix: python-version: [2.7, 3.5, 3.6, 3.7] steps: # ...
  5. name: Python package on: [push] jobs: build: runs-on: ubuntu-latest strategy:

    max-parallel: 4 matrix: python-version: [2.7, 3.5, 3.6, 3.7] steps: # ...
  6. name: Python package # ... steps: - uses: actions/checkout@v1 -

    name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | pip install -r requirements.txt
  7. name: Python package # ... steps: - uses: actions/checkout@v1 -

    name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | pip install -r requirements.txt
  8. name: Python package # ... steps: - uses: actions/checkout@v1 -

    name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | pip install -r requirements.txt
  9. name: Python package # ... steps: - uses: actions/checkout@v1 -

    name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | pip install -r requirements.txt matrix: python-version: [2.7, 3.5, 3.6, 3.7]
  10. name: Python package # ... steps: - uses: actions/checkout@v1 -

    name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | pip install -r requirements.txt
  11. name: Python package # ... steps: - uses: actions/checkout@v1 -

    name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | pip install -r requirements.txt
  12. name: Python package # ... steps: # ... - name:

    Lint with wemake-python-styleguide run: | pip install flake8 flake8 . - name: Test with pytest run: | pip install pytest pytest
  13. name: Python package # ... steps: # ... - name:

    Lint with wemake-python-styleguide run: | pip install flake8 flake8 . - name: Test with pytest run: | pip install pytest pytest
  14. on: pull_request - assigned - unassigned - labeled - unlabeled

    - opened - edited - closed - reopened - synchronize - ready_for_review - locked - unlocked - review_requested - review_request_removed
  15. FROM python:3.7-alpine RUN apk add --no-cache bash RUN pip install

    wemake-python-styleguide COPY entrypoint.sh / RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"]
  16. FROM python:3.7-alpine RUN apk add --no-cache bash RUN pip install

    wemake-python-styleguide COPY entrypoint.sh / RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"]
  17. FROM python:3.7-alpine RUN apk add --no-cache bash RUN pip install

    wemake-python-styleguide COPY entrypoint.sh / RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"]
  18. #!/bin/bash # Runs flake8: output=$(flake8 "$1") status="$?" echo "::set-output name=output::$output"

    # Fail the build in case status code is not 0: if [[ "$status" != 0 ]]; then echo "$output" echo "Process failed with the status code: $status" exit "$status" fi
  19. #!/bin/bash # Runs flake8: output=$(flake8 "$1") status="$?" echo "::set-output name=output::$output"

    # Fail the build in case status code is not 0: if [[ "$status" != 0 ]]; then echo "$output" echo "Process failed with the status code: $status" exit "$status" fi
  20. #!/bin/bash # Runs flake8: output=$(flake8 "$1") status="$?" echo "::set-output name=output::$output"

    # Fail the build in case status code is not 0: if [[ "$status" != 0 ]]; then echo "$output" echo "Process failed with the status code: $status" exit "$status" fi
  21. name: 'wemake-python-styleguide' inputs: path: description: 'List of paths to lint'

    required: false default: '.' outputs: output: description: 'The output of a linter run' runs: using: 'docker' image: 'Dockerfile' args: - ${{ inputs.path }}
  22. name: 'wemake-python-styleguide' inputs: path: description: 'List of paths to lint'

    required: false default: '.' outputs: output: description: 'The output of a linter run' runs: using: 'docker' image: 'Dockerfile' args: - ${{ inputs.path }}
  23. name: 'wemake-python-styleguide' inputs: path: description: 'List of paths to lint'

    required: false default: '.' outputs: output: description: 'The output of a linter run' runs: using: 'docker' image: 'Dockerfile' args: - ${{ inputs.path }}
  24. name: 'wemake-python-styleguide' inputs: path: description: 'List of paths to lint'

    required: false default: '.' outputs: output: description: 'The output of a linter run' runs: using: 'docker' image: 'Dockerfile' args: - ${{ inputs.path }}
  25. const github = require('@actions/github') const core = require('@actions/core') async function

    run() { const octokit = new github.GitHub(process.env.GITHUB_TOKEN) switch (github.context.eventName) { case 'issue_comment': checkIssueComment(github.context, async () => { await octokit.issues.updateComment({ ...github.context.repo, 'body': core.getInput('text'), }) }) break // ... } }
  26. const github = require('@actions/github') const core = require('@actions/core') async function

    run() { const octokit = new github.GitHub(process.env.GITHUB_TOKEN) switch (github.context.eventName) { case 'issue_comment': checkIssueComment(github.context, async () => { await octokit.issues.updateComment({ ...github.context.repo, 'body': core.getInput('text'), }) }) break // ... } }
  27. const github = require('@actions/github') const core = require('@actions/core') async function

    run() { const octokit = new github.GitHub(process.env.GITHUB_TOKEN) switch (github.context.eventName) { case 'issue_comment': checkIssueComment(github.context, async () => { await octokit.issues.updateComment({ ...github.context.repo, 'body': core.getInput('text'), }) }) break // ... } }
  28. name: comments on: issues: types: [opened, edited] issue_comment: types: [created,

    edited] pull_request: types: [created, edited] jobs: comments: runs-on: ubuntu-latest steps: - uses: sobolevn/restrict-cursing-action@latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  29. name: comments on: issues: types: [opened, edited] issue_comment: types: [created,

    edited] pull_request: types: [created, edited] jobs: comments: runs-on: ubuntu-latest steps: - uses: sobolevn/restrict-cursing-action@latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  30. name: comments on: issues: types: [opened, edited] issue_comment: types: [created,

    edited] pull_request: types: [created, edited] jobs: comments: runs-on: ubuntu-latest steps: - uses: sobolevn/restrict-cursing-action@latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  31. !85

  32. Упади, все плохо import { danger, fail } from 'danger'

    if (danger.github.pr.base.ref !== 'master') { fail('We only accept PRs to `master` branch.') } if (!danger.github.pr.rebaseable) { fail('Looks like your PR cannot be merged, please fix it: reopen or rebase.') }
  33. Не падай, но скажи import { danger, warn } from

    'danger' if (danger.github.pr.body.length < 50) { warn('Please provide a summary, at least 50 chars') } if (!danger.github.pr.body.match(/closes #\d+/i)) { warn('MR does not close any issues. Should close one') }
  34. Полезности > Проверять, что не утекли пароли: npmjs.com/package/detect-secrets > Валидировать

    конфиги: yaml, json > Проверять повторяющиеся действия
  35. !95

  36. Алгоритм > Бот читает список ваших зависимостей > Смотрит на

    наличие обновлений по заданным правилам
  37. Алгоритм > Бот читает список ваших зависимостей > Смотрит на

    наличие обновлений по заданным правилам > Делает много PR с изменениями одной зависимости
  38. Алгоритм > Бот читает список ваших зависимостей > Смотрит на

    наличие обновлений по заданным правилам > Делает много PR с изменениями одной зависимости > Ждет прогона CI
  39. Алгоритм > Бот читает список ваших зависимостей > Смотрит на

    наличие обновлений по заданным правилам > Делает много PR с изменениями одной зависимости > Ждет прогона CI > Готово!
  40. steps: - uses: actions/checkout@master - uses: codfish/semantic-release-action@master id: semantic env:

    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: echo "${{ steps.semantic.outputs.release-version }}"
  41. steps: - uses: actions/checkout@master - uses: codfish/semantic-release-action@master id: semantic env:

    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: echo "${{ steps.semantic.outputs.release-version }}"
  42. steps: - uses: actions/checkout@master - uses: codfish/semantic-release-action@master id: semantic env:

    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: echo "${{ steps.semantic.outputs.release-version }}"
  43. Готовые провайдеры > AWS, Azure > Zeit / Now, Heroku

    > K8S, DockerSwarm, Dokku > Ansible, Chef, Terraform
  44. Готовые провайдеры > AWS, Azure > Zeit / Now, Heroku

    > K8S, DockerSwarm, Dokku > Ansible, Chef, Terraform > rsync
  45. Готовые провайдеры > AWS, Azure > Zeit / Now, Heroku

    > K8S, DockerSwarm, Dokku > Ansible, Chef, Terraform > rsync > Docker registry
  46. on: [push] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@master

    - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@master with: name: myDocker/repository username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} registry: my.custom-registry.com
  47. on: [push] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@master

    - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@master with: name: myDocker/repository username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} registry: my.custom-registry.com
  48. name: terraform on: pull_request jobs: terraform: runs-on: ubuntu-latest steps: -

    uses: hashicorp/terraform-github-actions/fmt - uses: hashicorp/terraform-github-actions/init - uses: hashicorp/terraform-github-actions/validate - uses: hashicorp/terraform-github-actions/plan - uses: hashicorp/terraform-github-actions/deploy
  49. name: terraform on: pull_request jobs: terraform: runs-on: ubuntu-latest steps: -

    uses: hashicorp/terraform-github-actions/fmt - uses: hashicorp/terraform-github-actions/init - uses: hashicorp/terraform-github-actions/validate - uses: hashicorp/terraform-github-actions/plan - uses: hashicorp/terraform-github-actions/deploy
  50. name: terraform on: pull_request jobs: terraform: runs-on: ubuntu-latest steps: -

    uses: hashicorp/terraform-github-actions/fmt - uses: hashicorp/terraform-github-actions/init - uses: hashicorp/terraform-github-actions/validate - uses: hashicorp/terraform-github-actions/plan - uses: hashicorp/terraform-github-actions/deploy
  51. name: terraform on: pull_request jobs: terraform: runs-on: ubuntu-latest steps: -

    uses: hashicorp/terraform-github-actions/fmt - uses: hashicorp/terraform-github-actions/init - uses: hashicorp/terraform-github-actions/validate - uses: hashicorp/terraform-github-actions/plan - uses: hashicorp/terraform-github-actions/deploy
  52. name: terraform on: pull_request jobs: terraform: runs-on: ubuntu-latest steps: -

    uses: hashicorp/terraform-github-actions/fmt - uses: hashicorp/terraform-github-actions/init - uses: hashicorp/terraform-github-actions/validate - uses: hashicorp/terraform-github-actions/plan - uses: hashicorp/terraform-github-actions/deploy
  53. name: terraform on: pull_request jobs: terraform: runs-on: ubuntu-latest steps: -

    uses: hashicorp/terraform-github-actions/fmt - uses: hashicorp/terraform-github-actions/init - uses: hashicorp/terraform-github-actions/validate - uses: hashicorp/terraform-github-actions/plan - uses: hashicorp/terraform-github-actions/apply
  54. Проблемы > Пока не работает кеш для зависимостей > Проблемы

    с origin / fork > Относительно мало готовых компонентов
  55. Проблемы > Пока не работает кеш для зависимостей > Проблемы

    с origin / fork > Относительно мало готовых компонентов > Не у всех есть доступ (до 13.11)
  56. Проблемы > Пока не работает кеш для зависимостей > Проблемы

    с origin / fork > Относительно мало готовых компонентов > Не у всех есть доступ (до 13.11) > Тесты за вас никто не напишет!