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

chore(actions): support cron schedule task #26655

Merged
merged 104 commits into from
Aug 24, 2023
Merged

Conversation

lunny
Copy link
Member

@lunny lunny commented Aug 22, 2023

Replace #22751

  1. only support the default branch in the repository setting.
  2. autoload schedule data from the schedule table after starting the service.
  3. support specific syntax like @yearly, @monthly, @weekly, @daily, @hourly

How to use

See the GitHub Actions document for getting more detailed information.

on:
  schedule:
    - cron: '30 5 * * 1,3'
    - cron: '30 5 * * 2,4'

jobs:
  test_schedule:
    runs-on: ubuntu-latest
    steps:
      - name: Not on Monday or Wednesday
        if: github.event.schedule != '30 5 * * 1,3'
        run: echo "This step will be skipped on Monday and Wednesday"
      - name: Every time
        run: echo "This step will always run"

Signed-off-by: Bo-Yi.Wu appleboy.tw@gmail.com

appleboy and others added 30 commits March 10, 2023 18:30
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Remove `robfig/cron/v3 v3.0.1` from `go.mod`
- Remove `newSchedule()` and `resetSchedule()` functions from `services/actions/init.go`
- Change return type of `CreateScheduleTask()` from `(int, error)` to `error` in `services/actions/notifier_helper.go`
- Add `services/actions/schedule_tasks.go` file
- Add `StartScheduleTasks()` and `startTasks()` functions to `services/actions/schedule_tasks.go`
- Register `start_schedule_tasks` task in `services/cron/tasks_actions.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
- Add a new function `GetSchedulesMapByIDs` to retrieve schedules by ID
- Create new schedule and schedule spec when creating a schedule task
- Delete schedule specs when deleting a schedule
- Add a new model `ActionScheduleSpec` for schedule specs

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
- Rename v245.go to v246.go
- Add a new migration for action schedule table addition

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
- Rename the `Webhook org_id` column to `owner_id`
- Add a new migration for creating an `action schedule` table
…nability

- Rename `jobs` to `workflows` in `notifier_helper.go`
- Fix the `if` statement to properly continue in `notifier_helper.go`
- Remove unnecessary `else` block in `notifier_helper.go`

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
…on v246

- Remove `EntryIDs` field from `ActionSchedule` struct in `schedule.go`
- Remove `EntryIDs` field from migration v246 in `v1_20` folder

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Rename `jobs` to `workflows` for clarity
- Simplify error handling in line 14
- Simplify error handling in line 19
- Remove unnecessary else statement in line 22

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Remove the license for `github.com/robfig/cron/v3`

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Update `CreateScheduleTask` to use the passed context instead of `db.DefaultContext`
- Update `DeleteScheduleTaskByRepo` to use the passed context instead of `db.DefaultContext`

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Delete the `ifNeedApproval` function from `notifier_helper.go`

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Add a license to the `go-licenses.json` file

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Remove a line that had no newline at the end of the file

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Add an import statement in `schedule_spec_list.go`

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Change `run` initialization to a pointer
- Add function `ifNeedApproval` for deciding if a user needs approval
- Modify `handleWorkflows` to use `ifNeedApproval` function
- Add `NeedApproval` field to `run` in `handleWorkflows` function

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Fix a typo in the `CreateScheduleTask` function
- Remove unnecessary code from the `CreateScheduleTask` function

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Add `xorm: "index"` tag to `RepoID` and `ScheduleID` fields in `ActionScheduleSpec`
- Remove `RepoID` and `ScheduleID` fields from the model struct

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Remove the function `CreateScheduleTask` from the `notifier_helper.go` file
- Add the function `CreateScheduleTask` to the `schedule_tasks.go` file, which creates a scheduled task from a cron action schedule and a spec string. It creates an action run based on the schedule, inserts it into the database, and creates commit statuses for each job.

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Change in variable assignment for `specs` in `startTasks` function

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Remove the handleWorkflows function and replace it with a new version that has a different signature and takes more arguments.

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
Co-authored-by: Jason Song <i@wolfogre.com>
- Update the `now` variable to truncate to the nearest minute
- Change the calculation of `next` to use `now.Add(-1)` instead of `now`
- Replace `next.Sub(now) <= 60` with `schedule.Next(now.Add(-1)).Equal(now)`

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
- Change the initialization of `crons` to allocate capacity upfront, improving performance.
- Remove an unused variable definition.
- Add a new function `startTasks` with `opts` parameter.

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Aug 22, 2023
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Aug 23, 2023
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Aug 23, 2023
@lunny lunny enabled auto-merge (squash) August 24, 2023 01:08
@lunny lunny merged commit 0d55f64 into go-gitea:main Aug 24, 2023
24 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Aug 24, 2023
@lunny lunny deleted the appleboy-schedule branch August 24, 2023 11:17
zjjhot added a commit to zjjhot/gitea that referenced this pull request Aug 25, 2023
* giteaofficial/main:
  Fix review bar misalignment (go-gitea#26711)
  Use "small-loading-icon" insead of "btn-octicon is-loading" (go-gitea#26710)
  Improve Image Diff UI (go-gitea#26696)
  Make issue template field template access correct template data (go-gitea#26698)
  add Upload URL to release API (go-gitea#26663)
  Add merge files files to GetCommitFileStatus (go-gitea#20515)
  PATCH branch-protection updates check list even when checks are disabled (go-gitea#26351)
  Add `member`, `collaborator`, `contributor`, and `first-time contributor` roles and tooltips (go-gitea#26658)
  chore(actions): support cron schedule task (go-gitea#26655)
@nouknouk
Copy link

nouknouk commented Aug 27, 2023

I tested here with latest nightly (rootfull) docker build and a dumb workflow.
The feature works well.

Many thanks @appleboy , @lunny and reviewers 👍

@go-gitea go-gitea locked as resolved and limited conversation to collaborators Nov 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. topic/gitea-actions related to the actions of Gitea 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.

None yet

7 participants