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

Implement actions #21937

Merged
merged 475 commits into from
Jan 31, 2023
Merged

Implement actions #21937

merged 475 commits into from
Jan 31, 2023

Conversation

wolfogre
Copy link
Member

@wolfogre wolfogre commented Nov 25, 2022

Close #13539.

Co-authored by: @lunny @appleboy @fuxiaohei and others.

Related projects:

Summary

The target of this PR is to bring a basic implementation of "Actions", an internal CI/CD system of Gitea. That means even though it has been merged, the state of the feature is EXPERIMENTAL, and please note that:

  • It is disabled by default;
  • It shouldn't be used in a production environment currently;
  • It shouldn't be used in a public Gitea instance currently;
  • Breaking changes may be made before it's stable.

Please comment on #13539 if you have any different product design ideas, all decisions reached there will be adopted here. But in this PR, we don't talk about naming, feature-creep or alternatives.

⚠️ Breaking

gitea-actions will become a reserved user name. If a user with the name already exists in the database, it is recommended to rename it.

Some important reviews

What it looks like

Manage runners

image

List runs

image

View logs

image

How to try it

1. Start Gitea

Clone this branch and install from source.

Add additional configurations in app.ini to enable Actions:

[actions]
ENABLED = true

Start it.

If all is well, you'll see the management page of runners:

image

2. Start runner

Clone the act_runner, and follow the README to start it.

If all is well, you'll see a new runner has been added:

image

3. Enable actions for a repo

Create a new repo or open an existing one, check the Actions checkbox in settings and submit.

image image

If all is well, you'll see a new tab "Actions":

image

4. Upload workflow files

Upload some workflow files to .gitea/workflows/xxx.yaml, you can follow the quickstart of GitHub Actions. Yes, Gitea Actions is compatible with GitHub Actions in most cases, you can use the same demo:

name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
  Explore-GitHub-Actions:
    runs-on: ubuntu-latest
    steps:
      - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
      - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
      - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
      - name: Check out repository code
        uses: actions/checkout@v3
      - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
      - run: echo "🖥️ The workflow is now ready to test your code on the runner."
      - name: List files in the repository
        run: |
          ls ${{ github.workspace }}
      - run: echo "🍏 This job's status is ${{ job.status }}."

If all is well, you'll see a new run in Actions tab:

image

5. Check the logs of jobs

Click a run and you'll see the logs:

image

6. Go on

You can try more examples in the documents of GitHub Actions, then you might find a lot of bugs.

Come on, PRs are welcome.

See also: Feature Preview: Gitea Actions

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 25, 2022
@lunny lunny added type/feature Completely new functionality. Can only be merged if feature freeze is not active. type/changelog Adds the changelog for a new Gitea version labels Nov 25, 2022
@lunny lunny added this to the 1.19.0 milestone Nov 25, 2022
@silverwind

This comment was marked as off-topic.

@wolfogre

This comment was marked as resolved.

Copy link
Contributor

@Gusted Gusted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't intend to review other parts of the code, but this was too notable.


Is it also intended to create documentation for this?

models/bots/task.go Outdated Show resolved Hide resolved
models/bots/runner.go Outdated Show resolved Hide resolved
modules/graceful/server_http.go Outdated Show resolved Hide resolved
models/bots/runner_token.go Outdated Show resolved Hide resolved
models/bots/run.go Outdated Show resolved Hide resolved
@KN4CK3R
Copy link
Member

KN4CK3R commented Nov 28, 2022

Is "bots" the name of the whole CI/CD feature? If yes, then I think that's not a good name because bots are usually something different (machine controlled user accounts).

@lunny
Copy link
Member

lunny commented Nov 28, 2022

It's not only CICD, that's why we don't name it Gitea CI. We have a name discuss in #13539, maybe automate is a better name.

@wolfogre

This comment was marked as resolved.

lunny added a commit that referenced this pull request Dec 1, 2022
Provide a new type to make it easier to parse a ref name.

Actually, it's picked up from #21937, to make the origin PR lighter.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Copy link
Member

@delvh delvh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, after a lot of problems, I've finally been able to successfully test the most critical parts.

I still made some observations:

