Skip to content

@.各ファイルの役割

Geusen edited this page Dec 19, 2022 · 13 revisions

ディレクトリ

Schedule_Bot
├─ schedule.py  (メインのプログラム)
├─ url.txt  (urlの文字列を保存)
└─ .github
    └─ workflows
        └─ Schedule.yml  (定期実行用ファイル)

Schedule.yml

name: GitHub_Actions(shedule)
on:    #(以下の場合に実行)
  workflow_dispatch:
  schedule:
    - cron: '*/40 0-12,21-23 * * *'    #(6時〜21時、40分ごとに動作)
  repository_dispatch:
    types: GitHub_Actions(gas)
env:  # 環境変数から文字列(パスワードなど)を取得
  ACCESS_TOKEN: ${{secrets.ACCESS_TOKEN}}
  ACCESS_TOKEN_SECRET: ${{secrets.ACCESS_TOKEN_SECRET}}
  CONSUMER_KEY: ${{secrets.CONSUMER_KEY}}
  CONSUMER_SECRET: ${{secrets.CONSUMER_SECRET}}
  GOOGLE_URL: ${{secrets.GOOGLE_URL}}
  LINE_NOTIFY: ${{secrets.LINE_NOTIFY}}
  LINE_NOTIFY_27: ${{secrets.LINE_NOTIFY_27}}
  LINE_NOTIFY_13: ${{secrets.LINE_NOTIFY_13}}
  WEBHOOK: ${{secrets.WEBHOOK}}
  IMGUR: ${{secrets.IMGUR}}
  GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
  RUN_NUMBER: ${{github.run_number}}
  RUN_ID: ${{github.run_id}}
concurrency:  # 同時にworkflowが実行されたらキャンセル
  group: ${{ github.workflow }}-${{ github.ref }}

jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 5    # 5分過ぎたら強制終了
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.11'
          architecture: 'x64'
      - name: run python
        id: results
        run: |
          echo "::group::pip install --upgrade pip"
          python -m pip install --upgrade pip==22.3.1
          pip install get-chrome-driver==1.3.9
          pip install selenium==4.5.0
          pip install opencv-python==4.6.0.66
          pip install numpy==1.23.4
          pip install python-opencv-utils==0.0.4
          pip install tweepy==4.10.0
          echo "::endgroup::"
          python -B schedule.py
      - name: commit&push
        run: |    # 差分が発生した場合のみcommit&push
          git remote set-url origin https://github-actions:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}
          git config --global user.name '${GITHUB_ACTOR}'
          git config --global user.email 'github-actions[bot]@users.noreply.github.com'
          if (git diff --shortstat | grep '[0-9]'); then \
            git add .; \
            git commit -m 'Updated image URL'; \
            git push origin HEAD:${GITHUB_REF}; \
            echo '# Updated image URL :sunglasses:' >> $GITHUB_STEP_SUMMARY; \
          fi
          echo -e "- #### 時刻: ${{steps.results.outputs.TIME}}" >> $GITHUB_STEP_SUMMARY
          echo -e "- #### ステータス: ${{steps.results.outputs.STATUS}}" >> $GITHUB_STEP_SUMMARY
          echo -e "- #### 現在の時間割:\n${{steps.results.outputs.NOW}}" >> $GITHUB_STEP_SUMMARY
          echo -e "- #### 過去の時間割:\n${{steps.results.outputs.BEFORE}}" >> $GITHUB_STEP_SUMMARY
Clone this wiki locally