mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-12 02:24:21 -05:00
[Proposal] Use actionlint to parse Actions workflow files instead of act #10808
Open
opened 2025-11-02 09:18:42 -06:00 by GiteaMirror
·
8 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.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.3
v1.4.0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#10808
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @wolfogre on GitHub (May 9, 2023).
This idea was inspired during a discussion with the nektos maintainers team.
Background
Act runner depends on act to run jobs, as act provides the necessary infrastructure. However, Gitea also depends on Act because Gitea needs the models defined in Act to parse workflow files and assign tasks.
For example, Gitea needs to extract
onfrom the workflow file to decide which event to trigger, and alsoruns-onof jobs to match runners.Unfortunately, the models defined in act are not incomplete because some fields do not matter when running workflows locally (which is what act is designed to do), such as permissions and concurrency.
Solution
If we add full syntax support to
actor other packages, we would be reinventing the wheel, because actionlint has already done it.Although actionlint could be used as a command-line tool, it is also designed as a library. See the document which describes how to use actionlint as a Go library. Actually,
actimports it too.So we could replace act in Gitea with actionlint to parse workflow files.
Possible difficulties
The forked act has a new package
act/pkg/jobparserto split jobs in single files. LikeThis is for distributing jobs to multiple runners. The jobs may run on different platforms and run concurrently.
It may be difficult to do it again with actionlint. A half-baked idea of mine is:
IIRC, act supports specifying job but not matrix. So, there may be more work to do.
@wolfogre commented on GitHub (Jul 17, 2023):
Originally posted by @ChristopherHX
@TheFox0x7 commented on GitHub (Sep 2, 2023):
I assume by js parser he means one in https://github.com/actions/languageservices which might be useful for validating before commit?
Also what is
insert? It's as you say undocumented and I have no clue what it could be.Regarding ignoring case - it's changed on main branch of actionlint, but not yet released.
@ChristopherHX commented on GitHub (Sep 3, 2023):
Yes I mean that repo by js parser.
You would have to add the
giteacontext everywhere in the workflowv1 json and tweak it to allow gitea action extensions...it inserts a mapping into a mapping from an expression result. Due to limitations of the workflow validator values on the right side may have to be expressions instead of a yaml mapping.
Yes I read the source code of action/runner carefully, it is somewhat documented there.
This example won't work in nektos/act.
insert has been implemented under
jobs.<id>.strategy.matrixof nektos/act.BTW this
inserthas been copied from the original Azure Pipelines Code Base, it is also undocumented there.@ChristopherHX commented on GitHub (Sep 3, 2023):
Here are the references of the actions/runner:
143639ddac/src/Sdk/DTObjectTemplating/ObjectTemplating/TemplateUnraveler.cs (L440)However that example still uses azure pipelines yaml syntax
@ChristopherHX commented on GitHub (Sep 3, 2023):
Seems like action lint doesn't validate workflow keys of expression enabled objects.
So it doesn't make
${{ insert }}an error as of now.In Github Actions is the following also possible (
jobs.<id>.envallows expressions recursively and not only for the value)Actionlint handles this one perfectly fine
However doesn't parse
${{ matrix.key }}, but this could be fixed.All in all Actionlint is pretty good, while having it's own parser.
@TheFox0x7 commented on GitHub (Sep 3, 2023):
It does when a expression linter rule is applied, but that's after parsing and we have no reason to use it.
Since you probably know - when are expressions expanded? Taking your example:
@ChristopherHX commented on GitHub (Sep 3, 2023):
Isn't it enabled by default in the online playground? I only see errors and syntax highlighting about expressions in yaml values (not keys).
Yes and this is server side expanded, then the strategy is expanded to a list of sibling jobs.
However the whole strategy key is an expandable expression. Including all keys and values of sub objects.
The last time I looked at the Gitea Actions code, this is not expanded.
Only processed to create sibling jobs.
No, the runner side expands the expression. The runner get's a list of parsed MappingToken of each workflow level.
I reused actions/runner to enable GitHub Actions on my Gitea Server in 2021. However it has flaws with securty, db support and webpage design.
So I know exactly what goes to the actions/runner and what not.
yes this is server side, Gitea Actions is expanding it somehow already on the server before scheduling the job
You can look at the log of my GitHub Actions Emulator to see, when which expression is expanded on the server side.
The order of some fields doesn't matter while expanding expression, while it is important for other fields.
@TheFox0x7 commented on GitHub (Jan 3, 2024):
I was tinkering with this for a long while and have some "drafts", though I haven't tested them at yet.
I got stuck (unsurprisingly, and multiple times) at making a jobparser version based on actionlint. Currently, I'm stuck at the following:
As far as I know, gitea splits the job when the workflow is triggered and inserts the number of runs into the database. This works for simple jobs with no matrix. If the matrix is expanded into more jobs (or runs however you call them) we get more entries.
The issue is, if we don't know about the amount of jobs that the matrix would expand to - we cannot insert them. Picture a case when someone decides one of
matrixlabel in the output of another job, when this one depends on - this is valid because strategy supportsneedscontext. We know that there will be at least one job - but we almost cannot touch it until the prerequisite finishes.I'm thinking about something like this:
Here is a rough concept I have:
Make a middle layer in the database. Idea being that since the job!=run, we can split them into separate tables (one-to-many relations):
Workflows->Jobs->Runs
Parsing workflow would create a finite amount of jobs equal to the jobs in the workflow - I don't have any concrete proposal for the layout of such table, but it could just be a storage for the job metadata (is it a matrix job, is it finished, what permissions would it need, concurrency markers, etc.) kinda like it's now except it's not used for actual runs of the job.
Next from the job we could create a run entry for processing and here we actually can expand the matrix properly into separate jobs.
There are a lot of issues with this that I can think of:
If it was possible, I'd like to combine this move with outsourcing steps to the runner #24604 - to avoid even thinking about how to port step generation to this.
Alternatively, we could try to insert the job with the matrix and later expand it... but I feel like this would end up being more complex to track.
I'm open to different/better ideas though. Maybe someone here sees a less complex way of handling this.