Open4

GitHub Actionsメモ

kentamakentama

commitとpushをする例

name: Commit and Push

on:
  workflow_dispatch:

jobs:
  commit_and_push:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      
      - name: Update file
        run: date >> test.text

      - name: Commit and Push
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com
          git add .
          git commit -m "Update"
          git push
kentamakentama

continue-on-error: true を設定するとエラーが発生しても後続の処理が実行される

jobs:
  foo:
    runs-on: ubuntu-latest
    steps:   
      - name: エラーになる処理
        continue-on-error: true
        run: ...

     - name: エラーになっても処理される
        run: ...
kentamakentama

環境変数GH_TOKENにsecrets.GITHUB_TOKEN を設定すればghが使えるようになる

jobs:
  gh:
    runs-on: ubuntu-latest
    env:
      GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

    steps:
        - uses: actions/checkout@v3
        - run: gh pr status
kentamakentama

特定のブランチへのPRがマージされたら起動するアクション

on:
  pull_request:
    branches:
      - 'hoge'
    types:
      - closed

jobs:
  if_merged:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo The PR was merged