Repository navigation
feat(gitlab): default pipeline schedule on the least used slot - #67
Merged
Merged
Conversation
The message shown when a project already has a mirror still suggested the old `opsi gitlab update mirroring` command, removed by the command reorder. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add `opsi gitlab schedule create <project>...`, which creates a weekly pipeline schedule on one or more existing projects (ID or path). The slot is not chosen by hand: it is the least used one among the working days between 09:00 and 18:00 (Europe/Rome, 15 minutes slots), counting the active schedules of every project, the ones in another time zone included, and the ones created in the same run. So the pipelines are spread instead of starting together. The schedule runs on `main` when the project has it, otherwise on the default branch. A project that already has an active schedule is left alone, and a failing project does not stop the others. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
`opsi gitlab project create <name> -c` creates the default weekly pipeline schedule at the end of the creation, on the least used slot. Without the flag nothing changes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add `opsi gitlab schedule update <project>...`, which gives to the user of the token the pipeline schedules of one or more projects that belong to someone else, or to nobody. A schedule runs as its owner, so it stops when the owner is blocked, deactivated or removed; taking the ownership works in every case. Cron, branch and description are not touched. --dry-run only shows the schedules with their owner, and asks no confirmation. Without it the command asks for a confirmation, unless -f. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
`schedule update` took every schedule owned by someone else, so launching it with a personal token would have stolen the schedules of a service user. Take only the schedules whose owner is missing, blocked or deactivated, the ones that stopped running; the schedules of an active user are left alone. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
`opsi gitlab schedule update` without projects checks all of them, 5 at a time, with the progress on a single line. It only looks at the active schedules: it never creates or activates one, so the projects without an active schedule are ignored. A project whose schedules cannot be read (pipelines disabled) is skipped without failing the command, unless it was named explicitly. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A project can have more schedules with the same cron, so the lines looked like duplicates. Show the description of each schedule next to the project. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The other commands take the numeric ID of the project (and of the group), so the schedule commands do the same instead of also accepting the path. Support for the path can be added to every command later. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New projects had no pipeline schedule, so whoever wanted a periodic run (e.g. to rebuild the Docker images with the latest patches) created it by hand, usually at the same time as everyone else. This adds an opt-in default schedule whose time is chosen by the tool, so the pipelines are spread.
The schedule (defaults in code, no configuration)
mainwhen the project has it, otherwise on the default branchopsi default scheduleCommands
opsi gitlab project create <name> ... -c(--schedule): creates the schedule at the end of the creation. Without the flag nothing changes.opsi gitlab schedule create {project_id}...: creates the schedule on existing projects. A project that already has an active schedule is skipped; a failing project does not stop the others.opsi gitlab schedule update [project_id]...: fixes the active schedules that lost their owner (the owner does not exist anymore, is blocked or is deactivated). A schedule runs as its owner, so it stops silently when the owner goes away. Those schedules are given to the user of the token withtake_ownership. The schedules of an active user are left alone, and cron, branch and description are not touched. It never creates or activates anything. Without projects it checks all of them (5 at a time, progress on one line); projects whose schedules cannot be read (pipelines disabled) are skipped.--dry-runonly shows the schedules with their description and owner, and asks no confirmation.The projects are referred to by numeric ID, like the other commands.
Also fixes the hint of
mirror create, which still suggested the removedupdate mirroringcommand.Notes
cicd; the ones created with a personal token will belong to that user. Giving them tocicdwould need a token with thesudoscope (Sudoheader) or thecicdtoken: not part of this PR.Test plan
go vet ./...andgo test ./...(slot choice and spreading, existing cron parsing and time zone conversion, create with an existing schedule / withoutmain/ failing project, update dry run, orphan owner, inactive schedules, projects without pipelines)opsi gitlab schedule update --dry-runongit.beliven.dev(241 projects): the 3 active schedules, all owned bycicd, are left aloneopsi gitlab schedule create <id>on a test repo, twice (second run skips), and check it in Build > Pipeline schedulesopsi gitlab project create ... -con a test group🤖 Generated with Claude Code