as you can see here, branch bug, the branch still has the BranchPrefix.
Additionally, only about 5% of the time when I click on the Rerun action, it will actually be rerun. And I can see at the same time that the runner does not get any new tasks while polling.
The last problem I noticed is that canceled workflows are displayed with the same color as failed workflows, but there is no indication anywhere that the reason for this is that the task was canceled.
Lastly, as you might know already, I absolutely dislike the DBFS.
I also noticed some minor things which you can see in the history of all comments on this PR.

However, as it seems at the moment, these things will all be postponed for later PRs.
Once this PR is merged, I'll create a follow-up issue where I post everything that was postponed here to merge it in time for 1.19.

@wxiaoguang
Copy link
Contributor

Lastly, as you might know already, I absolutely dislike the DBFS.

I would like to suggest reviewers to always provide alternative and feasible solutions when something is disliked. Otherwise, there will be non-sense arguments, the author won't know what to do.

@ChristopherHX
Copy link
Contributor

ChristopherHX commented Jan 30, 2023

the branch still has the BranchPrefix

This is expected behavior. Use github.ref_name if you don't want the prefix.

EDIT
I see github.ref_name is incorrect in this PR, github.ref should not be equal to github.ref_name.
I expected that github.ref_name is correct, because it has no refs/heads/ prefix under nektos/act.

@yardenshoham
Copy link
Member

yardenshoham commented Jan 30, 2023

PR's too awesome for lgtm bot to handle? Both @lunny + @delvh approved!

@delvh delvh 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 Jan 30, 2023
@delvh
Copy link
Member

delvh commented Jan 30, 2023

I've done the work of the 🤖 now myself.
Let's let it 😴 a bit longer. It needs the rest.

@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Jan 30, 2023
@delvh
Copy link
Member

delvh commented Jan 30, 2023

Okay, now I feel bullied.

@lunny
Copy link
Member

lunny commented Jan 31, 2023

@delvh You did work well. Thank you very much!!!

@lunny
Copy link
Member

lunny commented Jan 31, 2023

make LG-TM work

@lunny lunny merged commit 4011821 into go-gitea:main Jan 31, 2023
@wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf
Copy link
Contributor

great work y'all!
can I ask, does "It shouldn't be used in a public Gitea instance currently;" still apply or was it there just for the development phase?

@delvh
Copy link
Member

delvh commented Jan 31, 2023

That sentence is meanst as "large public instances such as Codeberg should probably not enable it", mainly because of the stress it places on that system.
For instances where you know everyone, this shouldn't apply.

zeripath pushed a commit that referenced this pull request Jan 31, 2023
If triggered by PR, the ref should be `pull/<index>/head` instead of
`repo.DefaultBranch`.

And improve UI:

<img width="493" alt="image"
src="https://user-images.githubusercontent.com/9418365/215731280-312564f2-2450-45d0-b986-1accb0670976.png">


Related to #21937.
lunny added a commit that referenced this pull request Feb 1, 2023
#21937 implemented only basic events based on name because of `act`'s
limitation. So I sent a PR to parse all possible events details in
https://gitea.com/gitea/act/pulls/11 and it merged. The ref
documentation is
https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows

This PR depends on that and make more detail responses for `push` events
and `pull_request` events. And it lefts more events there for future
PRs.

---------

Co-authored-by: Jason Song <i@wolfogre.com>
wolfogre added a commit that referenced this pull request Feb 5, 2023
Should call `PushToBaseRepo` before
`notification.NotifyPullRequestSynchronized`.

Or the notifier will get an old commit when reading branch
`pull/xxx/head`.

Found by ~#21937~ #22679.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
@ghnp5
Copy link

ghnp5 commented Feb 20, 2023

Hey!

My understanding is that this is merged to main.

I have updated the Docker image earlier today, from the latest release.

I have:

[actions]
ENABLED = true

But Gitea 1.18.4 (shows on the footer) still doesn't show anything about Actions/Runners.

Am I doing anything wrong, or does this release not yet include Actions at all?

Thanks!

@lunny
Copy link
Member

lunny commented Feb 20, 2023

If you are using docker, using dev currently not 1.18.4.

@go-gitea go-gitea locked as off-topic and limited conversation to collaborators Feb 20, 2023
@yardenshoham yardenshoham removed the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Mar 20, 2023
@delvh delvh removed the type/changelog Adds the changelog for a new Gitea version label Oct 7, 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. pr/breaking Merging this PR means builds will break. Needs a description what exactly breaks, and how to fix it! type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet