【Github】Github Actions ~ サンプル集 ~

■ はじめに

色々なGithub Actions の サンプル集 を書き溜めていく

目次

【1】flake8/black/isort を使う
【2】yamllintを追加

【1】flake8/black/isort を使う

Github Actionsで「flake8」「black」「isort」を使いたい
=> 各ツールの詳細については、以下の関連記事を参照のこと。

https://dk521123.hatenablog.com/entry/2020/02/07/000000
https://dk521123.hatenablog.com/entry/2021/11/10/095258
demo.yml

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the develop branch
  push:
    branches: [develop]
  pull_request:
    branches: [develop]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    env:
      PYTHON_VERSION: 3.7
      MAX_LINE_LENGTH: 120
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      - name: Set up Python 3.X
        uses: actions/setup-python@v2
        with:
          python-version: ${PYTHON_VERSION}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install flake8 isort black
      - name: Lint
        run: |
          flake8 . --max-line-length=${MAX_LINE_LENGTH}
          isort --check --diff .
          black --check --line-length ${MAX_LINE_LENGTH} .

【2】yamllintを追加

https://github.com/adrienverge/yamllint

にある yamllint を追加してみる。

github-actions-demo.yml

      - uses: actions/checkout@v2

      # ★ここを追加★ => コミット後実行されYAMLファイルがチェックされるはず
      - uses: actions/checkout@v2
      - name: yaml-lint
        uses: ibiqlik/action-yamllint@v3

      # Runs a single command using the runners shell
      - name: Run a one-line script
        run: echo Hello, world!

関連記事

Github ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2019/07/18/234652
Github Actions ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2021/11/04/142835
Github Actions ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2022/06/16/151443
Github Actions ~ 基本編 ~
https://dk521123.hatenablog.com/entry/2023/12/22/195715
Github Actions ~ あれこれ編 ~
https://dk521123.hatenablog.com/entry/2023/12/21/155224
Github Actions ~ GITHUB_ENV ~
https://dk521123.hatenablog.com/entry/2023/12/29/000840
Github Actions ~ プロパティ ~
https://dk521123.hatenablog.com/entry/2023/12/23/231250
Github Actions ~ egg / wheel ファイル作成 ~
https://dk521123.hatenablog.com/entry/2022/06/21/143624
Python を奇麗に書くためのツール群
https://dk521123.hatenablog.com/entry/2021/11/08/221219
flake8 ~ Pythonコードチェック ~
https://dk521123.hatenablog.com/entry/2020/02/07/000000
black ~ Python formatter ~
https://dk521123.hatenablog.com/entry/2021/11/10/095258