Compare commits

13 Commits

Author SHA1 Message Date
npease 9146d14bd1 test
ci / build (push) Failing after 10m10s
2023-11-07 05:26:43 +00:00
npease 17762e08b5 test
ci / build (push) Failing after 9s
2023-11-07 05:23:08 +00:00
npease a670e0c6db revert
ci / build (push) Failing after 1m3s
2023-11-07 05:14:12 +00:00
npease f77cfa26ce try
ci / build (push) Failing after 2s
2023-11-07 05:07:56 +00:00
npease 5831820a14 try
ci / build (push) Failing after 3s
2023-11-07 05:05:10 +00:00
npease 498cd40955 Try This
ci / build (push) Failing after 15s
2023-11-07 05:00:44 +00:00
npease fd121e288e try
build / coverage (push) Failing after 3s
build / build (push) Failing after 3s
build / publish (push) Has been skipped
2023-11-07 04:11:58 +00:00
npease c863e318e7 Try
build / linting (push) Failing after 11s
build / coverage (push) Failing after 3s
build / build (push) Failing after 3s
build / publish (push) Has been skipped
2023-11-07 04:10:51 +00:00
npease 579c495afb New workflow
build / linting (push) Has been cancelled
build / coverage (push) Has been cancelled
build / build (push) Has been cancelled
build / publish (push) Has been cancelled
2023-11-07 04:07:18 +00:00
npease c5ca27c958 Try Build 2023-11-07 04:03:34 +00:00
LAX18 ee924054b4 Add " to version for docker-compose compliance 2023-11-07 02:49:49 +00:00
Gergely Nagy b85bf9ae0d Fix the tests
Ironforge switched to using a different Forgejo API URL, update the
mocks to follow suit.

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
2023-09-30 23:26:20 +02:00
Gergely Nagy c70bcf427a Change the way we find the status & log
Rather than just looking at the very latest status, for the badge,
consider *all* of them. If they're all successful, then that's our end
state. If there's any that isn't, then the first non-successful state
will be ours.

For the logs, return the latest Forgejo Action log (if any). If there
aren't any Forgejo Action logs, return the latest log, whatever it may
be.

