简体   繁体   中英

Github Actions workflow not triggered although schedule should trigger the job

I'm trying to auto-assign issues and PRs in Github from a Github Actions workflow. The respective steps work fine when an issue / a PR is opened. So this trigger is fine.

Recently I added Dependabot to my repo. Since Dependabot cannot access my secrets I cannot assign any issue in a Dependabot-triggeres pipeline. So I just thought I run this pipeline with a scheduler one per day to "clean up" every issue and PR which is unassigned. But this schedule config does not trigger the pipeline. It simply does nothing, not even show as a pipeline run which does nothing (with all jobs skipped). Seems like the trigger is completely ignored.

This is my workflow file.

---
name: "Organize: Assign Issues + Pull Requests"

on:
  issues:
    types:
      - opened
  pull_request:
    types:
      - opened
  schedule:
    - cron: '0 9 * * *' # https://crontab.guru/#0_11_*_*_*

permissions:
  contents: read
  issues: write
  pull-requests: write

jobs:
  add-to-project:
    name: Add to project
    runs-on: ubuntu-latest
    steps:
      - name: Add to project (issues and PRs)
        uses: actions/add-to-project@main
        with:
          project-url: https://github.com/users/sebastian-sommerfeld-io/projects/1
          github-token: ${{ secrets.GH_TOKEN_REPO_AND_PROJECT }}

  assign-to-user:
    name: Assign to user
    runs-on: ubuntu-latest
    steps:
      - name: Assign issue to user when moved into column
        uses: pozil/auto-assign-issue@v1
        # https://github.com/marketplace/actions/auto-assign-issue
        with:
          assignees: ${{ github.actor }}
          numOfAssignee: 1
          allowSelfAssign: true
          abortIfPreviousAssignees: true

  new-pull-request-chat-message:
    runs-on: ubuntu-latest
    needs: ['add-to-project', 'assign-to-user']
    if: github.event_name == 'pull_request'
    steps:
      - name: Send message to Google Chat
        uses: Co-qn/google-chat-notification@releases/v1
        with:
          name: New Pull Request "${{ github.event.pull_request.title }}" (raised by ${{ github.actor }})
          url: ${{ secrets.GOOGLE_CHAT_WEBHOOK }}
          status: ${{ job.status }}

  on-failure:
    runs-on: ubuntu-latest
    needs: ['add-to-project', 'assign-to-user', 'new-pull-request-chat-message']
    if: failure()
    steps:
      - name: Send Pipeline Status to Google Chat
        if: always()
        uses: Co-qn/google-chat-notification@releases/v1
        with:
          name: ${{ github.workflow }}
          url: ${{ secrets.GOOGLE_CHAT_WEBHOOK }}
          status: failure

What bugs me is that the scheduler setting is copied from another workflow where it works just fine. So I cannot think of a reason why this pipeline is not triggered at 09:00 in the morning.

Found a way:-)

I use the Github CLI to get all PRs with a certain label and assign a user. This is a new dedicated pipeline.

---
name: "Organize: Dependabot Pull Requests"

on:
  schedule:
    - cron: '30 * * * *' # https://crontab.guru

permissions:
  contents: read
  issues: write
  pull-requests: write

jobs:
  assign-user:
    name: Aassign PRs with label 'dependencies'
    runs-on: ubuntu-latest
    steps:
      - name: Get PR and assign user (filtered by github cli)
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO_AND_PROJECT }}
          label: dependencies
          assignee: sebastian-sommerfeld-io
        run: |
          OUTPUT=""
          pr_ids="$(gh pr list --repo "$GITHUB_REPOSITORY" --label "$label" --json number --jq '.[].number')"
          for id in $pr_ids; do
            gh pr edit "$id" --repo "$GITHUB_REPOSITORY" --add-assignee "$assignee"
          done

Then I updated the triggers of my original pipeline to

on:
  issues:
    types:
      - opened
  pull_request:
    types:
      - opened
      - assigned

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM