fix: don't prepend server URL with https:// if it's an empty string #1083

Merged
earl-warren merged 4 commits from drewcassidy/runner:empty-server-url-fix into main 2025-10-12 08:53:46 +00:00
Contributor

An attempt to address #1074 in a way that makes everyone happy

Right now, any server URL that doesnt start with http:// or https:// automatically gets https:// prepended to it. When no instance is set while running forgejo-runner exec this results in the {FORGEJO,GITHUB}_SERVER_URL environment variables being set to simply "https://". Any action using the GitHub actions toolkit chokes on this as an invalid URL and fails the run with a nondescript error. This PR instead leaves empty strings alone, which the actions toolkit seems much happier with

Alternate fixes:

  • default the --forgejo-instance flag to a valid but unresolved url like 'http://example.com' so the actions don't crash
  • don't set the environment variables at all when the server URL is an empty string. This causes the actions toolkit to assume GitHub.com as a fallback
  • bug fixes
    • PR: fix: don't prepend server URL with https:// if it's an empty string
An attempt to address #1074 in a way that makes everyone happy Right now, any server URL that doesnt start with `http://` or `https://` automatically gets `https://` prepended to it. When no instance is set while running `forgejo-runner exec` this results in the `{FORGEJO,GITHUB}_SERVER_URL` environment variables being set to simply "https://". Any action using the GitHub actions toolkit chokes on this as an invalid URL and fails the run with a nondescript error. This PR instead leaves empty strings alone, which the actions toolkit seems much happier with Alternate fixes: * default the `--forgejo-instance` flag to a valid but unresolved url like 'http://example.com' so the actions don't crash * don't set the environment variables at all when the server URL is an empty string. This causes the actions toolkit to assume GitHub.com as a fallback <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1083): <!--number 1083 --><!--line 0 --><!--description Zml4OiBkb24ndCBwcmVwZW5kIHNlcnZlciBVUkwgd2l0aCBodHRwczovLyBpZiBpdCdzIGFuIGVtcHR5IHN0cmluZw==-->fix: don't prepend server URL with https:// if it's an empty string<!--description--> <!--end release-notes-assistant-->
Don't prepend server URL if its an empty string
All checks were successful
checks / validate pre-commit-hooks file (pull_request) Successful in 50s
checks / validate mocks (pull_request) Successful in 1m9s
checks / build and test (pull_request) Successful in 1m20s
checks / runner exec tests (pull_request) Successful in 42s
checks / runner integration tests (pull_request) Successful in 7m9s
checks / integration tests (pull_request) Successful in 14m1s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
5163d401dc
Instead of getting the URL "https://" which causes some actions to fail, they will now get the empty string if no instance is set (such as when running `exec`). Some github.com/actions actions such as cache fail with cryptic errors with an invalid URL
Owner

This change looks good to me. Could you please add an automated test to the sibling file run_context_test.go which covers the expected behaviour?

This change looks good to me. Could you please add an automated test to the sibling file `run_context_test.go` which covers the expected behaviour?
earl-warren changed title from Fix: Don't prepend server URL with https:// if its an empty string to fix: Don't prepend server URL with https:// if its an empty string 2025-10-12 06:43:33 +00:00
Add tests
Some checks failed
checks / build and test (pull_request) Failing after 58s
checks / validate mocks (pull_request) Failing after 53s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
checks / validate pre-commit-hooks file (pull_request) Successful in 36s
checks / runner exec tests (pull_request) Has been skipped
checks / runner integration tests (pull_request) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
Integration tests for the release process / release-simulation (pull_request) Successful in 5m15s
checks / integration tests (pull_request) Successful in 12m45s
41f3020420
drewcassidy changed title from fix: Don't prepend server URL with https:// if its an empty string to fix: Don't prepend server URL with https:// if it's an empty string 2025-10-12 06:55:01 +00:00
@ -1362,4 +1356,0 @@
set("SERVER_URL", instance)
set("API_URL", instance+"/api/v1")
}
Author
Contributor

I removed this since getGithubContext is doing the exact same transformation (twice...) and withGithubEnv is always run with rc.getGithubContext

I removed this since getGithubContext is doing the exact same transformation (twice...) and withGithubEnv is always run with rc.getGithubContext
Contributor

can you explain with references to code why this is redundant? I think you are correct but it would help me make sure there is not a weird situation where this is actually doing something different 🙏

can you explain with references to code why this is redundant? I think you are correct but it would help me make sure there is not a weird situation where this is actually doing something different 🙏
Author
Contributor
The two usages of `withGithubEnv` are https://code.forgejo.org/drewcassidy/runner/src/commit/1ef1b8323b2d546382387cc506f04c3e98ab246d/act/runner/action.go#L256 and https://code.forgejo.org/drewcassidy/runner/src/commit/1ef1b8323b2d546382387cc506f04c3e98ab246d/act/runner/step.go#L268 All implementations of `step.getGithubContext` ultimately call `rc.getGithubContext` https://code.forgejo.org/drewcassidy/runner/src/commit/1ef1b8323b2d546382387cc506f04c3e98ab246d/act/runner/step_action_local.go#L96 https://code.forgejo.org/drewcassidy/runner/src/commit/1ef1b8323b2d546382387cc506f04c3e98ab246d/act/runner/step_action_remote.go#L195 https://code.forgejo.org/drewcassidy/runner/src/commit/1ef1b8323b2d546382387cc506f04c3e98ab246d/act/runner/step_docker.go#L43 https://code.forgejo.org/drewcassidy/runner/src/commit/1ef1b8323b2d546382387cc506f04c3e98ab246d/act/runner/step_run.go#L58 Plus it just makes more sense for the context variables to get the same treatment as the environment variables
Contributor

Crystal clear. Thanks for making it easy for me to follow your footsteps 🙏

Crystal clear. Thanks for making it easy for me to follow your footsteps 🙏
earl-warren marked this conversation as resolved
Make the linter happy
All checks were successful
checks / validate mocks (pull_request) Successful in 57s
checks / validate pre-commit-hooks file (pull_request) Successful in 37s
checks / build and test (pull_request) Successful in 3m24s
checks / runner exec tests (pull_request) Successful in 32s
Integration tests for the release process / release-simulation (pull_request) Successful in 5m7s
checks / runner integration tests (pull_request) Successful in 5m36s
checks / integration tests (pull_request) Successful in 11m35s
issue-labels / release-notes (pull_request_target) Successful in 18s
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Successful in 6s
cascade / forgejo (pull_request_target) Successful in 2m38s
1ef1b8323b
Contributor

cascading-pr updated at actions/setup-forgejo#720

cascading-pr updated at https://code.forgejo.org/actions/setup-forgejo/pulls/720
Contributor

@drewcassidy set the run-end-to-end-test for triggering additional tests at https://code.forgejo.org/forgejo/end-to-end/src/branch/main/actions

@drewcassidy set the `run-end-to-end-test` for triggering additional tests at https://code.forgejo.org/forgejo/end-to-end/src/branch/main/actions
earl-warren changed title from fix: Don't prepend server URL with https:// if it's an empty string to fix: don't prepend server URL with https:// if it's an empty string 2025-10-12 08:52:58 +00:00
earl-warren deleted branch empty-server-url-fix 2025-10-12 08:53:47 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
forgejo/runner!1083
No description provided.