Jatin Mehrotra
Jatin Mehrotra

Reputation: 11574

Is it possible to rerun GitHub Actions (after commit) if it has failed earlier

I am running GitHub Actions when a PR is open. This works fine. Is it possible to run workflows again if they failed in their earlier execution due to any error? Currently if I commit a fix, GitHub Actions are not triggered.

name: Node.js CI

on:
  push:
    branches: [main]
  pull_request:
    types: [opened]
    branches: [main]
jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
      - run: npm ci
      - run: npm run build --if-present
      - run: npm test
      - name: serverless deploy
        if: ${{github.event_name=='push'}}
        uses: serverless/github-action@master
        with:
          args: deploy
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

Upvotes: 1

Views: 2463

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40759

It doesn't work because you have event_type opened, which triggers when:

pull request is created

If you want to run your workflow for next commits you need to add event synchronize

So you are going yo have:

on:
  push:
    branches: [main]
  pull_request:
    types: [opened, synchronize]
    branches: [main]

or

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

Please check this for more details.

Upvotes: 1

Related Questions