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

adapt act_runner exec in action file #25524

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

a1012112796
Copy link
Member

@a1012112796 a1012112796 commented Jun 26, 2023

Signed-off-by: a1012112796 <1012112796@qq.com>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 26, 2023
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 26, 2023
@silverwind
Copy link
Member

Wait, is this changing something that works on GH Actions to work on Gitea Actions? Why not fix the root cause?

@a1012112796
Copy link
Member Author

Wait, is this changing something that works on GH Actions to work on Gitea Actions? Why not fix the root cause?

not, just want make act_runner exec useable, checking changed files is meaningless when using act_runner exec, so just skip this step and make all jobs runable.

@silverwind
Copy link
Member

silverwind commented Jun 27, 2023

Right, so act_runner exec does not run in the scope of a commit with a diff?

Maybe it should instead be something like act_runner exec <commit-ish> to run on a specific commit hash, so that the environment is more close to what it would usually run and changed-when can do its work? I guess there is still value in running locally without a commit, but I'm not sure how to solve that. A number of actions will depend on commit data being present.

@silverwind
Copy link
Member

silverwind commented Jun 27, 2023

I would at minimum make it skip when commit-related environment variables are not set, which I think is the case of exec, e.g. don't make it detect ACT_EXEC but instead GITHUB_SHA or GITEA_SHA being unset.

Ideally this check would be done in the paths-filter action, e.g. when it is unset, trigger all changes.

@a1012112796
Copy link
Member Author

I would at minimum make it skip when commit-related environment variables are not set, which I think is the case of exec, e.g. don't make it detect ACT_EXEC but instead GITHUB_SHA or GITEA_SHA being unset.

Ideally this check would be done in the paths-filter action, e.g. when it is unset, trigger all changes.

I think checking changed files is meaningless when using act_runner exec. that's because when using act_runner exec, user can choose a job to run manually, so it's not necessary to auto check whether a job should run. not meaning I can't produe some commit-related environment variables to make paths-filter action work in act_runner exec.

@silverwind
Copy link
Member

silverwind commented Jun 27, 2023

Hmm I still wonder if there is a cleaner solution and whetherpaths-filter could somehow be made into emitting all files as changed. Detecting based on ACT_EXEC feels like user-agent sniffing, a very bad practice.

@silverwind
Copy link
Member

silverwind commented Jun 29, 2023

Would base: HEAD option of paths-filter work for this? I think it should also work on uncommited changes as per https://github.com/dorny/paths-filter docs, and I think it should also work for our regular runs.

Signed-off-by: a1012112796 <1012112796@qq.com>
@pull-request-size pull-request-size bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 30, 2023
Signed-off-by: a1012112796 <1012112796@qq.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 19, 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 19, 2023
@silverwind silverwind self-requested a review August 19, 2023 13:01
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Aug 19, 2023
@GiteaBot GiteaBot removed the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Aug 20, 2023
@GiteaBot GiteaBot added the lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. label Aug 20, 2023
@silverwind
Copy link
Member

silverwind commented Aug 20, 2023

Let's try with base: HEAD, I think it will work fine for regular runs as well because:

  1. There are no unclean files in a PR checkout, so HEAD should equal the last commit on the branch
  2. The option says that base is ignored for pull_request events

@silverwind
Copy link
Member

Actually it did not work, with HEAD:

Run dorny/paths-filter@v2
Change detection on HEAD
Detected 0 changed files
Results:
Filter backend = false
Filter frontend = false
Filter docs = false
Filter actions = false
Filter templates = false
Filter docker = false
Filter swagger = false
Changes output set to []

Without HEAD:

Run dorny/paths-filter@v2
Fetching list of changed files for PR#25524 from Github API
Detected 4 changed files
Results:
Filter backend = true
Filter frontend = false
Filter docs = false
Filter actions = true
Filter templates = false
Filter docker = false
Filter swagger = false
Changes output set to ["backend","actions"]

Maybe we actually need to detect exec via one of the vars.

@silverwind
Copy link
Member

@a1012112796 can you try latest change with act exec? I think ref is the right option to set, base was incorrect because that was the base branch it compared to.

@silverwind silverwind self-requested a review August 20, 2023 14:31
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Aug 20, 2023
@a1012112796
Copy link
Member Author

a1012112796 commented Aug 21, 2023

@silverwind test result, looks 'base' is required.
image

How about someting like this?

@@ -36,7 +36,7 @@ jobs:
         id: changes
         with:
           # needed for `act_runner exec`
-          ref: ${{ env.ACT_EXEC == 'true' && 'HEAD' || env.GITHUB_REF }}
+          base: ${{ env.ACT_EXEC == 'true' && 'HEAD' || '' }}
           filters: |
             backend:
               - "**/*.go"

Signed-off-by: a1012112796 <1012112796@qq.com>
@silverwind
Copy link
Member

Hmm I think we lack github.event.repository.default_branch in the act payload, else it would work.

@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 21, 2023
@silverwind silverwind self-requested a review August 21, 2023 14:35
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Aug 21, 2023
@silverwind
Copy link
Member

silverwind commented Aug 21, 2023

@a1012112796 please try this one, I set base: main, e.g. compare commit to main branch. Likely not correct for non-main PRs but good enough for a test.

@a1012112796
Copy link
Member Author

a1012112796 commented Aug 22, 2023

@silverwind looks no changed files was found ...
image

full logs: time="2023-08-22T01:04:24Z" level=info msg="Using chosed event for filtering: pull_request" time="2023-08-22T01:04:24Z" level=info msg="Planning job: test-unit" time="2023-08-22T01:04:24Z" level=info msg="cache handler listens on: http://192.168.170.128:43319" time="2023-08-22T01:04:24Z" level=info msg="Start server on http://192.168.170.128:34567" [files-changed/files-changed/detect] 🚀 Start image=catthehacker/ubuntu:runner-latest time="2023-08-22T01:04:24Z" level=info msg="Parallel tasks (0) below minimum, setting to 1" [files-changed/files-changed/detect] 🐳 docker pull image=catthehacker/ubuntu:runner-latest platform= username= forcePull=false time="2023-08-22T01:04:24Z" level=info msg="Parallel tasks (0) below minimum, setting to 1" [files-changed/files-changed/detect] 🐳 docker create image=catthehacker/ubuntu:runner-latest platform= entrypoint=["/bin/sleep" "10800"] cmd=[] [files-changed/files-changed/detect] 🐳 docker run image=catthehacker/ubuntu:runner-latest platform= entrypoint=["/bin/sleep" "10800"] cmd=[] [files-changed/files-changed/detect] 🐳 docker exec cmd=[chown -R 1001:1001 /home/zzc/gitea_ws/gitea] user=0 workdir= [files-changed/files-changed/detect] ☁ git clone 'https://github.com/dorny/paths-filter' # ref=v2 [files-changed/files-changed/detect] ⭐ Run Main actions/checkout@v3 [files-changed/files-changed/detect] 🐳 docker cp src=/home/zzc/gitea_ws/gitea/. dst=/home/zzc/gitea_ws/gitea [files-changed/files-changed/detect] 🐳 docker exec cmd=[chown -R 1001:1001 /home/zzc/gitea_ws/gitea] user=0 workdir= [files-changed/files-changed/detect] ✅ Success - Main actions/checkout@v3 [files-changed/files-changed/detect] ⭐ Run Main dorny/paths-filter@v2 [files-changed/files-changed/detect] 🐳 docker cp src=/home/zzc/.cache/act/dorny-paths-filter@v2/ dst=/var/run/act/actions/dorny-paths-filter@v2/ [files-changed/files-changed/detect] 🐳 docker exec cmd=[chown -R 1001:1001 /var/run/act/actions/dorny-paths-filter@v2/] user=0 workdir= [files-changed/files-changed/detect] 🐳 docker exec cmd=[node /var/run/act/actions/dorny-paths-filter@v2/dist/index.js] user= workdir= [files-changed/files-changed/detect] ❓ ::group::Get current git ref [files-changed/files-changed/detect] | ::group::Get current git ref [files-changed/files-changed/detect] | [command]/usr/bin/git branch --show-current [files-changed/files-changed/detect] | zzc/dev/act_runner_exec [files-changed/files-changed/detect] ❓ ::endgroup:: [files-changed/files-changed/detect] | ::endgroup:: [files-changed/files-changed/detect] | Changes will be detected between main and HEAD [files-changed/files-changed/detect] ❓ ::group::Searching for merge-base main...HEAD [files-changed/files-changed/detect] | ::group::Searching for merge-base main...HEAD [files-changed/files-changed/detect] | [command]/usr/bin/git show-ref main [files-changed/files-changed/detect] | b3f713717407fcb66515a7a702e81b2028800f76 refs/heads/main [files-changed/files-changed/detect] | 3db3f5daaeea38a9a8d8ec1a05d864e288338f82 refs/remotes/or_p/main [files-changed/files-changed/detect] | da6df0d0636c9e7bb5481e41dcd7d8f9b46deed5 refs/remotes/or_zzc/main [files-changed/files-changed/detect] | b3f713717407fcb66515a7a702e81b2028800f76 refs/remotes/origin/main [files-changed/files-changed/detect] | 1e76a824bcd71acd59cdfb2c4547806bc34b3d86 refs/remotes/yp05327/main [files-changed/files-changed/detect] | [command]/usr/bin/git show-ref HEAD [files-changed/files-changed/detect] | b3f713717407fcb66515a7a702e81b2028800f76 refs/remotes/origin/HEAD [files-changed/files-changed/detect] | [command]/usr/bin/git merge-base refs/remotes/origin/main refs/remotes/origin/HEAD [files-changed/files-changed/detect] | b3f713717407fcb66515a7a702e81b2028800f76 [files-changed/files-changed/detect] ❓ ::endgroup:: [files-changed/files-changed/detect] | ::endgroup:: [files-changed/files-changed/detect] ❓ ::group::Change detection refs/remotes/origin/main...refs/remotes/origin/HEAD [files-changed/files-changed/detect] | ::group::Change detection refs/remotes/origin/main...refs/remotes/origin/HEAD [files-changed/files-changed/detect] | [command]/usr/bin/git diff --no-renames --name-status -z refs/remotes/origin/main...refs/remotes/origin/HEAD [files-changed/files-changed/detect] | [files-changed/files-changed/detect] ❓ ::endgroup:: [files-changed/files-changed/detect] | ::endgroup:: [files-changed/files-changed/detect] | Detected 0 changed files [files-changed/files-changed/detect] | Results: [files-changed/files-changed/detect] ❓ ::group::Filter backend = false [files-changed/files-changed/detect] | ::group::Filter backend = false [files-changed/files-changed/detect] | Matching files: none [files-changed/files-changed/detect] ❓ ::endgroup:: [files-changed/files-changed/detect] | ::endgroup:: [files-changed/files-changed/detect] ❓ ::group::Filter frontend = false [files-changed/files-changed/detect] | ::group::Filter frontend = false [files-changed/files-changed/detect] | Matching files: none [files-changed/files-changed/detect] ❓ ::endgroup:: [files-changed/files-changed/detect] | ::endgroup:: [files-changed/files-changed/detect] ❓ ::group::Filter docs = false [files-changed/files-changed/detect] | ::group::Filter docs = false [files-changed/files-changed/detect] | Matching files: none [files-changed/files-changed/detect] ❓ ::endgroup:: [files-changed/files-changed/detect] | ::endgroup:: [files-changed/files-changed/detect] ❓ ::group::Filter actions = false [files-changed/files-changed/detect] | ::group::Filter actions = false [files-changed/files-changed/detect] | Matching files: none [files-changed/files-changed/detect] ❓ ::endgroup:: [files-changed/files-changed/detect] | ::endgroup:: [files-changed/files-changed/detect] ❓ ::group::Filter templates = false [files-changed/files-changed/detect] | ::group::Filter templates = false [files-changed/files-changed/detect] | Matching files: none [files-changed/files-changed/detect] ❓ ::endgroup:: [files-changed/files-changed/detect] | ::endgroup:: [files-changed/files-changed/detect] ❓ ::group::Filter docker = false [files-changed/files-changed/detect] | ::group::Filter docker = false [files-changed/files-changed/detect] | Matching files: none [files-changed/files-changed/detect] ❓ ::endgroup:: [files-changed/files-changed/detect] | ::endgroup:: [files-changed/files-changed/detect] ❓ ::group::Filter swagger = false [files-changed/files-changed/detect] | ::group::Filter swagger = false [files-changed/files-changed/detect] | Matching files: none [files-changed/files-changed/detect] ❓ ::endgroup:: [files-changed/files-changed/detect] | ::endgroup:: [files-changed/files-changed/detect] | Changes output set to [] [files-changed/files-changed/detect] ✅ Success - Main dorny/paths-filter@v2 [files-changed/files-changed/detect] ⚙ ::set-output:: backend_count=0 [files-changed/files-changed/detect] ⚙ ::set-output:: frontend=false [files-changed/files-changed/detect] ⚙ ::set-output:: actions_count=0 [files-changed/files-changed/detect] ⚙ ::set-output:: swagger=false [files-changed/files-changed/detect] ⚙ ::set-output:: swagger_count=0 [files-changed/files-changed/detect] ⚙ ::set-output:: changes=[] [files-changed/files-changed/detect] ⚙ ::set-output:: docs_count=0 [files-changed/files-changed/detect] ⚙ ::set-output:: actions=false [files-changed/files-changed/detect] ⚙ ::set-output:: docs=false [files-changed/files-changed/detect] ⚙ ::set-output:: templates=false [files-changed/files-changed/detect] ⚙ ::set-output:: templates_count=0 [files-changed/files-changed/detect] ⚙ ::set-output:: docker=false [files-changed/files-changed/detect] ⚙ ::set-output:: backend=false [files-changed/files-changed/detect] ⚙ ::set-output:: frontend_count=0 [files-changed/files-changed/detect] ⚙ ::set-output:: docker_count=0 [files-changed/files-changed/detect] Cleaning up services for job detect time="2023-08-22T01:04:32Z" level=info msg="Parallel tasks (0) below minimum, setting to 1" [files-changed/files-changed/detect] Cleaning up container for job detect [files-changed/files-changed/detect] Cleaning up network for job detect, and network name is: GITEA-ACTIONS-TASK-pull-request_WORKFLOW-files-changed_JOB-detect-network [files-changed/files-changed/detect] 🏁 Job succeeded

looks only when the base is HEAD it will detect on HEAD directly.
image

@silverwind
Copy link
Member

silverwind commented Aug 22, 2023

Hmm, the problem with base: HEAD is that if you have commited changes on the branch, it would incorrectly use the last commit on the branch.

What we want is a diff between PR target branch and current working tree including any potential uncomitted changes, e.g. the output of git diff <target-branch>, not git diff HEAD. The module seems to diff with ref..head, but as far as I know, working tree has no commit-ish reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants