aboutsummaryrefslogtreecommitdiffstats
path: root/models/actions
Commit message (Collapse)AuthorAgeFilesLines
* Use env GITEA_RUNNER_REGISTRATION_TOKEN as global runner token (#32946) (#32964)Giteabot11 days1-8/+13
| | | | | | | | | | Backport #32946 by wxiaoguang Fix #23703 When Gitea starts, it reads GITEA_RUNNER_REGISTRATION_TOKEN or GITEA_RUNNER_REGISTRATION_TOKEN_FILE to add registration token. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Backport 1.23 (#32868)wxiaoguang2024-12-171-1/+1
| | | Co-authored-by: delvh <dev.lh@web.de>
* Improve Actions status aggregations (#32860)v1.24.0-devwxiaoguang2024-12-162-9/+31
| | | | | | Make the result the same as GitHub: * all skipped, then result is skipped * any cancelled, then result cancelled
* Fix incomplete Actions status aggregations (#32859)wxiaoguang2024-12-162-19/+88
| | | fix #32857
* Enable tenv and testifylint rules (#32852)TheFox0x72024-12-151-3/+3
| | | | Enables tenv and testifylint linters closes: https://github.com/go-gitea/gitea/issues/32842
* Fix missing outputs for jobs with matrix (#32823)Zettat1232024-12-141-2/+2
| | | | | | | Fix #32795 If a job uses a matrix, multiple `ActionRunJobs` may have the same `JobID`. We need to merge the outputs of these jobs to make them available to the jobs that need them.
* Detect whether action view branch was deleted (#32764)Lunny Xiao2024-12-121-0/+1
| | | | | Fix #32761 ![图片](https://github.com/user-attachments/assets/a5a7eef8-0fea-4242-b199-1b0b73d9bbdb)
* Trim title before insert/update to database to match the size requirements ↵Lunny Xiao2024-11-143-0/+7
| | | | | of database (#32498) Fix #32489
* Harden runner updateTask and updateLog api (#32462)ChristopherHX2024-11-111-1/+3
| | | Per proposal https://github.com/go-gitea/gitea/issues/32461
* Fix milestone deadline and date related problems (#32339)Lunny Xiao2024-11-051-5/+3
| | | | | | | | | Use zero instead of 9999-12-31 for deadline Fix #32291 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
* Always update expiration time when creating an artifact (#32281)Zettat1232024-10-171-1/+8
| | | Fix #32256
* Show latest run when visit /run/latest (#31808)FuXiaoHei2024-08-101-0/+13
| | | | | | | | | Proposal from https://github.com/go-gitea/gitea/issues/27911#issuecomment-2271982172 When visit latest run path, such as `/{user}/{repo}/actions/runs/latest`. It renders latest run instead of index=0 currently.
* Support compression for Actions logs (#31761)Jason Song2024-08-091-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Support compression for Actions logs to save storage space and bandwidth. Inspired by https://github.com/go-gitea/gitea/issues/24256#issuecomment-1521153015 The biggest challenge is that the compression format should support [seekable](https://github.com/facebook/zstd/blob/dev/contrib/seekable_format/zstd_seekable_compression_format.md). So when users are viewing a part of the log lines, Gitea doesn't need to download the whole compressed file and decompress it. That means gzip cannot help here. And I did research, there aren't too many choices, like bgzip and xz, but I think zstd is the most popular one. It has an implementation in Golang with [zstd](https://github.com/klauspost/compress/tree/master/zstd) and [zstd-seekable-format-go](https://github.com/SaveTheRbtz/zstd-seekable-format-go), and what is better is that it has good compatibility: a seekable format zstd file can be read by a regular zstd reader. This PR introduces a new package `zstd` to combine and wrap the two packages, to provide a unified and easy-to-use API. And a new setting `LOG_COMPRESSION` is added to the config, although I don't see any reason why not to use compression, I think's it's a good idea to keep the default with `none` to be consistent with old versions. `LOG_COMPRESSION` takes effect for only new log files, it adds `.zst` as an extension to the file name, so Gitea can determine if it needs decompression according to the file name when reading. Old files will keep the format since it's not worth converting them, as they will be cleared after #31735. <img width="541" alt="image" src="https://github.com/user-attachments/assets/e9598764-a4e0-4b68-8c2b-f769265183c9">
* Clear up old Actions logs (#31735)Jason Song2024-08-021-3/+13
| | | | | | | | | | | | | | | | | Part of #24256. Clear up old action logs to free up storage space. Users will see a message indicating that the log has been cleared if they view old tasks. <img width="1361" alt="image" src="https://github.com/user-attachments/assets/9f0f3a3a-bc5a-402f-90ca-49282d196c22"> Docs: https://gitea.com/gitea/docs/pulls/40 --------- Co-authored-by: silverwind <me@silverwind.io>
* Use UTC as default timezone when schedule Actions cron tasks (#31742)Jason Song2024-08-013-12/+104
| | | | | | | | | | | | | | | | | | | | | | | | | Fix #31657. According to the [doc](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onschedule) of GitHub Actions, The timezone for cron should be UTC, not the local timezone. And Gitea Actions doesn't have any reasons to change this, so I think it's a bug. However, Gitea Actions has extended the syntax, as it supports descriptors like `@weekly` and `@every 5m`, and supports specifying the timezone like `TZ=UTC 0 10 * * *`. So we can make it use UTC only when the timezone is not specified, to be compatible with GitHub Actions, and also respect the user's specified. It does break the feature because the times to run tasks would be changed, and it may confuse users. So I don't think we should backport this. ## ⚠️ BREAKING ⚠️ If the server's local time zone is not UTC, a scheduled task would run at a different time after upgrading Gitea to this version.
* Clarify Actions resources ownership (#31724)Jason Song2024-08-013-19/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix #31707. Also related to #31715. Some Actions resources could has different types of ownership. It could be: - global: all repos and orgs/users can use it. - org/user level: only the org/user can use it. - repo level: only the repo can use it. There are two ways to distinguish org/user level from repo level: 1. `{owner_id: 1, repo_id: 2}` for repo level, and `{owner_id: 1, repo_id: 0}` for org level. 2. `{owner_id: 0, repo_id: 2}` for repo level, and `{owner_id: 1, repo_id: 0}` for org level. The first way seems more reasonable, but it may not be true. The point is that although a resource, like a runner, belongs to a repo (it can be used by the repo), the runner doesn't belong to the repo's org (other repos in the same org cannot use the runner). So, the second method makes more sense. And the first way is not user-friendly to query, we must set the repo id to zero to avoid wrong results. So, #31715 should be right. And the most simple way to fix #31707 is just: ```diff - shared.GetRegistrationToken(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.ID) + shared.GetRegistrationToken(ctx, 0, ctx.Repo.Repository.ID) ``` However, it is quite intuitive to set both owner id and repo id since the repo belongs to the owner. So I prefer to be compatible with it. If we get both owner id and repo id not zero when creating or finding, it's very clear that the caller want one with repo level, but set owner id accidentally. So it's OK to accept it but fix the owner id to zero.
* Drop `IDOrderDesc` for listing Actions task and always order by `id DESC` ↵Jason Song2024-05-311-5/+1
| | | | | | | (#31150) Close #31066 Just follow what `FindRunOptions` and `FindScheduleOptions` do.
* Update misspell to 0.5.1 and add `misspellings.csv` (#30573)silverwind2024-04-273-13/+13
| | | | | | Misspell 0.5.0 supports passing a csv file to extend the list of misspellings, so I added some common ones from the codebase. There is at least one typo in a API response so we need to decided whether to revert that and then likely remove the dict entry.
* Improve job commit description (#30579)yp053272024-04-261-0/+11
| | | | | | | | | | | | | | | | | | | | | Fix https://github.com/go-gitea/gitea/issues/30567 When job is a schedule: ![image](https://github.com/go-gitea/gitea/assets/18380374/b07e9d43-e8b7-4ee2-87b3-a7050c3a8ca5) When it is a normal one: ![image](https://github.com/go-gitea/gitea/assets/18380374/0d58dab9-74bb-421b-8952-0578cdf21a52) also add a 'space' behind `:` ![image](https://github.com/go-gitea/gitea/assets/18380374/4cebece0-bfe6-4ad9-b806-e5c49bb9be43) ![image](https://github.com/go-gitea/gitea/assets/18380374/02da7681-474b-4c0f-9dad-b6558f6cb484) --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Interpolate runs-on with variables when scheduling tasks (#30640)sillyguodong2024-04-232-6/+21
| | | | | | | | | | Follow #29468 1. Interpolate runs-on with variables when scheduling tasks. 2. The `GetVariablesOfRun` function will check if the `Repo` of the run is nil. --------- Co-authored-by: Giteabot <teabot@gitea.io>
* Add a db consistency check to remove runners that do not belong to a ↵Zettat1232024-04-231-2/+24
| | | | | repository (#30614) Follow #30406
* Avoid user does not exist error when detecting schedule actions when the ↵yp053272024-04-111-0/+3
| | | | | | | | | | | | | | | | commit author is an external user (#30357) ![image](https://github.com/go-gitea/gitea/assets/18380374/ddf6ee84-2242-49b9-b066-bd8429ba4d76) When repo is a mirror, and commit author is an external user, then `GetUserByEmail` will return error. reproduce/test: - mirror Gitea to your instance - disable action and enable it again, this will trigger `DetectAndHandleSchedules` ps: also follow #24706, it only fixed normal runs, not scheduled runs.
* Refactor more filterslice (#30370)Lunny Xiao2024-04-101-10/+3
|
* Fix ambiguous id when fetch Actions tasks (#30382)Jason Song2024-04-101-1/+1
| | | | | | | Fix regression of #30331. ```txt time="2024-04-10T02:23:49Z" level=error msg="failed to fetch task" func="[fetchTask]" file="[poller.go:91]" error="unknown: rpc error: code = Internal desc = pick task: CreateTaskForRunner: Error 1052 (23000): Column 'id' in field list is ambiguous" ```
* Add container.FilterSlice function (#30339)oliverpool2024-04-096-54/+27
| | | | | | | | | | | | | | | | | | | | | | | | | Many places have the following logic: ```go func (jobs ActionJobList) GetRunIDs() []int64 { ids := make(container.Set[int64], len(jobs)) for _, j := range jobs { if j.RunID == 0 { continue } ids.Add(j.RunID) } return ids.Values() } ``` this introduces a `container.FilterMapUnique` function, which reduces the code above to: ```go func (jobs ActionJobList) GetRunIDs() []int64 { return container.FilterMapUnique(jobs, func(j *ActionRunJob) (int64, bool) { return j.RunID, j.RunID != 0 }) } ```
* Avoid running action when action unit is disabled after workflows detected ↵yp053272024-04-081-1/+4
| | | | | | | | | | | | | (#30331) Fix #30243 We only checking unit disabled when detecting workflows, but not in runner `FetchTask`. So if a workflow was detected when action unit is enabled, but disabled later, `FetchTask` will still return these detected actions. Global setting: repo.ENABLED and repository.`DISABLED_REPO_UNITS` will not effect this.
* Add API for `Variables` (#29520)sillyguodong2024-03-281-11/+16
| | | | | | | close #27801 --------- Co-authored-by: silverwind <me@silverwind.io>
* Cancel previous runs of the same PR automatically (#29961)Jason Song2024-03-212-6/+7
| | | | | | | | | | | Follow #25716. Also cancel previous runs for `pull_request_sync`. It's not a bug since it original PR said "if the event is push". The main change is https://github.com/go-gitea/gitea/pull/29961/files#diff-08adda3f8ae0360937f46abb1f4418603bd3518522baa356be11c6c7ac4abcc3. And also rename `CancelRunningJobs` to `CancelPreviousJobs` to make it more clear.
* Make runs-on support variable expression (#29468)sillyguodong2024-03-081-0/+33
| | | | | | | | As title. Close issue: https://gitea.com/gitea/act_runner/issues/445 Follow: https://gitea.com/gitea/act/pulls/91 Move `getSecretsOfTask` and `getVariablesOfTask` under `models` because of circular dependency issues.
* remove util.OptionalBool and related functions (#29513)65432024-03-021-5/+8
| | | | | | and migrate affected code _last refactoring bits to replace **util.OptionalBool** with **optional.Option[bool]**_
* Implement actions badge svgs (#28102)Nanguan Lin2024-02-271-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | replace #27187 close #23688 The badge has two parts: label(workflow name) and message(action status). 5 colors are provided with 7 statuses. Color mapping: ```go var statusColorMap = map[actions_model.Status]string{ actions_model.StatusSuccess: "#4c1", // Green actions_model.StatusSkipped: "#dfb317", // Yellow actions_model.StatusUnknown: "#97ca00", // Light Green actions_model.StatusFailure: "#e05d44", // Red actions_model.StatusCancelled: "#fe7d37", // Orange actions_model.StatusWaiting: "#dfb317", // Yellow actions_model.StatusRunning: "#dfb317", // Yellow actions_model.StatusBlocked: "#dfb317", // Yellow } ``` preview: ![1](https://github.com/go-gitea/gitea/assets/70063547/5465cbaf-23cd-4437-9848-2738c3cb8985) ![2](https://github.com/go-gitea/gitea/assets/70063547/ec393d26-c6e6-4d38-b72c-51f2494c5e71) ![3](https://github.com/go-gitea/gitea/assets/70063547/3edb4fdf-1b08-4a02-ab2a-6bdd7f532fb2) ![4](https://github.com/go-gitea/gitea/assets/70063547/8c189de2-2169-4251-b115-0e39a52f3df8) ![5](https://github.com/go-gitea/gitea/assets/70063547/3fe22c73-c2d7-4fec-9ea4-c501a1e4e3bd) --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: delvh <dev.lh@web.de>
* Artifact deletion in actions ui (#27172)FuXiaoHei2024-02-181-0/+22
| | | | | | | | | | | Add deletion link in runs view page. Fix #26315 ![image](https://github.com/go-gitea/gitea/assets/2142787/aa65a4ab-f434-4deb-b953-21e63c212033) When click deletion button. It marks this artifact `need-delete`. This artifact would be deleted when actions cleanup cron task.
* Refactor locale&string&template related code (#29165)wxiaoguang2024-02-142-2/+2
| | | | | | Clarify when "string" should be used (and be escaped), and when "template.HTML" should be used (no need to escape) And help PRs like #29059 , to render the error messages correctly.
* Fix incorrect action duration time when rerun the job before executed once ↵yp053272024-01-191-5/+8
| | | | | | | | | | | | | | | | | | (#28364) Fix #28323 Reason was mentioned here: https://github.com/go-gitea/gitea/issues/28323#issuecomment-1841867298 ### Changes: (maybe breaking) We can rerun jobs in Gitea, so there will be some problems in calculating duration time. In this PR, I use the exist `Started` and `Stopped` column to record the last run time instead of the total time, and add a new `PreviousDuration` column to record the previous duration time. You can also check the cost time of last run: ![image](https://github.com/go-gitea/gitea/assets/18380374/2ca39145-2c92-401a-b78b-43164f7ae061)
* Fix schedule tasks bugs (#28691)Lunny Xiao2024-01-123-5/+31
| | | | | | | | | | | | | | | | 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.
* Refactor deletion (#28610)delvh2023-12-252-14/+1
| | | | | | | | | | | | | | | | | | Introduce the new generic deletion methods - `func DeleteByID[T any](ctx context.Context, id int64) (int64, error)` - `func DeleteByIDs[T any](ctx context.Context, ids ...int64) error` - `func Delete[T any](ctx context.Context, opts FindOptions) (int64, error)` So, we no longer need any specific deletion method and can just use the generic ones instead. Replacement of #28450 Closes #28450 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Added instance-level variables (#28115)Jean-Baptiste Gomond2023-12-251-8/+4
| | | | | | | | | | | This PR adds instance-level variables, and so closes #27726 ![gitea_instance_variables_1](https://github.com/go-gitea/gitea/assets/8344487/ad409cd4-ce36-4c84-a764-34451b0fb63a) ![gitea_instance_variables_2](https://github.com/go-gitea/gitea/assets/8344487/426f0965-dec6-4560-948c-067cdeddd720) ![gitea_instance_variables_3](https://github.com/go-gitea/gitea/assets/8344487/cf1d7776-4938-4825-922e-cbbbf28a5f33)
* Only check online runner when detecting matching runners in workflows (#28286)yp053272023-12-181-2/+15
| | | | | | | | | | | Mentioned: [#28277](https://github.com/go-gitea/gitea/issues/28277#issuecomment-1831325276) We should only check online runner when detecting matching runners in workflows, as if runner is not online, the workflow will not run. ![image](https://github.com/go-gitea/gitea/assets/18380374/11855e9d-7241-4b7a-b8d7-49dbb94ba1c5)
* Fix incorrect run order of action jobs (#28367)yp053272023-12-061-1/+1
| | | | | | When we pick up a job, all waiting jobs should firstly be ordered by update time, otherwise when there's a running job, if I rerun an older job, the older job will run first, as it's id is smaller.
* Use db.Find instead of writing methods for every object (#28084)Lunny Xiao2023-11-249-124/+48
| | | | For those simple objects, it's unnecessary to write the find and count methods again and again.
* Fix no ActionTaskOutput table waring (#28149)yp053272023-11-211-0/+4
| | | | | | | | | | | | | | | Reproduce: - Create a new Gitea instance - Register a runner - Create a repo and add a workflow - Check the log, you will see warnings: ![image](https://github.com/go-gitea/gitea/assets/18380374/5f1278e0-114b-48bc-8113-8ba1404d9975) It comes from: ![image](https://github.com/go-gitea/gitea/assets/18380374/c2807831-e137-4229-9536-87f6114c8a5b) The reason is that we forgot registering `ActionTaskOutput` model. So `action_table_output` table will be missing in your db.
* Remove action runners on user deletion (#27902)Earl Warren2023-11-051-0/+24
| | | | | | | | | | - On user deletion, delete action runners that the user has created. - Add a database consistency check to remove action runners that have nonexistent belonging owner. - Resolves https://codeberg.org/forgejo/forgejo/issues/1720 (cherry picked from commit 009ca7223dab054f7f760b7ccae69e745eebfabb) Co-authored-by: Gusted <postmaster@gusted.xyz>
* Upgrade to golangci-lint@v1.55.0 (#27756)silverwind2023-10-241-1/+1
| | | https://github.com/golangci/golangci-lint/releases/tag/v1.55.0
* Add unit tests for action runner token (#27670)Nanguan Lin2023-10-192-0/+58
| | | In case the behavior of the register token changes.
* Fix typo "GetLatestRunnerToken" (#27680)Jason Song2023-10-181-2/+2
|
* Penultimate round of `db.DefaultContext` refactor (#27414)JakobDev2023-10-114-7/+7
| | | | | | | Part of #27065 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Redefine the meaning of column is_active to make Actions Registration Token ↵Lunny Xiao2023-09-271-8/+18
| | | | | | | | | | | | | | | generation easier (#27143) Partially Fix #25041 This PR redefined the meaning of column `is_active` in table `action_runner_token`. Before this PR, `is_active` means whether it has been used by any runner. If it's true, other runner cannot use it to register again. In this PR, `is_active` means whether it's validated to be used to register runner. And if it's true, then it can be used to register runners until it become false. When creating a new `is_active` register token, any previous tokens will be set `is_active` to false.
* Next round of `db.DefaultContext` refactor (#27089)JakobDev2023-09-162-8/+8
| | | Part of #27065
* resolve issue with sort icons on admin/users and admin/runners (#24360)jladbrook2023-09-121-0/+6
| | | | Fixes #24327 to avoid the sort icon changing the table header over multiple lines and adds missing sort icons on the runners page.
* Add a new column schedule_id for action_run to track (#26975)Lunny Xiao2023-09-081-1/+2
| | | | | | | | Fix #26971 And the UI now will display it's scheduled but not triggered by a push. <img width="954" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/d211845c-457e-4c3e-af1f-a0d654d3f365">