Fixes #1.

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
2023-09-30 22:57:17 +02:00
12 changed files with 131 additions and 343 deletions
-79
View File
@@ -1,79 +0,0 @@
name: build
on: [ push ]
jobs:
linting:
runs-on: nixos-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: bootstrap
uses: actions/nix/develop@main
- name: formatting
uses: actions/nix/develop@main
with:
run: cargo fmt --check
- name: clippy
uses: actions/nix/develop@main
with:
run: cargo clippy
coverage:
runs-on: nixos-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: bootstrap
uses: actions/nix/develop@main
- name: test & coverage
id: coverage
uses: actions/nix/develop@main
with:
run: |
cargo tarpaulin --tests --engine llvm --exclude-files src/main.rs | tee build.log
tail -n 1 build.log | sed -e 's/^/coverage=/' >>"${GITHUB_OUTPUT}"
- name: summary
run: |
echo ${{ steps.coverage.outputs.coverage }}
build:
runs-on: nixos-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: build
uses: actions/nix/build@main
with:
package: ironforge
- name: build the container image
uses: actions/nix/build@main
with:
package: container-image
- name: load the container image into docker
run: |
docker load <result
publish:
runs-on: nixos-latest
needs: [ linting, coverage, build ]
steps:
- name: login to the container registry
uses: https://code.forgejo.org/docker/login-action@v2
with:
registry: git.madhouse-project.org
username: algernon
password: ${{ secrets.DOCKER_PASSWORD }}
- name: publish
run: |
docker push git.madhouse-project.org/algernon/ironforge:latest
+30
View File
@@ -0,0 +1,30 @@
name: ci
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:latest
Generated
+2 -224
View File
@@ -8,7 +8,7 @@ version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
dependencies = [
"gimli 0.28.0",
"gimli",
]
[[package]]
@@ -221,43 +221,6 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
[[package]]
name = "c-gull"
version = "0.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44589b5130ab40d739906751b9066cc514e83b7f0c7df1e0484c96df34791b85"
dependencies = [
"c-scape",
"errno",
"libc",
"printf-compat",
"rustix",
"sync-resolve",
"tz-rs",
]
[[package]]
name = "c-scape"
version = "0.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f19eced9b8932f6d75223bc43263a7fbc92241ae2ff4e1325e893f0bc7f0e261"
dependencies = [
"errno",
"libc",
"libm",
"memoffset",
"origin",
"rand",
"rand_core",
"rand_pcg",
"realpath-ext",
"rustix",
"rustix-dlmalloc",
"rustix-futex-sync",
"rustix-openpty",
"unwinding",
]
[[package]]
name = "cc"
version = "1.0.83"
@@ -368,22 +331,6 @@ dependencies = [
"typenum",
]
[[package]]
name = "cstr_core"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd98742e4fdca832d40cab219dc2e3048de17d873248f83f17df47c1bea70956"
dependencies = [
"cty",
"memchr",
]
[[package]]
name = "cty"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
[[package]]
name = "digest"
version = "0.10.7"
@@ -400,12 +347,6 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "encoding_rs"
version = "0.8.33"
@@ -436,15 +377,6 @@ dependencies = [
"libc",
]
[[package]]
name = "eyra"
version = "0.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a271b0c7bd629bf6d0464c57b0e784c426581c283b2fcd18537c664c7956dcbf"
dependencies = [
"c-gull",
]
[[package]]
name = "fnv"
version = "1.0.7"
@@ -570,12 +502,6 @@ dependencies = [
"wasi",
]
[[package]]
name = "gimli"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
[[package]]
name = "gimli"
version = "0.28.0"
@@ -700,17 +626,6 @@ dependencies = [
"tokio-rustls",
]
[[package]]
name = "idna"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8"
dependencies = [
"matches",
"unicode-bidi",
"unicode-normalization",
]
[[package]]
name = "idna"
version = "0.4.0"
@@ -744,7 +659,6 @@ dependencies = [
"axum",
"clap",
"config",
"eyra",
"log",
"mockito",
"reqwest",
@@ -770,15 +684,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "itertools"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "1.0.9"
@@ -817,12 +722,6 @@ version = "0.2.148"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
[[package]]
name = "libm"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4"
[[package]]
name = "linked-hash-map"
version = "0.5.6"
@@ -860,12 +759,6 @@ dependencies = [
"regex-automata 0.1.10",
]
[[package]]
name = "matches"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
[[package]]
name = "matchit"
version = "0.7.2"
@@ -878,15 +771,6 @@ version = "2.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c"
[[package]]
name = "memoffset"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
dependencies = [
"autocfg",
]
[[package]]
name = "mime"
version = "0.3.17"
@@ -993,20 +877,6 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "origin"
version = "0.13.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad6f816ea4b0df9f8210ad29b206d856ffdb3d1093fdfc0210e8ca96cd2b2bc1"
dependencies = [
"bitflags 2.4.0",
"linux-raw-sys",
"memoffset",
"rustix",
"rustix-futex-sync",
"unwinding",
]
[[package]]
name = "overload"
version = "0.1.1"
@@ -1131,18 +1001,6 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "printf-compat"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b002af28ffe3d3d67202ae717810a28125a494d5396debc43de01ee136ac404"
dependencies = [
"bitflags 1.3.2",
"cstr_core",
"cty",
"itertools",
]
[[package]]
name = "proc-macro2"
version = "1.0.67"
@@ -1191,26 +1049,6 @@ dependencies = [
"getrandom",
]
[[package]]
name = "rand_pcg"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e"
dependencies = [
"rand_core",
]
[[package]]
name = "realpath-ext"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692f72862a0d532b44a0f4965fb10f17e7659eaedf24d2ce3c989ca778bd092f"
dependencies = [
"bitflags 1.3.2",
"errno",
"libc",
]
[[package]]
name = "redox_syscall"
version = "0.3.5"
@@ -1353,44 +1191,11 @@ checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f"
dependencies = [
"bitflags 2.4.0",
"errno",
"itoa",
"libc",
"linux-raw-sys",
"once_cell",
"windows-sys",
]
[[package]]
name = "rustix-dlmalloc"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "730c0a5fbe9885450abcfca57da8c5d5a886492d01aa1a78b782fc5ddb2c0931"
dependencies = [
"rustix",
"rustix-futex-sync",
]
[[package]]
name = "rustix-futex-sync"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "778811def1fc5ab594a0474b44ccbd02fe276e4a3f3551d005770108bdc92072"
dependencies = [
"lock_api",
"rustix",
]
[[package]]
name = "rustix-openpty"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a25c3aad9fc1424eb82c88087789a7d938e1829724f3e4043163baf0d13cfc12"
dependencies = [
"errno",
"libc",
"rustix",
]
[[package]]
name = "rustls"
version = "0.21.7"
@@ -1596,17 +1401,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "sync-resolve"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a89fa9e37fd57511c6c486c4e7a2f38c94a27c130347b4a310425074a4ad7a7"
dependencies = [
"idna 0.2.3",
"log",
"rand",
]
[[package]]
name = "sync_wrapper"
version = "0.1.2"
@@ -1856,12 +1650,6 @@ version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "tz-rs"
version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33851b15c848fad2cf4b105c6bb66eb9512b6f6c44a4b13f57c53c73c707e2b4"
[[package]]
name = "ucd-trie"
version = "0.1.6"
@@ -1904,16 +1692,6 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]]
name = "unwinding"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ee215fc0991fb587275819562685254302112d0b7c8d25e635655526c0ecdc6"
dependencies = [
"gimli 0.26.2",
"libc",
]
[[package]]
name = "url"
version = "2.4.1"
@@ -1921,7 +1699,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5"
dependencies = [
"form_urlencoded",
"idna 0.4.0",
"idna",
"percent-encoding",
"serde",
]
-1
View File
@@ -7,7 +7,6 @@ edition = "2021"
axum = "0.6.20"
clap = { version = "4", features = ["derive"] }
config = "0.13.3"
eyra = { version = "0.15.3" }
log = "0.4"
reqwest = { version = "0.11.20", default-features = false, features = ["rustls-tls", "json"] }
serde = { version = "1", features = ["derive"] }
+2 -2
View File
@@ -8,14 +8,14 @@ ironforge
[container:badge]: https://img.shields.io/badge/container-ironforge:latest-blue?style=for-the-badge
[container:url]: https://git.madhouse-project.org/algernon/-/packages/container/ironforge/latest
A lightweight bridge between Forgejo Actions and shields.io.
A lightweight bridge between Gitea Actions and shields.io.
## Usage
In `docker-compose-yaml`:
``` yaml
version: 3
version: "3"
services:
ironforge:
image: git.madhouse-project.org/algernon/ironforge:latest
-3
View File
@@ -1,3 +0,0 @@
fn main() {
println!("cargo:rustc-link-arg=-nostartfiles");
}
+1 -1
View File
@@ -15,7 +15,7 @@
let
inherit (nixpkgs) lib;
toolchain = pkgs:
(pkgs.rust-bin.nightly.latest.default.override {
(pkgs.rust-bin.stable.latest.default.override {
targets = [ "x86_64-unknown-linux-gnu" "x86_64-unknown-linux-musl" ];
});
ironforgeLambda = pkgs:
+46
View File
@@ -0,0 +1,46 @@
# This is a more or less default configuration for Ironforge.
# Unless noted otherwise, all settings here use the default values.
[server]
# The address and port to listen on.
#
# ⚠ There is no default, this must be set explicitly.
listen_addr = "0.0.0.0:3000"
[server.cache]
# Whether to enable caching.
#
# If enabled, badges will be cached in-memory (keyed by the URL they are
# fetched from), with no expiry. Caching improves performance a *lot*, and
# reduces the reliance on shields.io.
#
# Becaue it is all stored in-memory, only enable this if you expect to have a
# small number of badges.
#enable = false
[forge]
# URL for the Forgejo/Gitea instance to ask for Action statuses.
#
# ⚠ There is no default, this must be set explicitly.
url = "https://gitea.nicholaspease.com"
# Branch to check for action statuses. The `branch` query parameter can override this.
#branch = "main"
[badges]
# A shields.io URL to redirect to for badges.
#shields_url = "https://img.shields.io"
# Label to use for the badge. The `label` query parameter can override this.
#label = "ci"
# Style to use for the badge. The `style` query parameter can override this.
#style = "for-the-badge"
# Action status to color mappings. These set the background color of the
# content part of the badge.
[badges.color]
#success = "brightgreen"
#pending = "lightgrey"
#error = "lightgrey"
#failure = "crimson"
#warning = "orange"
#running = "gold"
#unknown = "lightgrey"
+40 -22
View File
@@ -50,8 +50,13 @@ struct ActionAPI {
fallback_url: FallbackURL,
}
#[derive(Deserialize, Clone)]
#[derive(Deserialize, Clone, Debug)]
struct ActionAPIResponse {
statuses: Vec<ActionAPIStatuses>,
}
#[derive(Deserialize, Clone, Debug)]
struct ActionAPIStatuses {
status: String,
target_url: String,
}
@@ -92,7 +97,7 @@ impl ActionAPI {
.forge
.url
.join(&format!(
"/api/v1/repos/{}/{}/statuses/{}",
"/api/v1/repos/{}/{}/commits/{}/status",
encode(owner),
encode(repo),
encode(&config.forge.branch)
@@ -100,11 +105,7 @@ impl ActionAPI {
.unwrap()
.to_string();
let request = reqwest::Client::new()
.get(&url)
.query(&[("sort", "leastindex"), ("limit", "1")])
.send()
.await;
let request = reqwest::Client::new().get(&url).send().await;
match request {
Err(e) => {
@@ -134,7 +135,7 @@ impl ActionAPI {
}
pub async fn send(self) -> Result<ActionAPIResponse, AppError> {
let status = self.response.json::<Vec<ActionAPIResponse>>().await;
let status = self.response.json::<ActionAPIResponse>().await;
match status {
Err(e) => {
@@ -146,8 +147,8 @@ impl ActionAPI {
)))
}
Ok(r) => {
if !r.is_empty() {
Ok(r[0].clone())
if !r.statuses.is_empty() {
Ok(r.clone())
} else {
log::error!(target: "ironforge::actions", "No statuses received.");
Err(AppError::ActionStatusEmpty(self.fallback_url.to_string(
@@ -174,15 +175,22 @@ async fn latest_log(
.send()
.await?;
let redir_url = if status.target_url.starts_with('/') {
config
.forge
.url
.join(&status.target_url)
.unwrap()
.to_string()
let redir_url = status
.statuses
.iter()
.fold(None, |u, item| {
if item.target_url.starts_with('/') {
Some(item.target_url.clone())
} else {
u.or(Some(item.target_url.clone()))
}
})
.unwrap();
let redir_url = if redir_url.starts_with('/') {
config.forge.url.join(&redir_url).unwrap().to_string()
} else {
status.target_url
redir_url
};
Ok(Redirect::temporary(&redir_url))
@@ -197,13 +205,23 @@ async fn badge(
let Query(q) = q.unwrap();
let config = q.merge_into(&config);
let status = ActionAPI::new(&config, &owner, &repo, FallbackURL::Badge)
let statuses = ActionAPI::new(&config, &owner, &repo, FallbackURL::Badge)
.await?
.send()
.await?
.status;
.statuses;
let color = match status.as_str() {
let state = if statuses.iter().all(|item| item.status == "success") {
"success"
} else {
&statuses
.iter()
.find(|item| item.status != "success")
.unwrap()
.status
};
let color = match state {
"pending" => config.badges.color.pending,
"success" => config.badges.color.success,
"error" => config.badges.color.error,
@@ -219,7 +237,7 @@ async fn badge(
.join(&format!(
"/badge/{}-{}-{}",
encode(&config.badges.label),
encode(&status),
encode(state),
encode(&color)
))
.unwrap();
+1 -1
View File
@@ -34,7 +34,7 @@ impl FallbackURL {
.join(&format!(
"/badge/{}-{}-{}",
encode(&config.badges.label),
encode("internal error"),
encode("none"),
encode("lightgrey"),
))
.unwrap();
-1
View File
@@ -13,7 +13,6 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
extern crate eyra;
use clap::Parser;
use std::path::PathBuf;
+9 -9
View File
@@ -20,12 +20,12 @@ pub fn status_with_relative_url(status: &str) -> (ServerGuard, Mock) {
let mut server = mockito::Server::new();
let mock = server
.mock("GET", "/api/v1/repos/test/test/statuses/main")
.mock("GET", "/api/v1/repos/test/test/commits/main/status")
.match_query(mockito::Matcher::Any)
.with_status(200)
.with_header("content-type", "application/json")
.with_body(&format!(
r#"[{{"status":"{}", "target_url":"/totally-latest-log"}}]"#,
.with_body(format!(
r#"{{"statuses":[{{"status":"{}","target_url":"/totally-latest-log"}}]}}"#,
status
))
.create();
@@ -37,12 +37,12 @@ pub fn status_with_absolute_url(status: &str) -> (ServerGuard, Mock) {
let mut server = mockito::Server::new();
let mock = server
.mock("GET", "/api/v1/repos/test/test/statuses/main")
.mock("GET", "/api/v1/repos/test/test/commits/main/status")
.match_query(mockito::Matcher::Any)
.with_status(200)
.with_header("content-type", "application/json")
.with_body(&format!(
r#"[{{"status":"{}", "target_url":"https://somewhere/totally-latest-log"}}]"#,
.with_body(format!(
r#"{{"statuses":[{{"status":"{}","target_url":"https://somewhere/totally-latest-log"}}]}}"#,
status
))
.create();
@@ -54,11 +54,11 @@ pub fn no_statuses() -> (ServerGuard, Mock) {
let mut server = mockito::Server::new();
let mock = server
.mock("GET", "/api/v1/repos/test/test/statuses/main")
.mock("GET", "/api/v1/repos/test/test/commits/main/status")
.match_query(mockito::Matcher::Any)
.with_status(200)
.with_header("content-type", "application/json")
.with_body("[]")
.with_body(r#"{{"statuses":[]}}"#)
.create();
(server, mock)
@@ -68,7 +68,7 @@ pub fn status_with_bad_json() -> (ServerGuard, Mock) {
let mut server = mockito::Server::new();
let mock = server
.mock("GET", "/api/v1/repos/test/test/statuses/main")
.mock("GET", "/api/v1/repos/test/test/commits/main/status")
.match_query(mockito::Matcher::Any)
.with_status(200)
.with_header("content-type", "application/json")