Skip to content

Send email on Workflow Run Success/Failure #34982

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

Merged
merged 46 commits into from
Jul 16, 2025
Merged

Conversation

NorthRealm
Copy link
Contributor

@NorthRealm NorthRealm commented Jul 7, 2025

Closes #23725

1
2

/claim #23725

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 7, 2025
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files labels Jul 7, 2025
@NorthRealm
Copy link
Contributor Author

NorthRealm commented Jul 7, 2025

Note: For code reusability, there's a refactor/renaming in mail.go, mail_issue_common.go and mail_test.go in c8b64c7, ed7b2bc

@NorthRealm
Copy link
Contributor Author

1

@lunny lunny added this to the 1.25.0 milestone Jul 7, 2025
@lunny
Copy link
Member

lunny commented Jul 7, 2025

replace #33601

@wxiaoguang

This comment was marked as resolved.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jul 8, 2025

outdated

And by reading the history discussions:

I think the concern is not addressed? should we send the email on "workflow job" level, or "workflow run" level? (I am not certain about the details, just FYI)


It looks right, the concerns in "Actions - send Email on Success/Failure #33601" should all be addressed. 🙏

@wxiaoguang
Copy link
Contributor

I refer a lot from elsewhere in the whole code base, and I see it potentially reusable/re-applicable if it's been there.

Actually we should never trust existing code, there are bugs and bad-smells. If you just copy-paste existing code, then there will be more bugs and bad-smells.

@wxiaoguang wxiaoguang added reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. type/feature Completely new functionality. Can only be merged if feature freeze is not active. labels Jul 15, 2025
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jul 15, 2025

Will explain more "bad smells" in old code that I have made changes to:

  1. It shouldn't duplicate log.Error when using ServerError which already logs the err
  2. It shouldn't show 500 error page when the user input is invalid.
  3. It shouldn't set selected active for a dropdown item, selected and active have different meanings
  4. It shouldn't duplicate {{if eq ...}}selected{{end}} when using dropdown, the input value is the selected one and the framework already handles it
  5. It shouldn't duplicate rel="noopener noreferer", it only makes the translation more difficult (the affect has been explained above)

Actually I can tolerate the nits in code (not serious bugs) if the PR was reviewed and merged by others, or I missed some of them. While if I am reviewing or writing code, I will always do my best to avoid the bad smells.

@lunny lunny merged commit 0d00ec7 into go-gitea:main Jul 16, 2025
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jul 16, 2025
@ankurk91
Copy link

@lunny
this will land in 1.25?😬 please

