Skip to content

Commit b7bc2b4

Browse files
committed
monitor: add support for Forgejo Actions
1 parent 520a367 commit b7bc2b4

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GITHUB_TOKEN=gho_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1+
GITHUB_OR_FORGEJO_TOKEN=gho_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
22
LIBVIRT_DEFAULT_URI=qemu:///system
33

44
# Accept requests with this API token only.

monitor.toml.example

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ listen_on = ["::1", "192.168.100.1"]
44
# Prepend this to any internal URL in our own responses. Must end with trailing slash.
55
external_base_url = "http://[::1]:8000/"
66

7-
# GitHub Actions runner scope (`/repos/<owner>/<repo>` or `/orgs/<owner>`).
8-
github_api_scope = "/repos/delan/servo"
7+
# GitHub Actions runner scope, as a full URL including the domain of the forge. For example:
8+
# - `https://api.github.com/repos/<owner>/<repo>`
9+
# - `https://api.github.com/orgs/<org>`
10+
# - `https://codeberg.org/api/v1/repos/<owner>/<repo>`
11+
# - `https://codeberg.org/api/v1/orgs/<org>`
12+
# - `https://codeberg.org/api/v1/user`
13+
github_api_scope_url = "https://api.github.com/repos/delan/servo"
14+
github_api_is_forgejo = false
915

1016
# For tokenless runner select, qualified repos must start with this prefix.
1117
allowed_qualified_repo_prefix = "delan/"

monitor/settings/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub static TOML: LazyLock<Toml> = LazyLock::new(|| {
5353

5454
#[derive(Default)]
5555
pub struct Dotenv {
56-
// GITHUB_TOKEN not used
56+
pub github_or_forgejo_token: String,
5757
// LIBVIRT_DEFAULT_URI not used
5858
pub monitor_api_token_raw_value: String,
5959
pub monitor_api_token_authorization_value: String,
@@ -64,7 +64,8 @@ pub struct Dotenv {
6464
pub struct Toml {
6565
pub listen_on: Vec<String>,
6666
pub external_base_url: String,
67-
pub github_api_scope: String,
67+
pub github_api_scope_url: String,
68+
pub github_api_is_forgejo: bool,
6869
pub allowed_qualified_repo_prefix: String,
6970
pub github_api_suffix: String,
7071
monitor_poll_interval: u64,
@@ -94,6 +95,7 @@ impl Dotenv {
9495
pub fn load() -> Self {
9596
let monitor_api_token = env_string("SERVO_CI_MONITOR_API_TOKEN");
9697
let result = Self {
98+
github_or_forgejo_token: env_string("GITHUB_OR_FORGEJO_TOKEN"),
9799
monitor_api_token_raw_value: monitor_api_token.clone(),
98100
monitor_api_token_authorization_value: Self::monitor_api_token_authorization_value(
99101
&monitor_api_token,

monitor/src/github.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<Response: Clone + Debug> Cache<Response> {
107107
}
108108

109109
fn list_registered_runners() -> eyre::Result<Vec<ApiRunner>> {
110-
let github_api_scope = &TOML.github_api_scope;
110+
let github_api_scope = &TOML.github_api_scope_url;
111111
let result = run_fun!(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28"
112112
"$github_api_scope/actions/runners" --paginate -q ".runners[]"
113113
| jq -s .)?;
@@ -126,7 +126,7 @@ pub fn list_registered_runners_for_host() -> eyre::Result<Vec<ApiRunner>> {
126126

127127
pub fn register_runner(runner_name: &str, label: &str, work_folder: &str) -> eyre::Result<String> {
128128
let github_api_suffix = &TOML.github_api_suffix;
129-
let github_api_scope = &TOML.github_api_scope;
129+
let github_api_scope = &TOML.github_api_scope_url;
130130
let result = run_fun!(gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28"
131131
"$github_api_scope/actions/runners/generate-jitconfig"
132132
-f "name=$runner_name@$github_api_suffix" -F "runner_group_id=1" -f "work_folder=$work_folder"
@@ -136,7 +136,7 @@ pub fn register_runner(runner_name: &str, label: &str, work_folder: &str) -> eyr
136136
}
137137

138138
pub fn unregister_runner(id: usize) -> eyre::Result<()> {
139-
let github_api_scope = &TOML.github_api_scope;
139+
let github_api_scope = &TOML.github_api_scope_url;
140140
run_cmd!(gh api --method DELETE -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28"
141141
"$github_api_scope/actions/runners/$id")?;
142142

@@ -149,7 +149,7 @@ pub fn reserve_runner(
149149
reserved_since: SystemTime,
150150
reserved_by: &str,
151151
) -> eyre::Result<()> {
152-
let github_api_scope = &TOML.github_api_scope;
152+
let github_api_scope = &TOML.github_api_scope_url;
153153
let reserved_since = reserved_since.duration_since(UNIX_EPOCH)?.as_secs();
154154
run_cmd!(gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28"
155155
"$github_api_scope/actions/runners/$id/labels"

0 commit comments

Comments
 (0)