Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduled Gitea Actions sometimes run on non-default merged branches #28157

Closed
andrewimeson opened this issue Nov 21, 2023 · 8 comments · Fixed by #28691
Closed

Scheduled Gitea Actions sometimes run on non-default merged branches #28157

andrewimeson opened this issue Nov 21, 2023 · 8 comments · Fixed by #28691
Labels
topic/gitea-actions related to the actions of Gitea type/bug
Milestone

Comments

@andrewimeson
Copy link
Contributor

andrewimeson commented Nov 21, 2023

Description

Scheduled Gitea Actions are supposed to run on the default branch of the containing repository, but sometimes they run on branches that aren't the default. I haven't done enough testing to narrow down the circumstances, but it has so far always been a merged-and-deleted branch.

Given a workflow file like this:

---
on:  # yamllint disable-line rule:truthy
  schedule:
    - cron: '*/15 * * * *'
jobs:
  backup:
    name: Backup DNS Zones
    runs-on: ubuntu-latest
    container: catthehacker/ubuntu:act-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Debug git status
        run: |
          git status

      - name: Debug Gitea Actions variables
        run: |-
          echo "GITHUB_HEAD_REF: $GITHUB_HEAD_REF"
          echo "GITHUB_REF: $GITHUB_HEAD_REF"
          echo "GITHUB_EVENT_NAME: $GITHUB_EVENT_NAME"
          echo "…and a change to the workflow file to see if that is part of it"

If you create that in the default branch, it will run in the default branch as scheduled. However, once you create a PR and merge it (with branch auto-deletion turned on) it will start running the schedule on the deleted branch instead.

I've created a repository on try.gitea.io, but the screenshots are from my own instance.

Gitea Version

1.21.0

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

image image

Git Version

No response

Operating System

No response

How are you running Gitea?

Official Helm chart v9.5.1

Database

PostgreSQL

@lunny lunny added the topic/gitea-actions related to the actions of Gitea label Nov 22, 2023
@metalMajor
Copy link

metalMajor commented Jan 2, 2024

Hello, I can confirm that I have the same situation. Gitea 1.21.2. It was also a merge-and-delete. Now the action runs each time according to the schedule and indeed does not find the deleted branch then of course. Have you found a way to stop it from running?

For me, the schedule for my master branch even stopped running and now it's only the "deleted" branch that triggers according the schedule. It's like it took it's place somehow.

@viceice

This comment was marked as spam.

@wxiaoguang
Copy link
Contributor

It might have been fixed by fix empty ref for cron workflow runs (#28640) #28647

Could you try 1.21 nightly?

@metalMajor
Copy link

it doesn't help, it still ran the deleted branch:
image

@wxiaoguang
Copy link
Contributor

Hmm, it seems that it needs a complete fix (The Gitea forks don't seem having the proper fix either).

If I understand correctly, maybe the root problem is that the "deleted" branch shouldn't trigger the schedule action? I haven't looked into the problem, maybe someone who have written&reviewed the code could help to figure out. Correct me if I am wrong.

@metalMajor
Copy link

yes that is indeed the case, the deleted branch is triggering the schedule action, and not the default branch which is "master" in my case.

@metalMajor
Copy link

metalMajor commented Jan 4, 2024

I pushed again to "master" branch, directly, without a pull request, and now my schedule ran from the master branch again, and the "deleted" one was not run, so that is a workaround it seems. But I hope I don't have the problem again for every pull request 🤞

@lunny
Copy link
Member

lunny commented Jan 4, 2024

I'm working on this issue.

@lunny lunny added this to the 1.21.4 milestone Jan 4, 2024
lafriks pushed a commit that referenced this issue Jan 12, 2024
Fix #28157 

This PR fix the possible bugs about actions schedule.

## The Changes

- Move `UpdateRepositoryUnit` and `SetRepoDefaultBranch` from models to
service layer
- Remove schedules plan from database and cancel waiting & running
schedules tasks in this repository when actions unit has been disabled
or global disabled.
- Remove schedules plan from database and cancel waiting & running
schedules tasks in this repository when default branch changed.
lunny added a commit to lunny/gitea that referenced this issue Jan 13, 2024
Fix go-gitea#28157

This PR fix the possible bugs about actions schedule.

- Move `UpdateRepositoryUnit` and `SetRepoDefaultBranch` from models to
service layer
- Remove schedules plan from database and cancel waiting & running
schedules tasks in this repository when actions unit has been disabled
or global disabled.
- Remove schedules plan from database and cancel waiting & running
schedules tasks in this repository when default branch changed.
KN4CK3R pushed a commit that referenced this issue Jan 14, 2024
Fix #28157
Backport #28691 

This PR fix the possible bugs about actions schedule.

- Move `UpdateRepositoryUnit` and `SetRepoDefaultBranch` from models to
service layer
- Remove schedules plan from database and cancel waiting & running
schedules tasks in this repository when actions unit has been disabled
or global disabled.
- Remove schedules plan from database and cancel waiting & running
schedules tasks in this repository when default branch changed.
fuxiaohei pushed a commit to fuxiaohei/gitea that referenced this issue Jan 17, 2024
Fix go-gitea#28157 

This PR fix the possible bugs about actions schedule.

## The Changes

- Move `UpdateRepositoryUnit` and `SetRepoDefaultBranch` from models to
service layer
- Remove schedules plan from database and cancel waiting & running
schedules tasks in this repository when actions unit has been disabled
or global disabled.
- Remove schedules plan from database and cancel waiting & running
schedules tasks in this repository when default branch changed.
silverwind pushed a commit to silverwind/gitea that referenced this issue Feb 20, 2024
Fix go-gitea#28157 

This PR fix the possible bugs about actions schedule.

## The Changes

- Move `UpdateRepositoryUnit` and `SetRepoDefaultBranch` from models to
service layer
- Remove schedules plan from database and cancel waiting & running
schedules tasks in this repository when actions unit has been disabled
or global disabled.
- Remove schedules plan from database and cancel waiting & running
schedules tasks in this repository when default branch changed.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic/gitea-actions related to the actions of Gitea type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants