1
0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2026-10-29 05:52:57 +03:00

45 Commits

Author SHA1 Message Date
Shane Creighton-Young
61e691e4de feat: efficient actions repo fetching (#1722)
In testing of 5 popular action repos, this change uses 100x less disk space for the actions repo cache and makes initial repo cloning 12x faster. It does this by only fetching 1 commit and 0-1 refs from the remote whereas current `main` code unconditionally fetches all refs including tags, branches and the full commit history associated with each ref and any other reachable objects.

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1722
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.code.forgejo.org>
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
2026-09-11 21:35:47 +00:00
Mathieu Fenniak
d4db4179a9 fix: don't run host-based executor & LXC executor subcommands in a TTY (#1692)
All LXC and host-based commands were being unconditionally run with a pty attached.  As Forgejo Action's log viewer is not a terminal emulator, and it is not capable of supporting most terminal control output, this PR removes that implementation choice.  This brings consistency with docker-based execution, where the container may optionally be connected to a tty, but the command execution is not (when using `daemon` mode).

The accurate state to describe Forgejo Runner's output is that it is not a terminal, but that it does support a subset of ANSI codes such as colour selection (FG & BG), bold, faint, italic, underline, and hyperlinks.  Unfortunately there is no way to communicate that subset to a program in a standardized way -- setting a tty is sometimes used as a signal for such, but it's a near-miss in communicating that intent.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1692): <!--number 1692 --><!--line 0 --><!--description Zml4OiBkb24ndCBydW4gaG9zdC1iYXNlZCBleGVjdXRvciAmIExYQyBleGVjdXRvciBzdWJjb21tYW5kcyBpbiBhIFRUWQ==-->fix: don't run host-based executor & LXC executor subcommands in a TTY<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1692
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.code.forgejo.org>
2026-08-21 20:23:55 +00:00
Mathieu Fenniak
1a633ad513 chore: prepare for runner v13 release (#1645)
Global search and replace of `runner/v12` for `runner/v13`.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1645): <!--number 1645 --><!--line 0 --><!--description Y2hvcmU6IHByZXBhcmUgZm9yIHJ1bm5lciB2MTMgcmVsZWFzZQ==-->chore: prepare for runner v13 release<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1645
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.code.forgejo.org>
2026-08-03 15:55:53 +00:00
Mathieu Fenniak
b5a3bf90d1 fix: prevent commit impersonation via refs/replace/* during action checkout (#1635)
Prevent the usage of `git replace` to create a ref that shadows another commit, similar to previous fixes for tags and branches.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1635): <!--number 1635 --><!--line 0 --><!--description Zml4OiBwcmV2ZW50IGNvbW1pdCBpbXBlcnNvbmF0aW9uIHZpYSBgcmVmcy9yZXBsYWNlLypgIGR1cmluZyBhY3Rpb24gY2hlY2tvdXQ=-->fix: prevent commit impersonation via `refs/replace/*` during action checkout<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1635
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.code.forgejo.org>
2026-07-19 20:46:56 +00:00
Mathieu Fenniak
2736a4eff8 fix: run git subprocesses in a process group (#1623)
git subprocesses which the runner spawns were not being placed into a process group, and were not being terminated in a process group, in the event that a job's context was cancelled.  This could allow git subprocesses to be left as zombies when git was cancelled by the runner.

This PR fixes the git subprocess management to use the same cross-platform system developed for the host-based executor.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1623): <!--number 1623 --><!--line 0 --><!--description Zml4OiBydW4gZ2l0IHN1YnByb2Nlc3NlcyBpbiBhIHByb2Nlc3MgZ3JvdXA=-->fix: run git subprocesses in a process group<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1623
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.code.forgejo.org>
2026-07-14 16:12:44 +00:00
Andreas Ahlenstorf
9a617b497b test: use flags instead of env variables for skipping tests (#1591)
https://code.forgejo.org/forgejo/runner/pulls/1585 introduced the environment variable `TEST_FEATURES` for switching tests related to particular feature on and off. For example, with `TEST_FEATURES=""`, tests that require Docker would be skipped. Unfortunately, that technique has multiple problems. Environment variables might not be passed on to child processes without it being clearly visible. Also, the usage differs by platform. On top of that, informational messages that are only related to testing were printed by the release binary.

Instead of the environment variable `TEST_FEATURES`, the command line flag `-features` is introduced:

```
$  go test ./... -args -features "docker,lxc"
```

That runs all tests that require the presence of Docker and LXC. It is also the default.

If tests that require Docker should be skipped, run:

```
$  go test ./... -args -features "lxc"
```

To exclude all tests that require the presence of a particular feature, run:

```
$  go test ./... -args -features "-"
```

At the moment, `-features` cannot be controlled when using make targets. That means that `make integration-test` runs all tests that require Docker or LXC.

Supersedes  https://code.forgejo.org/forgejo/runner/pulls/1588.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1591): <!--number 1591 --><!--line 0 --><!--description dGVzdDogdXNlIGZsYWdzIGluc3RlYWQgb2YgZW52IHZhcmlhYmxlcyBmb3Igc2tpcHBpbmcgdGVzdHM=-->test: use flags instead of env variables for skipping tests<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1591
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
2026-07-05 22:26:52 +00:00
dsonck
9eb2ed865c fix: use ^{commit} to actually let rev-parse resolve to the commit (#1476)
This resolves a false positive likely introduced after: #1465

Closes: #1475

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1476): <!--number 1476 --><!--line 0 --><!--description Zml4OiB1c2UgYF57Y29tbWl0fWAgdG8gYWN0dWFsbHkgbGV0IGByZXYtcGFyc2VgIHJlc29sdmUgdG8gdGhlIGNvbW1pdA==-->fix: use `^{commit}` to actually let `rev-parse` resolve to the commit<!--description-->
<!--end release-notes-assistant-->

Co-authored-by: Daniel Sonck <daniel@sonck.nl>
Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1476
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: dsonck <dsonck@noreply.code.forgejo.org>
Co-committed-by: dsonck <dsonck@noreply.code.forgejo.org>
2026-04-06 17:20:18 +00:00
Mathieu Fenniak
5900b0ba5f fix: protect against tags & branches that look like pinned SHAs but are not (#1465)
Adds two tests that verify the Runner's action checkout operations are not affected negatively by branches or tags that look exactly like commit IDs:

- "Shadowing" an existing commit by adding a tag with the commit ID as the name, redirecting to another commit.
- Removing the original commit and adding a tag with the commit ID as the name, redirecting to another commit.

Thanks to Matthew Donoughe <mdonoughe@pm.me> for reporting the risk to security@forgejo.org.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1465): <!--number 1465 --><!--line 0 --><!--description Zml4OiBwcm90ZWN0IGFnYWluc3QgdGFncyAmIGJyYW5jaGVzIHRoYXQgbG9vayBsaWtlIHBpbm5lZCBTSEFzIGJ1dCBhcmUgbm90-->fix: protect against tags & branches that look like pinned SHAs but are not<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1465
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.code.forgejo.org>
Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
2026-03-31 00:27:13 +00:00
Crown0815
68bbce26ca Fix issues with tests on Windows (#1433)
Most issues were again due to incorrect path handling.
In `git.go` I chose an alternative authorization scheme which was simpler and avoids interaction with the Git Credential Manager on Windows.

I introduced the `github.com/powerman/fileuri` package which made the conversion from paths to URLs significantly easier for Windows.
I came across it in [this discussion](https://github.com/golang/go/issues/32456).

One decision I made was that env-files are expected to be given in UNIX style even when on Windows. This may be worth discussing.

Please let me know if any changes shall be revised.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1433): <!--number 1433 --><!--line 0 --><!--description Rml4IGlzc3VlcyB3aXRoIHRlc3RzIG9uIFdpbmRvd3M=-->Fix issues with tests on Windows<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1433
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.code.forgejo.org>
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Crown0815 <felix.kroener@gmx.de>
Co-committed-by: Crown0815 <felix.kroener@gmx.de>
2026-03-16 17:11:51 +00:00
Andreas Ahlenstorf
a21178b533 fix: only skip fetching when a commit exists locally (#1293)
When attempting to update a clone of an action or a reusable workflow with a commit reference, Forgejo Runner would erroneously not fetch the remote because it believed that commit were already present. That leads to an error:

```
runner(version:v12.5.2) received task 2 of job test, be triggered by event: push
workflow prepared
evaluating expression 'success()'
expression 'success()' evaluated to 'true'
  git -C /tmp/tmp.K9MTg4Hvs0/.cache/act/4f/03a001f96fcf7afd5f55aed90c7de6ae304b7f800980f5e3f6d414a38e7ae7 remote get-url origin
  git -C /tmp/tmp.K9MTg4Hvs0/.cache/act/4f/03a001f96fcf7afd5f55aed90c7de6ae304b7f800980f5e3f6d414a38e7ae7 rev-parse c58510e7c779846cb5f0801a159cbf91d971026c
Found revision: c58510e7c779846cb5f0801a159cbf91d971026c
  ☁️  git fetch 'http://192.168.124.88:3000/root/example-private-workflow-call' skipped; ref=c58510e7c779846cb5f0801a159cbf91d971026c cached
  git -C /tmp/tmp.K9MTg4Hvs0/.cache/act/4f/03a001f96fcf7afd5f55aed90c7de6ae304b7f800980f5e3f6d414a38e7ae7 rev-parse c58510e7c779846cb5f0801a159cbf91d971026c
Found revision: c58510e7c779846cb5f0801a159cbf91d971026c
  git worktree create for ref=c58510e7c779846cb5f0801a159cbf91d971026c (sha=c58510e7c779846cb5f0801a159cbf91d971026c) to /tmp/tmp.K9MTg4Hvs0/.cache/act/66/f8d01b29c88af989524f5b0324dcf963a4c0c9f8e118bc2795cd711a1a853d
  git -C /tmp/tmp.K9MTg4Hvs0/.cache/act/4f/03a001f96fcf7afd5f55aed90c7de6ae304b7f800980f5e3f6d414a38e7ae7 worktree add -f --end-of-options /tmp/tmp.K9MTg4Hvs0/.cache/act/66/f8d01b29c88af989524f5b0324dcf963a4c0c9f8e118bc2795cd711a1a853d c58510e7c779846cb5f0801a159cbf91d971026c
git worktree add error: fatal: invalid reference: c58510e7c779846cb5f0801a159cbf91d971026c: exit status 128
```

The reason is that `git rev-parse` skips the existence check if a full commit hash is supplied.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1293): <!--number 1293 --><!--line 0 --><!--description Zml4OiBvbmx5IHNraXAgZmV0Y2hpbmcgd2hlbiBhIGNvbW1pdCBleGlzdHMgbG9jYWxseQ==-->fix: only skip fetching when a commit exists locally<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1293
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
Co-committed-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
2026-01-15 02:21:26 +00:00
Andreas Ahlenstorf
572bd0b50e chore: ensure all tests are run (#1261)
The Forgejo Runner Makefile only looks for tests in some directories. If someone adds a test in another place, they have to remember to update the Makefile. That is error-prone and easy to forget. Another problem is that integration tests are stored alongside short tests and not in a separate directory tree. That makes it hard to separate them.

In response to https://code.forgejo.org/forgejo/runner/pulls/1255#issuecomment-71897, all `go test` commands now scan the entire source tree for tests. All integration tests are skipped if `testing.Short()` is `true`. While `make test` runs only short tests, `make integration-test` now runs **all** tests, no matter whether they are short or not. Separating them would either require the introduction of [test suites](https://pkg.go.dev/github.com/stretchr/testify/suite) or moving them to a separate directory tree.

CI was restructured to reflect the changes. The build step no longer runs any tests because the integration test step will run all tests anyway. CI might run slightly longer than before because short tests and some integration tests that do not require a container runtime are now run twice with each Docker version instead of once.

Additional slow tests were identified and marked as slow by running `go test -json -short ./... | gotestsum tool slowest --threshold 200ms`. Some were reclassified after a manual review.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1261): <!--number 1261 --><!--line 0 --><!--description Y2hvcmU6IGVuc3VyZSBhbGwgdGVzdHMgYXJlIHJ1bg==-->chore: ensure all tests are run<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1261
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
Co-committed-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
2026-01-13 22:38:02 +00:00
Andreas Ahlenstorf
e123f729b7 fix: try to empty clone directory that is not empty (#1277)
When cloning an action or a workflow with `git`, the target directory might not be empty, for example, due to a failed cloning attempt. Because the target directory's name is derived from the repository's URL that is about to be cloned, it would be an unrecoverable situation and would require human intervention to resolve it. To reduce the likelihood of such a situation, Forgejo Runner will try to delete the directory before cloning the repository containing the action or workflow.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1277): <!--number 1277 --><!--line 0 --><!--description Zml4OiB0cnkgdG8gZW1wdHkgY2xvbmUgZGlyZWN0b3J5IHRoYXQgaXMgbm90IGVtcHR5-->fix: try to empty clone directory that is not empty<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1277
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
Co-committed-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
2026-01-13 15:51:23 +00:00
Eugene F.
f611819d2e fix: private repository cloning with authentication token (#1268)
After patch that replaced go-git with shell git commands, the runner fails to clone private repositories with error:

```
fatal: could not read Username for 'https://...': No such device or address
```

Root cause:

The credential-store helper expects credentials in URL format (`https://user:token@host/path`), but the current implementation writes only the raw token to the file, causing git to prompt for username interactively.

Solution:
- Format credentials as proper URL with embedded token: `https://x-access-token:TOKEN@host/path`
- Add `credential.useHttpPath=true` to respect repository paths in credential matching
- Parse remote URL to extract host and construct valid credential-store entry

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1268): <!--number 1268 --><!--line 0 --><!--description Zml4OiBwcml2YXRlIHJlcG9zaXRvcnkgY2xvbmluZyB3aXRoIGF1dGhlbnRpY2F0aW9uIHRva2Vu-->fix: private repository cloning with authentication token<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1268
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Eugene F. <grand@codabra.io>
Co-committed-by: Eugene F. <grand@codabra.io>
2026-01-12 16:30:24 +00:00
Andreas Ahlenstorf
a5a28e641b fix: clone actions with Git instead of go-git (#1255)
Enables cloning of actions hosted on Git repositories that use SHA-256.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1255): <!--number 1255 --><!--line 0 --><!--description Zml4OiBjbG9uZSBhY3Rpb25zIHdpdGggR2l0IGluc3RlYWQgb2YgZ28tZ2l0-->fix: clone actions with Git instead of go-git<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1255
Reviewed-by: limiting-factor <limiting-factor@noreply.code.forgejo.org>
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
Co-committed-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
2026-01-08 22:37:31 +00:00
Andreas Ahlenstorf
f9109c4f94 fix: stop creation of branch called HEAD during fetch (#1250)
When cloning a repository or updating the existing clone, Forgejo Runner performs a fetch. The ref spec `HEAD:refs/heads/HEAD` motivates go-git to create a local branch called `HEAD`. Consequently, `HEAD` becomes ambiguous and `git` rightfully complains about it (`warning: refname 'HEAD' is ambiguous.`).

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1250): <!--number 1250 --><!--line 0 --><!--description Zml4OiBzdG9wIGNyZWF0aW9uIG9mIGJyYW5jaCBjYWxsZWQgSEVBRCBkdXJpbmcgZmV0Y2g=-->fix: stop creation of branch called HEAD during fetch<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1250
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Reviewed-by: limiting-factor <limiting-factor@noreply.code.forgejo.org>
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
Co-committed-by: Andreas Ahlenstorf <andreas@ahlenstorf.ch>
2026-01-03 04:25:33 +00:00
Crown0815
0883b4a21d Fix test failure on Windows due to more strict file lock handling (#1183)
It appears that Unix is not as strict with File-Locks when deleting
files, but Windows complains about files still being locked when
`t.TempDir()` attempts to clean them up.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1183): <!--number 1183 --><!--line 0 --><!--description Rml4IHRlc3QgZmFpbHVyZSBvbiBXaW5kb3dzIGR1ZSB0byBtb3JlIHN0cmljdCBmaWxlIGxvY2sgaGFuZGxpbmc=-->Fix test failure on Windows due to more strict file lock handling<!--description-->
<!--end release-notes-assistant-->

Co-authored-by: Felix Kröner <felix.kroener@bruker.com>
Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1183
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Crown0815 <crown0815@noreply.code.forgejo.org>
Co-committed-by: Crown0815 <crown0815@noreply.code.forgejo.org>
2025-11-24 15:49:12 +00:00
limiting-factor
c196605572 chore: bump version to v12 (#1176)
<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1176): <!--number 1176 --><!--line 0 --><!--description Y2hvcmU6IGJ1bXAgdmVyc2lvbiB0byB2MTI=-->chore: bump version to v12<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1176
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: limiting-factor <limiting-factor@posteo.com>
Co-committed-by: limiting-factor <limiting-factor@posteo.com>
2025-11-22 16:25:20 +00:00
Mathieu Fenniak
8125975bc3 fix: 'failed to read action' errors when using relative workdir_parent (#1175)
When `workdir_parent` is a relative path, actions were failing with error:
```
⚙️ [runner]: failed to read action 'Checkout', no files found after reading paths: action.yml, action.yaml, Dockerfile
```

The cause of this is that worktree creation using `git -C relative/repodir worktree add relative/worktree` would actually create the `relative/worktree` inside the repo.  It seems that `git -C` to operate on a repo changes the working directory into that repo and evaluates relative paths from there.

Fixed by converting `workdir_parent` into an absolute path after the config file is read, and adding an error in the git operations if a relative path somehow makes its way through.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1175): <!--number 1175 --><!--line 0 --><!--description Zml4OiAnZmFpbGVkIHRvIHJlYWQgYWN0aW9uJyBlcnJvcnMgd2hlbiB1c2luZyByZWxhdGl2ZSB3b3JrZGlyX3BhcmVudA==-->fix: 'failed to read action' errors when using relative workdir_parent<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1175
Reviewed-by: limiting-factor <limiting-factor@noreply.code.forgejo.org>
Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
2025-11-22 13:17:16 +00:00
Mathieu Fenniak
97bff5d3af feat: use git work trees for remote git actions & workflows (#1162)
**Breaking:** forgejo-runner now requires access to `git` on its PATH in order to create efficient work trees for execution of remote git actions or workflows, such as `uses: actions/checkout`.

---

When you use a remote step action or a remote composite action, forgejo-runner will perform a clone of the remote repo into a temporary directory.  For steps, the temporary directory will be named with a SHA of the `uses: ...` step text; for reusable workflows, it will be named with a combination of remote org,repo@ref.  These are stored in `~/.cache/act` (or the `workflow_parent`, if overridden in the config file).

This design has these problems:
- Whenever the contents of `uses: ...` changes, an independent clone is performed as it causes a different unique directory name.  For example, when changing from `uses: actions/checkout@v4` to `...v5`, the existing cached repo that contains `v4` is not reused in any way; a new cache is made for `@v5`.
- The contents of the temp directories are somewhat cleaned up by a `git reset --HARD` between uses, but non-tracked files could be left in the directory between runs polluting from one run to another; there's no `git clean -fxd` performed.
- The directory could be used concurrently by multiple running actions.  If the git reference changes (eg. it is a reference to a tag, and it has changed in the second run), or if the workflow writes any content to the directory, it will pollute across action runs.
- Probably due to bugs identified in the past with performing operations on these shared repo directories, only a single clone operation can be performed by `forgejo-runner` at once:
    - A mutex is used that permits a forgejo-runner to only clone one repo at a time -- c1fe7a26a3/act/common/git/git.go (L30)
    - A redundant mutex is used during reusable workflow clones to permit only one clone at a time -- c1fe7a26a3/act/runner/reusable_workflow.go (L87-L96)
- **(Not resolved in this PR)**: All remote references are pulled during `git clone` of a remote, even if they aren't relevant to the reference being fetched.  (To be fixed in the future based upon this change.)

To address these issues, this PR proposes this design update:
- Based upon the remote URL without the reference, a single bare clone repo will be maintained.
- When a reference is to a branch, tag, or unidentified sha, a fetch will be performed on the bare repo to get the current sha for the reference.
- For each execution using the repo, a new independent work tree will be created from the bare repo.
- The work trees will be cleaned up at the end of execution; the bare repo will remain to be reused.
- Concurrency control will be ~~handed over to git, since it is capable of managing multiple fetches and work tree creations from a single bare repo~~ transitioned to a finer grained `MutexMap`, allowing higher concurrency but not taking any risks of go-git's [unclear concurrency guarantees](https://github.com/go-git/go-git/issues/773).

This will address the problems described above.  It does have a negative side-effect -- each running remote action will require creating a new work tree, increasing on-disk I/O where previously these might have been in-place already.  However, this is a trade-off against reducing total disk I/O and usage by sharing a single repo over multiple references to that repo; so long-term usage will likely be lower.

WIP: the core work is done and ready to be put through the test battery to see if any unexpected problems occur, which is why I opened this PR.  TODO:
- [x] Update the original repo to be a bare repo
- [x] Cleanup work trees after they are `Close()`'d
- [x] Seems like reference is slipping into the filepaths in `~/.cache/act` currently -- should be stripped
- [x] Pass through each commits to identify any needed automated testing revisions
- [x] Get all automated tests to pass
- [x] Perform manual testing as needed

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- features
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1162): <!--number 1162 --><!--line 0 --><!--description ZmVhdDogdXNlIGdpdCB3b3JrIHRyZWVzIGZvciByZW1vdGUgZ2l0IGFjdGlvbnMgJiB3b3JrZmxvd3M=-->feat: use git work trees for remote git actions & workflows<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1162
Reviewed-by: limiting-factor <limiting-factor@noreply.code.forgejo.org>
Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
2025-11-21 13:49:26 +00:00
Mathieu Fenniak
c1fe7a26a3 feat: skip fetching remote action repo when using full sha already fetched (#1160)
When a remote action is referenced by a full SHA (eg. `- uses: actions/checkout@08c6903cd8 # v5`) and the local cache already has that sha, then skip performing a `git fetch` on the remote.  Covered by new automated tests that also check tag updates work correctly (to ensure that `git fetch` *is* used in those cases).

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- features
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1160): <!--number 1160 --><!--line 0 --><!--description ZmVhdDogc2tpcCBmZXRjaGluZyByZW1vdGUgYWN0aW9uIHJlcG8gd2hlbiB1c2luZyBmdWxsIHNoYSBhbHJlYWR5IGZldGNoZWQ=-->feat: skip fetching remote action repo when using full sha already fetched<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1160
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
2025-11-17 18:22:38 +00:00
Mathieu Fenniak
fe9a61a03a fix: don't shortcut around the git reset, and remove other redundant code 2025-11-14 14:15:56 -07:00
Andrew Cassidy
7ab325cb0d only log about cloning if clone was actually run 2025-11-14 14:15:56 -07:00
Andrew Cassidy
2fee796138 fix indents 2025-11-14 14:15:56 -07:00
Andrew Cassidy
8aa6eb92cb Use git reset --hard instead of pull and checkout
Also use force fetch whatever that means
2025-11-14 14:15:56 -07:00
Andrew Cassidy
c80a40023c feat: disambiguate cloud emoji (#1076)
Many emoji technically have two forms, the colorful form and the monochrome text form. For some reason, on macOS, ☁️ defaults to the latter, which is also really tiny for some reason?. Adding the invisible emoji variant selector (U+FE0F) causes it to always render as the colorful full-width graphic

Before:

![Screenshot 2025-10-08 at 22.53.36](/attachments/beaeea4a-d355-4db6-9cca-2425a62b6ea9)

After:

![Screenshot 2025-10-08 at 22.53.14](/attachments/dd670d38-fed6-41dc-a0c2-421846bc26bd)

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1076): <!--number 1076 --><!--line 0 --><!--description ZGlzYW1iaWd1YXRlIGNsb3VkIGVtb2pp-->disambiguate cloud emoji<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1076
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Andrew Cassidy <drewcassidy@me.com>
Co-committed-by: Andrew Cassidy <drewcassidy@me.com>
2025-10-11 09:23:28 +00:00
Earl Warren
8a7f760d3c chore: bump version to v11 (#940)
the license change from MIT to GPLv3+ is a breaking change

Refs forgejo/runner#773

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/940): <!--number 940 --><!--line 0 --><!--description Y2hvcmU6IGJ1bXAgdmVyc2lvbiB0byB2MTE=-->chore: bump version to v11<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/940
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-09-05 07:29:38 +00:00
Michael Kriese
27f425987c chore: modernize code (#857)
Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/857
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
Reviewed-by: Gusted <gusted@noreply.code.forgejo.org>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-committed-by: Michael Kriese <michael.kriese@visualon.de>
2025-08-15 04:54:13 +00:00
Earl Warren
0520ff4e05 chore: use t.Context for tests, activate usetesting for lint + add t.TempDir and t.Chdir (#844)
<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/844): <!--number 844 --><!--line 0 --><!--description Y2hvcmU6IHVzZSB0LkNvbnRleHQgZm9yIHRlc3RzLCBhY3RpdmF0ZSB1c2V0ZXN0aW5nIGZvciBsaW50ICsgYWRkIHQuVGVtcERpciBhbmQgdC5DaGRpciBbc2tpcCBjYXNjYWRlXQ==-->chore: use t.Context for tests, activate usetesting for lint + add t.TempDir and t.Chdir [skip cascade]<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/844
Reviewed-by: Gusted <gusted@noreply.code.forgejo.org>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-08-11 13:21:42 +00:00
earl-warren
4f883e9707 fix: short sha has at least four digits (#820)
Refs https://github.com/nektos/act/pull/2540

---

Currently it is not very unlikly to have a false match for tag `0` with sha `0XXXXXXXXXXXXXXXXXXXXXXX`, 1 to 16

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 4dc67f6ba28f888328a2568bbcacf49e552650da)

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/820): <!--number 820 --><!--line 0 --><!--description Zml4OiBzaG9ydCBzaGEgaGFzIGF0IGxlYXN0IGZvdXIgZGlnaXRz-->fix: short sha has at least four digits<!--description-->
<!--end release-notes-assistant-->

Co-authored-by: ChristopherHX <christopher.homberger@web.de>
Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/820
Reviewed-by: Gusted <gusted@noreply.code.forgejo.org>
2025-08-07 21:04:09 +00:00
Earl Warren
ec99579451 chore: to allow the runner to be imported, v9 needs to be in the go module (#777)
It will be imported by Forgejo.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/777): <!--number 777 --><!--line 0 --><!--description Y2hvcmU6IHRvIGFsbG93IHRoZSBydW5uZXIgdG8gYmUgaW1wb3J0ZWQsIHY5IG5lZWRzIHRvIGJlIGluIHRoZSBnbyBtb2R1bGU=-->chore: to allow the runner to be imported, v9 needs to be in the go module<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/777
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-31 10:35:11 +00:00
Earl Warren
ebc7758c1f chore: s|github.com/nektos/act/pkg|code.forgejo.org/forgejo/runner/act| 2025-07-28 19:23:07 +02:00
Earl Warren
c377159121 chore: use the same .golangci.yml as the runner & gofumpt over gofmt (#206)
To prepare for a smooth merge in the runner codebase.

- run with --fix for gofumpt and golangci
- manual edits for
  - disabling useless package naming warning
  - rename variables that had underscore in their name
  - remove trailing else at the end of a few functions

Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/206
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 12:26:41 +00:00
achyrva
422e17bc27 [RDNF #10] Remove local action cache if remote has changed (#2284) (#142)
* fix: remove local cache if remote is changed
* test: TestCloneIfRequired

https://github.com/nektos/act/pull/2284

Co-authored-by: Jason Song <i@wolfogre.com>
Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/142
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
Co-authored-by: achyrva <achyrva@noreply.code.forgejo.org>
Co-committed-by: achyrva <achyrva@noreply.code.forgejo.org>
2025-06-09 10:16:45 +00:00
_
c455fb07f2 fix(git): add support for parsing weirder remote URLs 2025-03-31 23:45:06 -07:00
_
3f6addab2a fix(tests): explicitly set git-config user.name/user.email to avoid spurious test failures 2025-03-31 23:45:06 -07:00
Earl Warren
58966f5a8a chore(lint): fix lint errors
- upgrade to golangci-lint@v1.62.2
- make it renovate friendly
- remove most frequent lint check that are not of consequence (unused
  args, etc.)
- fix remaining lint errors
- add renovate custom manager to update the Makefile variable
2024-12-30 21:11:02 +00:00
Zettat123
90ce417f01 Support cloning remote actions from insecure Gitea instances (#92)
Related to https://github.com/go-gitea/gitea/issues/28693

Reviewed-on: https://gitea.com/gitea/act/pulls/92
Reviewed-by: Jason Song <i@wolfogre.com>
Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-committed-by: Zettat123 <zettat123@gmail.com>
2024-03-05 08:07:29 +00:00
TKaxv_7S
141b614c36 feat: support offline mode (#2128)
* Add: Actions Offline Mode

* Add: Actions Offline Mode

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2024-01-20 00:20:15 +00:00
Casey Lee
28c6da4522 chore: upgrade golangci-lint and address findings (#1904) 2023-07-10 17:12:12 -07:00
Jason Song
32b8839b68 chore: use new style octal (#1630)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2023-02-16 15:34:51 +00:00
Alexandre Lavigne
aeebe9f1d5 Feature/allow worktrees (#1530)
* Use go-git to find remote URL

* Use go-git package to resolve HEAD revision (commit sha1)

* Use go-git to find checked-out reference

* Remove unused functions
2023-01-19 06:29:23 +00:00
Eng Zer Jun
fef9bd3448 refactor: move from io/ioutil to io and os packages (#1417)
The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

[1]: https://golang.org/doc/go1.16#ioutil
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-10-29 17:15:38 +00:00
Alex Savchuk
658b6fdbf8 fix: support docker create arguments from container.options (#1022) (#1351)
* fix: support docker create arguments from container.options (#1022)

* fix processing of errors, add verbose logging, fix test

* disable linter for code copied from docker/cli

* fix all linter issues

* Add license info

* Add opts_test.go from docker/cli and required testdata

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-10-06 22:09:43 +00:00
Björn Brauer
ad6aeb1969 Improve logging (#1171)
* feat: use logger from context wherever possible

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* feat: add step/job id and results to json logs

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* test: value to be masked should not be hard-coded in the action

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* fix: replace values following ::add-mask:: in evaluated strings

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* feat: [DEBUG] identifier for debug logs to distinguish them

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* feat: replace logger with step logger

The container gets injected a job logger, but during the time that steps
are run, we want to use the step logger.
This commit wraps pre/main/post steps in an executor that replaces the
job logger with a step logger.

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* feat: add pre/post stage identifier fields to json log output

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* feat: add job/step result status to skipped steps/jobs

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-17 15:55:21 +00:00
R
bfa5723fda refactor: remove github.com/pkg/errors dependency (#1077)
* refactor: split out common/git

* refactor: move git options to separate func

* refactor: remove github.com/pkg/errors dependency

* fix(golangci-lint): forbid github.com/pkg/errors

* style: fix typo

* style: fix typo

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-10 21:16:42 +00:00