0
0

More than 1 year has passed since last update.

[GitHub Actions, Python] GitHub Actionsを用いて調整さんの候補日程を自動生成

Last updated at Posted at 2022-07-02

調整さんの候補日程をGitHub Actions上でPythonを用いて自動生成します。

使い方

  1. https://github.com/yarakigit/chouseisan_scriptfork

  2. Actions >> I understand my workflows, go ahead and enable themをクリック
    screen_shot_1.png

  3. setting.csvを変更してpush

  4. Github Actionsを用いて自動実行

  5. output.txt調整さんにコピペ

setting.csvについて

  • setting.csvの例
    • 2022年08月15日~08月23日の期間, 13時から19時の間に2時間おきに候補日程が生成されます。
      • 曜日の行を0にすると、その曜日は候補日から除外されます。
        • この例だと土曜、日曜を除く平日のみ候補日程が生成されます。
year,2022
start date,08,15
finish date,08,23
monday,1
tuesday,1
wednesday,1
thursday,1
friday,1
saturday,0
sunday,0
time start,13
time finish,19
time span,2

生成されたoutput.txt

8/15(月) 13:00~
8/15(月) 15:00~
8/15(月) 17:00~
8/15(月) 19:00~
8/16(火) 13:00~
8/16(火) 15:00~
8/16(火) 17:00~
8/16(火) 19:00~
8/17(水) 13:00~
8/17(水) 15:00~
8/17(水) 17:00~
8/17(水) 19:00~
8/18(木) 13:00~
8/18(木) 15:00~
8/18(木) 17:00~
8/18(木) 19:00~
8/19(金) 13:00~
8/19(金) 15:00~
8/19(金) 17:00~
8/19(金) 19:00~
8/22(月) 13:00~
8/22(月) 15:00~
8/22(月) 17:00~
8/22(月) 19:00~
8/23(火) 13:00~
8/23(火) 15:00~
8/23(火) 17:00~
8/23(火) 19:00~

GitHub Actionsのワークフローの定義

  • on:

    • GitHub Actionsが実行されるトリガー
      • workflow_dispatch: GitHub Actionsの画面からワークフローを実行
      • push: mainブランチにpushされる度に実行
  • jobs:

    • ワークフローは1つ以上のジョブで構成されていてパラレルに実行される
  • runs-on:

    • ジョブが実行される仮想環境のインスタンス
  • uses:

    • 公開Action
      • actions/checkout@v3 : リポジトリをチェックアウト
      • actions/setup-python@v3 : Pythonをビルド
  • run:

    • コマンドを実行
# This is a basic workflow to help you get started with Actions

name: build

# Controls when the workflow will run
on:  
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:
  
  push:
    branches:
    - main

# 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

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3

      - name: 'echo current datetime'
        env:
          TZ: 'Asia/Tokyo'
        run: |
          echo "CURRENT_DATETIME=$(date +'%Y/%m/%d(%a) %H:%M:%S')"
      
      - uses: actions/setup-python@v3
        with:
          python-version: '3.9.12' # Version range or exact version of a Python version to use, using SemVer's version range syntax
          architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
      
      - name: 'run python'
        working-directory: 'src'
        run: |
          python main.py
          
      - name: 'commit files'
        env:
          TZ: 'Asia/Tokyo'
        run: |
          git config --global user.name "${{ github.actor }}"
          git config --global user.email "${{ github.actor }}@users.noreply.github.com"
          git add ./output.txt
          git commit -m 'Update output.txt'
          git push origin main

Reference

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0