zjjhot added a commit to zjjhot/gitea that referenced this pull request Jul 16, 2025
* giteaofficial/main:
  Send email on Workflow Run Success/Failure (go-gitea#34982)
  [skip ci] Updated translations via Crowdin
  Replace `poetry` with `uv` (go-gitea#35084)
  nix flake update (go-gitea#35085)
  Use monospace font in PR command line instructions (go-gitea#35074)
  Add gitignore rules to exclude LLM instruction files (go-gitea#35076)
  [skip ci] Updated translations via Crowdin
  Fix form property assignment edge case (go-gitea#35073)
  Improve submodule relative path handling (go-gitea#35056)
  Fixed all grammatical errors in locale_en-US.ini (go-gitea#35053)
  UI: add hover background to table rows in user and repo admin page (go-gitea#35072)
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jul 16, 2025

Yes, it is in 1.25, great thanks to @NorthRealm and reviewers 🎉

You can use it by the nightly build:

@ghnp5
Copy link

ghnp5 commented Jul 16, 2025

Thank you so much for this!! 🥳🎉🧡

@NorthRealm NorthRealm deleted the patch4 branch July 16, 2025 08:11
@inxcts
Copy link

inxcts commented Aug 4, 2025

@NorthRealm
How do I activate this feature? I have set up the mailer and the mailer seems to work. When clicking the Test button in the settings, the email is sent successfully. However, if a Action run fails, I do not get any emails.

@NorthRealm
Copy link
Contributor Author

@inxcts [service] ENABLE_NOTIFY_MAIL=true

@inxcts
Copy link

inxcts commented Aug 4, 2025

@inxcts [service] ENABLE_NOTIFY_MAIL=true

I also set this variable to true and restarted Gitea. When an action run fails, I still do net any emails. I still something is still missing.

@NorthRealm
Copy link
Contributor Author

@inxcts I'm pretty sure that's the key. Manually tested on local instance (localhost) and it's working as intended. Do you have a valid email address in your account? Is your mailbox provider putting gitea emails into spam folder?

@inxcts
Copy link

inxcts commented Aug 4, 2025

@NorthRealm

@inxcts I'm pretty sure that's the key. Manually tested on local instance (localhost) and it's working as intended. Do you have a valid email address in your account? Is your mailbox provider putting gitea emails into spam folder?

The spam folder is empty. In the mailer section of the app.ini, I have put an email address that is not in use by any Gitea user, it is just used as the email account that Gitea should use. In the "FROM" variable, I have put the email address from my main account.

When navigating to the settings page, the mailer seems to work. When typing an email address and clicking the Test button, the email is sent to my account (the same that should be used for the actions).

@NorthRealm
Copy link
Contributor Author

@inxcts Enable Gitea trace log and see if anything like New e-mail sending request []: Run failed(failed/cancelled/succeeded) appears. If yes, then I don't see any issue on Gitea. If no, it probably means:

  • Event is not triggered (not likely)
  • Trigger user not eligible to receive emails.
  • Trigger user has disabled action emails. (In current implementation it's independent from the existing email notification preference setting.)
  • Trigger user is not you.
  • Anywhere else that I have not noticed.
[mailer]
ENABLED = true
SMTP_ADDR = mailbox.host
SMTP_PORT = 465
PROTOCOL = smtps
FROM = [email protected]
USER = [email protected]
PASSWD = 

The above is my (dummy) mailer config. You usually don't "put the email address from your main account."

@inxcts
Copy link

inxcts commented Aug 4, 2025

@NorthRealm

When I commit something and the action fails, I now get the email. The problem seems to be that the job is scheduled.

name: Nightly on: schedule: - cron: "0 0 * * *"

Is it possible to receive emails here or run the job with my user?

@NorthRealm
Copy link
Contributor Author

@inxcts I am not familiar with how Gitea determines trigger user. I looked at code base and did not find anywhere clear that logs an existing user as trigger user for a scheduled task. You get the email probably because of push trigger and you become the trigger user.
Prior in #23725 people had other workarounds.
To "run the job with your user", maybe trigger the run manually or with API?

@lunny
Copy link
Member

lunny commented Aug 5, 2025

@inxcts Please notice this feature will be released in v1.25

@inxcts
Copy link

inxcts commented Aug 5, 2025

@inxcts Please notice this feature will be released in v1.25

@lunny I know that this is a 1.25 feature, I am running the latest dev build.

@NorthRealm I think for scheduled builds, the repository owner should receive the emails(just like GitHub does), otherwise no one really knows that actions fail.

@PhantomPhoton
Copy link

FWIW, I'm in agreement with inxcts. I'm more interested in receiving notifications for scheduled actions when they fail vs push actions, as with push actions, I'm actively doing something and know to check. Having to check the results manually every morning is a chore I wish to avoid. Just my two cents.

That said, I really appreciate the work and feature and am very thankful for the project.

@ChristopherHX
Copy link
Contributor

ChristopherHX commented Aug 11, 2025

I think for scheduled builds, the repository owner should receive the emails(just like GitHub does)

My experience is different. The user who has changed the schedule trigger yaml most recently is the trigger of the run and email recipient on GitHub Actions, here is Gitea Actions the trigger and has no real user as target.

In very rare cases this is the repository owner for multi user projects.


There were discussions on how bad GitHubs behavior is, so it might make sense to actually use the repository owner for all non deliverable workflow failure notifications.

Some people might prefer, a repo setting to send all schedule failures to a custom user/team members / receive other event failures of other users as well.


Emoji Vote

  • 😀 The user who last changed the schedule workflow trigger yaml = trigger + email target, just like GitHub
  • 🚀 Use the owner for workflow emails without recipient, but orgs cannot receive emails, then the org owners need to looked up
  • 👀 Repository setting to specify target audience of workflow email notifications

@ghnp5
Copy link

ghnp5 commented Aug 11, 2025

Thanks!! I suggest repository setting for email address, and if it's not set, default to "last changed".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 Bounty claim lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/translation type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Actions - send Email on Success/Failure