diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index de5470f..d28f845 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: publish: name: Build container image (amd64) - runs-on: blacksmith-2vcpu-ubuntu-2404 + runs-on: ubuntu-24.04 timeout-minutes: 60 permissions: @@ -33,15 +33,22 @@ jobs: outputs: digest: ${{ steps.build.outputs.digest }} + image: ${{ steps.image.outputs.name }} steps: - name: Check out source - uses: useblacksmith/checkout@v1 # v7.0.1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - - name: Setup Blacksmith Builder - uses: useblacksmith/setup-docker-builder@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4 + + - name: Set image name + id: image + env: + REPOSITORY: ${{ github.repository }} + run: echo "name=ghcr.io/${REPOSITORY,,}" >> "$GITHUB_OUTPUT" - name: Log in to GitHub Container Registry if: env.PUBLISH_IMAGE == 'true' @@ -55,14 +62,14 @@ jobs: id: meta uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 with: - images: ghcr.io/${{ github.repository }} + images: ${{ steps.image.outputs.name }} flavor: latest=false tags: | type=sha,format=long - name: Build candidate image id: build - uses: useblacksmith/build-push-action@v2 # v7.3.0 + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 with: context: . platforms: linux/amd64 @@ -85,7 +92,7 @@ jobs: promote: name: Promote the tested image - runs-on: blacksmith-2vcpu-ubuntu-2404 + runs-on: ubuntu-24.04 timeout-minutes: 10 needs: [checks, publish] if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') @@ -95,12 +102,12 @@ jobs: packages: write env: - IMAGE: ghcr.io/${{ github.repository }} + IMAGE: ${{ needs.publish.outputs.image }} DIGEST: ${{ needs.publish.outputs.digest }} steps: - name: Check out source - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false @@ -109,6 +116,9 @@ jobs: with: tool: just,ripgrep + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4 + - name: Log in to GitHub Container Registry uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9868f6f..bb5a02b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,10 +13,10 @@ concurrency: jobs: fmt: - runs-on: blacksmith-2vcpu-ubuntu-2404 + runs-on: ubuntu-24.04 steps: - name: Check out source - uses: useblacksmith/checkout@v1 # v7.0.1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false @@ -35,10 +35,10 @@ jobs: run: just fmt-check clippy: - runs-on: blacksmith-2vcpu-ubuntu-2404 + runs-on: ubuntu-24.04 steps: - name: Check out source - uses: useblacksmith/checkout@v1 # v7.0.1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false @@ -57,10 +57,10 @@ jobs: run: just lint test: - runs-on: blacksmith-2vcpu-ubuntu-2404 + runs-on: ubuntu-24.04 steps: - name: Check out source - uses: useblacksmith/checkout@v1 # v7.0.1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false diff --git a/README.md b/README.md index 6f1ba02..f294782 100644 --- a/README.md +++ b/README.md @@ -1,114 +1,75 @@ # GitHub release router -A small Rust service that receives signed GitHub webhooks and sends release announcements to Discord. Source repositories need no GitHub Actions workflow. One Actix Web process serves HTTP and runs one delivery worker. The queue and recent deduplication records stay in memory. No database or persistent volume is required. +Send GitHub release announcements to Discord. The service checks webhook signatures, routes releases by repository and tag, and retries failed deliveries. Each message includes the release title, link, and notes. Long notes are attached as a Markdown file. -## Setup +No GitHub token, Discord bot, database, or workflow in the source repository is required. -1. In Discord server **771444961383153695**, open **#web → Edit Channel → Integrations → Webhooks → New Webhook**. Select #web and copy the webhook URL. You need permission to manage webhooks. Use the regular Execute Webhook URL, never its `/github` suffix. -2. Copy `config.example.toml` to `config.toml`. Create a `secrets` directory. Put the Discord URL in `secrets/discord_webhook_url`. Create two independent random GitHub secrets, for example with `openssl rand -hex 32`, and save them as `secrets/actix_github_secret` and `secrets/personal_github_secret`. Do not commit these files. Secret files must be readable by container UID 10001; protect their parent directory on the host. Trailing CR/LF is removed; other bytes are retained. -3. Run `docker compose up --build -d`. Keep one service instance so retries, rate limits, and deduplication share the same memory. The container needs only read-only configuration and secrets. -4. Put an HTTPS reverse proxy in front of `127.0.0.1:8080`. Forward `/webhooks/github/` without rewriting the body. Set a request limit of at least 2 MiB and preserve the GitHub headers. TLS ends at the proxy. The container binds to `0.0.0.0:8080`; Compose exposes it only on host loopback. A proxy in another container can use `http://router:8080` on the Compose network instead. -5. In GitHub repository **Settings → Webhooks → Add webhook**, set the URL to `https://YOUR_HOST/webhooks/github/actix` for actix/actix-web, or `/webhooks/github/personal` for robjtede/actix-web-lab. Select **application/json**, enter the corresponding secret, keep SSL verification enabled, and select **Releases** under individual events. Organization hooks use **Organization Settings → Webhooks** and the same endpoint and secret. Their source allowlist still applies to each release event. GitHub sends a ping when the hook is created; an authenticated ping returns `200 pong`. +## Deploy with Docker Compose -The service accepts URLs copied from Discord (`https://discord.com/api/webhooks/ID/TOKEN`) and versioned URLs (`https://discord.com/api/v10/webhooks/ID/TOKEN`). It never requests GitHub data or uses a Discord bot token. +You need Docker with Compose, OpenSSL, permission to create a Discord webhook, and an HTTPS address that can forward requests to this service. Run the commands below from this project directory. -## Configuration +### 1. Configure a repository -TOML defines named `sources`, named `destinations`, and `[[routes]]`. Unknown fields and invalid references fail startup. Each secret uses exactly one reference: `{ env = "VARIABLE_NAME" }` or `{ file = "/path/to/secret" }`. Config files contain no credential values. Secret values and webhook URLs are excluded from logs and queue records. Configuration is loaded once; restart to apply changes. Restarting clears queued jobs. - -A source has an explicit repository allowlist. Unauthorized repository events return 403. A ping is source-authenticated but need not contain a repository, which permits organization pings. Other events need an allowed `repository.full_name`. Non-release events and release actions other than `published` return 204 without creating jobs. - -Routes compare `repository.full_name` exactly and case-sensitively. Prereleases match only routes with `include_prereleases = true`. All matching routes contribute destinations; each destination receives one message even when routes overlap. An unmatched published release returns 202 with no jobs. - -Use `include_tags` to select tags and `exclude_tags` to reject tags for a route: - -```toml -include_tags = ["^actix-web-lab-.*$", "^lab-v.*$"] -exclude_tags = ["^actix-web-lab-derive-.*$"] +```sh +cp config.example.toml config.toml +mkdir -p secrets +chmod 700 secrets +openssl rand -hex 32 > secrets/github_webhook_secret ``` -Both lists contain case-insensitive regular expressions. A pattern can match anywhere in the tag; use `^` and `$` to match the complete tag. See the [regex syntax](https://docs.rs/regex/latest/regex/#syntax) for more options. A tag must match at least one `include_tags` pattern. **Omit `include_tags` or use `[]` to allow all repository tags before exclusions.** If any `exclude_tags` pattern matches, that route contributes no destinations, even if an inclusion pattern matches. Other routes can still announce the release. Omit `exclude_tags` or use `[]` to exclude no tags. The example above allows `actix-web-lab-v0.27.0` and `LAB-v0.27.0`, but excludes both `actix-web-lab-derive-v0.1.0` and `ACTIX-WEB-LAB-DERIVE-v0.1.0`. Invalid regular expressions fail startup. Restart the service after changing the configuration. - -Replace an existing `tag_prefix = "web-"` with `include_tags = ["^web-"]`. The `tag_prefix` field is no longer accepted. - -To add the third, fourth, or later repository, add its real `owner/name` to a source allowlist and add a route. Use a new source and secret if the hook needs a different trust boundary. Add named destinations to send to more channels, then list those destination names in routes. The example intentionally includes only the two known repositories. - -## Delivery and recovery - -The signature extractor adapts the [Actix Web Lab Discord example](https://github.com/robjtede/actix-web-lab/blob/main/actix-web-lab/examples/discord_webhook.rs): `RequestSignature, GithubSignature>` passes original payload chunks to HMAC-SHA256 while decoding JSON. `verify_slice` compares the digest in constant time. Missing, duplicate, malformed, or wrong signatures fail authentication. Content encodings are rejected so decompression cannot change signed bytes. Incoming JSON is limited to **2 MiB**, including chunked bodies. - -Published releases enter an in-memory queue before HTTP 202. Discord calls occur only in the worker. The queue holds at most 64 jobs, including the active send and delayed retries. If all new destinations cannot fit, the event returns HTTP 503 without adding jobs or consuming its delivery ID. Redeliver it after capacity becomes available. +Edit `config.toml`. Replace **both** instances of `example/app` with your repository's `owner/name`. The default route announces published releases and excludes prereleases. -Concurrency is fixed at **one outgoing request**. The shared HTTP client has a 5-second connect timeout, a 30-second request timeout, and redirects disabled. Every request sets `wait=true` and requires a returned message ID. HTTP 429 uses the larger of `retry_after` and `Retry-After`, rounded up with a one-second margin. A shared in-memory cooldown pauses all destinations. Network failures, HTTP 408/5xx, and absent creation confirmation retry with exponential delay and jitter (2 seconds initially, at most 1,125 seconds). Each job gets 12 attempts; remaining failures are logged and removed from the queue. Other HTTP errors fail immediately. A missing destination also fails explicitly. +### 2. Add a Discord webhook -SIGINT/SIGTERM stops intake and lets the active send finish, up to its timeout. **Pending jobs, retries, cooldowns, and deduplication records are lost when the process stops**, including during deployments and configuration changes. HTTP 202 means accepted into memory, not guaranteed delivery. Delivery is not exactly once: a lost Discord response can cause a retry to post a duplicate. +In your target Discord channel, open **Edit Channel → Integrations → Webhooks**. Create a webhook and copy its URL into `secrets/discord_webhook_url`. Use the URL as copied, without a `/github` suffix. -Delivery IDs and successful `(repository, release ID, destination)` keys are each cached for up to 30 days, with a limit of 4,096 entries per cache. The oldest entries are removed when a cache fills. Active jobs remain deduplicated until completion. Redelivery after a restart or cache eviction can post an announcement again. The first accepted payload wins while its key is retained; edits are not reposted. +Make both secret files readable by the container's user (UID 10001): -Permanent and exhausted failures appear in the logs and Sentry, when enabled. Their message bodies are discarded and their keys are released so GitHub can redeliver them. Successful destinations remain deduplicated while cached. There are no `failed` or `retry` CLI commands. - -If intake fails, the queue is full, or an outgoing delivery fails, fix the cause, open the repository or organization webhook's **Recent deliveries**, select the delivery, and choose **Redeliver**. Also check for accepted work lost during a restart. Monitor GitHub delivery failures and service logs. - -When upgrading from the SQLite version, let pending work finish and inspect failed jobs before replacing it. Remove the `database` setting from your TOML configuration; it is no longer accepted. Existing database files are not imported. Remove old Docker volumes or Kubernetes PVCs yourself after you no longer need their data. Applying the updated manifests does not delete an existing PVC. - -## Messages and operations - -An embed shows the release name as its linked title, plus the repository and notes. Discord displays the message time. The tag is used as the title only when GitHub provides no release name. Supported Markdown is retained. Empty notes have a fallback. All mention parsing is disabled. Notes longer than the description limit get an excerpt and a complete `release-notes.md` attachment in the same multipart message. - -The renderer budgets 256 UTF-16 units each for title and repository and 4,096 for description. Their sum stays below Discord's 6,000-character total embed limit. Unicode truncation preserves character boundaries. See [Discord embed limits](https://docs.discord.com/developers/resources/message#embed-limits) and [Execute Webhook](https://docs.discord.com/developers/resources/webhook#execute-webhook). The 2 MiB input limit also bounds the notes attachment. - -- `GET /healthz`: 200 when HTTP is running; it does not check Discord. -- `GET /readyz`: 200 when the delivery worker is active; otherwise 503. Discord failures do not take down readiness. -- Tracing logs go to stderr as text with named fields and no application timestamp. The default level is `INFO`. HTTP handlers run in a request span that records the method, route, status, and request ID. Logs show startup, authentication rejections, webhook decisions, and delivery results. Retries include the attempt, reason, delay, and destination name. Set `RUST_LOG=github_release_router=debug` to include job claims, Discord response status codes, safe network error classes, and failed readiness checks. Logs exclude secrets, webhook URLs, request bodies, and raw HTTP client errors. Do not enable HTTP wire logging in production. -- Monitor delivery failures, readiness, and GitHub's recent deliveries. No metrics service is required. - -The `serve` command supports Sentry error reporting. Set `SENTRY_DSN` to enable it and `SENTRY_ENVIRONMENT` to label the deployment. Compose passes these variables to the container. Without a DSN, reporting is disabled. The [Sentry Actix Web integration](https://docs.rs/sentry-actix/latest/sentry_actix/) gives each request its own scope and captures server errors. The tracing integration also reports error logs and records info and warning logs as breadcrumbs, subject to `RUST_LOG`. The client includes the package release and flushes pending events at shutdown. Preview does not initialize Sentry. +```sh +chmod 644 secrets/github_webhook_secret secrets/discord_webhook_url +``` -## Local development and preview +The `secrets` directory stays accessible only to your host user. The configuration and secrets are excluded from Git and Docker's build context. -Use stable Rust. `rust-toolchain.toml` and CI select the latest stable release; the Docker builder tracks the latest Rust release on Trixie. `Cargo.lock` is included and all builds use `--locked`. CI runs separate formatting, Clippy, test, and container build jobs on pull requests and pushes to `main`. You can also run the container workflow manually. +### 3. Start the service ```sh -just fmt -just fmt-check -just lint -just test -just preview # No config, credentials, or network calls -just preview path/to/webhook.json -just run config.toml -just container-build -just container-run +docker compose up --build -d --wait +curl --fail http://127.0.0.1:8080/readyz +docker compose logs -f router ``` -For local execution, use local secret files or environment references. Preview emits JSON containing `payload` (the Discord message) and `notes` (the full attachment, when needed). Tests use in-memory queues and loopback fake Discord servers. They never post to Discord. +The readiness endpoint returns `ready` when the worker is running. Compose binds the port to host loopback. Run **one instance**: the delivery queue, duplicate detection, and rate limits are stored in memory. Restarting clears this state, including pending deliveries. -Run `just container-smoke` after `just container-build` to check non-root startup with a read-only filesystem, health, readiness, in-process deduplication, cleared state after restart, and SIGTERM shutdown. This script needs Docker, OpenSSL, and ripgrep. It creates and removes its own container with no data volume. Its container has `--network none`, so no test can reach Discord. +### 4. Expose the webhook over HTTPS -## Container publishing +Configure your reverse proxy to forward to `http://127.0.0.1:8080`. A proxy on the Compose network can use `http://router:8080`. Preserve the request path, body, and GitHub headers. Allow request bodies up to 2 MiB and terminate TLS at the proxy. -The [container workflow](.github/workflows/build.yml) builds the locked Dockerfile for `linux/amd64`. Pull requests build and smoke-test a local image without publishing. Formatting, Clippy, and tests run in the CI workflow. +### 5. Connect GitHub -Each push to `main` publishes a `ghcr.io/actix/github-release-router:sha-` candidate and runs formatting, Clippy, and tests through the reusable CI workflow. After those checks and the image build pass, the promotion job runs `just container-smoke` against the published image digest. It then updates `:stable` and `:latest` to that exact digest without rebuilding the image. A failed check leaves the deployment tags unchanged. +In your repository, open **Settings → Webhooks → Add webhook**: -Deployments must follow the digest behind `ghcr.io/actix/github-release-router:stable`, or pin the digest recorded in the promotion job summary. Publishing a candidate alone does not select a deployment image. Manual runs publish and promote only when you select `main`. +| Setting | Value | +| --- | --- | +| Payload URL | `https://YOUR_HOST/webhooks/github/releases` | +| Content type | `application/json` | +| Secret | Contents of `secrets/github_webhook_secret` | +| SSL verification | Enabled | +| Events | Select individual events, then **Releases** | -The workflow uses the repository's `GITHUB_TOKEN` with package write permission. A new GHCR package is private by default, so make it public or grant your cluster image-pull access before deploying it. +GitHub's initial ping must return `200 pong`. Publish a release to send an announcement. Organization webhooks use the same endpoint; list each allowed repository in the source configuration. -## Kubernetes example +## Configuration and operations -The [`k8s/`](k8s/) directory contains example resources for a single-replica deployment. It needs no persistent volume, mounts the TOML configuration read-only, mounts credentials as files, runs as UID 10001, and exposes a ClusterIP service. `deployment.yaml` uses a placeholder image; replace it with the image published from your registry. `ingress.example.yaml` is an optional nginx example and must be adapted to the ingress controller and certificate manager in use. +- [Configuration](docs/configuration.md): more repositories, channels, secrets, and tag filters. +- [Operations](docs/operations.md): health checks, logs, retries, updates, and recovery. +- [Kubernetes deployment](k8s/README.md): manifests, secrets, and ingress. +- [Development and container publishing](docs/development.md): local commands and CI. -Create the Secret without committing credentials. For example, use `k8s/secret.example.yaml` as a template or generate it with `kubectl create secret generic`; do not apply the placeholder values. The example Secret is deliberately excluded from `kustomization.yaml`. Then apply the Secret and base resources: +To preview an announcement without credentials or network requests: ```sh -kubectl apply -f k8s/namespace.yaml -kubectl -n github-release-router create secret generic github-release-router-secrets \ - --from-file=actix_github_secret \ - --from-file=personal_github_secret \ - --from-file=discord_webhook_url -kubectl apply -k k8s/ -kubectl -n github-release-router rollout status deployment/github-release-router -kubectl -n github-release-router port-forward service/github-release-router 8080:8080 +just preview ``` -Configure GitHub hooks against the HTTPS ingress URL, for example `https://releases.example.com/webhooks/github/actix`. Keep one pod because deduplication and Discord cooldowns are local to the process. The Recreate strategy prevents old and new pods from overlapping. Each deployment clears pending work and recent history. +HTTP `202` means the release was accepted into memory. Check service logs for the delivery result. For failed or lost deliveries, use **Redeliver** in GitHub's webhook delivery history. See [delivery and recovery](docs/operations.md#delivery-and-recovery) for the delivery limits. diff --git a/compose.yaml b/compose.yaml index 97dcf50..6f9ee55 100644 --- a/compose.yaml +++ b/compose.yaml @@ -5,6 +5,7 @@ services: restart: unless-stopped init: true environment: + RUST_LOG: ${RUST_LOG:-github_release_router=info} SENTRY_DSN: ${SENTRY_DSN:-} SENTRY_ENVIRONMENT: ${SENTRY_ENVIRONMENT:-production} read_only: true @@ -15,15 +16,12 @@ services: volumes: - ./config.toml:/etc/router/config.toml:ro secrets: - - actix_github_secret - - personal_github_secret + - github_webhook_secret - discord_webhook_url stop_grace_period: 75s secrets: - actix_github_secret: - file: ./secrets/actix_github_secret - personal_github_secret: - file: ./secrets/personal_github_secret + github_webhook_secret: + file: ./secrets/github_webhook_secret discord_webhook_url: file: ./secrets/discord_webhook_url diff --git a/config.example.toml b/config.example.toml index 3defad9..15d2402 100644 --- a/config.example.toml +++ b/config.example.toml @@ -1,38 +1,24 @@ bind = "0.0.0.0:8080" -# A repository hook and an organization hook use the same endpoint format. -# Configure each hook with the secret for its named source. -[sources.actix] -repositories = ["actix/actix-web"] -secret = { file = "/run/secrets/actix_github_secret" } +# Replace example/app in both the allowlist and the route below. +# Configure GitHub to send releases to /webhooks/github/releases. +[sources.releases] +repositories = ["example/app"] +secret = { file = "/run/secrets/github_webhook_secret" } +# Alternative: secret = { env = "GITHUB_WEBHOOK_SECRET" } -[sources.personal] -repositories = ["robjtede/actix-web-lab"] -secret = { file = "/run/secrets/personal_github_secret" } - -# This URL must belong to #web in server 771444961383153695. -# The server/channel IDs are not API parameters for incoming webhook delivery. -[destinations.web] +[destinations.releases] webhook = { file = "/run/secrets/discord_webhook_url" } # Alternative: webhook = { env = "DISCORD_WEBHOOK_URL" } [[routes]] -name = "actix-web" -repository = "actix/actix-web" -# Optional. Match any of these case-insensitive regexes. -include_tags = ["^web-"] # Omit or use [] to match all tags before exclusions. -include_prereleases = false -destinations = ["web"] +name = "app-releases" +repository = "example/app" +destinations = ["releases"] -[[routes]] -name = "actix-web-lab" -repository = "robjtede/actix-web-lab" -# Optional. Match any of these case-insensitive regexes. -include_tags = ["^lab-"] # Omit or use [] to match all tags before exclusions. -# Optional. Exclude tags that match any of these case-insensitive regexes. -# exclude_tags = ["^actix-web-lab-derive-.*$"] -include_prereleases = false -destinations = ["web"] +# Optional. Prereleases are excluded by default. +# include_prereleases = true -# Add the other repository names to a source allowlist and add a route for each. -# There is no two-repository limit; four or more use the same configuration. +# Optional. All tags are allowed by default. Patterns are case-insensitive regexes. +# include_tags = ["^v[0-9]+[.][0-9]+[.][0-9]+$"] +# exclude_tags = ["-(internal|test)$"] diff --git a/docs/configuration.md b/docs/configuration.md new file mode 100644 index 0000000..17d0468 --- /dev/null +++ b/docs/configuration.md @@ -0,0 +1,66 @@ +# Configuration + +Start with [`config.example.toml`](../config.example.toml). Configuration is loaded once at startup. Restart the service after a change. Unknown fields, invalid regular expressions, and invalid references stop startup. + +## Sources and destinations + +A **source** defines a GitHub webhook secret and an explicit repository allowlist. Its name selects the endpoint: `[sources.releases]` accepts requests at `/webhooks/github/releases`. Source names can contain ASCII letters, digits, hyphens, and underscores. + +Repository names use the `owner/name` format and match exactly, including letter case. Signed events for repositories outside the source allowlist return `403`. An authenticated GitHub ping does not need a repository, which permits organization webhook setup. + +A **destination** defines a Discord webhook URL. Create a named destination for each webhook you want to use. URLs copied from Discord and URLs with `/api/v10/webhooks/` are accepted. The URL must use `https://discord.com`; suffixes such as `/github` and query strings are rejected. + +## Secrets + +Each secret must use exactly one reference: + +```toml +secret = { file = "/run/secrets/github_webhook_secret" } +# Or: secret = { env = "GITHUB_WEBHOOK_SECRET" } + +# Under a destination: +webhook = { file = "/run/secrets/discord_webhook_url" } +# Or: webhook = { env = "DISCORD_WEBHOOK_URL" } +``` + +Keep credential values out of TOML and source control. The service removes trailing CR/LF from secret values and preserves other bytes. Secret values and webhook URLs are excluded from application logs and queue records. + +Compose mounts the two files in `secrets/` at `/run/secrets/`. For local execution, change the file references to local paths or use environment references. Add any extra secret files to the Compose service's `secrets` list and top-level `secrets` definitions, or to the Kubernetes Secret. + +## Routes + +Each `[[routes]]` entry needs a unique `name`, one `repository`, and one or more named `destinations`. The repository must appear in a source allowlist. All matching routes contribute destinations; overlapping routes send only one message to each destination. + +To add a repository, add its `owner/name` to a source's `repositories` list and add a route: + +```toml +# First add example/cli to the existing source allowlist: +# repositories = ["example/app", "example/cli"] + +[[routes]] +name = "cli-releases" +repository = "example/cli" +destinations = ["releases"] +include_prereleases = true +``` + +Configure a repository webhook for each repository, or use an organization webhook. Reuse a source when hooks share a secret. Create a new source with an independent secret when hooks need separate credentials. Destination names can refer to webhooks in different Discord channels or servers. + +## Tag filters + +By default, a route allows all tags and excludes prereleases. Set `include_prereleases = true` to announce prereleases too. Only the `published` release action creates announcements. + +Use optional regular expressions to select tags within a route: + +```toml +include_tags = ["^app-v", "^v[0-9]+[.][0-9]+[.][0-9]+$"] +exclude_tags = ["-(internal|test)$"] +``` + +Patterns are case-insensitive and can match anywhere in the tag. Use `^` and `$` to match the complete tag. A tag must match at least one inclusion pattern, unless `include_tags` is omitted or empty. Any matching exclusion rejects the tag for that route. Other routes can still match. + +For example, these filters include `app-v1.0.0` and `V1.0.0`, but exclude `app-v1.0.0-internal` and `APP-v1.0.0-TEST`. Omit `exclude_tags` or use `[]` to exclude no tags. + +## HTTP listener + +`bind` defaults to `0.0.0.0:8080`. Use an IP address and port. TLS ends at your reverse proxy. The service accepts JSON bodies up to 2 MiB and rejects content encodings so it can verify the original signed bytes. diff --git a/docs/development.md b/docs/development.md new file mode 100644 index 0000000..a3d875e --- /dev/null +++ b/docs/development.md @@ -0,0 +1,37 @@ +# Development and container publishing + +## Local commands + +Install stable Rust and `just`. The toolchain file selects stable Rust with rustfmt and Clippy. Builds use the committed `Cargo.lock`. + +```sh +just fmt +just fmt-check +just lint +just test +just preview +just preview path/to/webhook.json +just run config.toml +``` + +Preview renders a webhook payload without configuration, credentials, or network calls. Its JSON output contains `payload` (the Discord message) and `notes` (the full attachment, when needed). Tests use in-memory queues and local fake Discord servers. + +## Containers + +```sh +just container-build +just container-smoke +just container-run +``` + +The smoke test needs Docker, OpenSSL, and ripgrep. It checks startup as a non-root user with a read-only filesystem, health, readiness, duplicate detection, state reset after restart, and SIGTERM shutdown. It uses an isolated container with no external network and removes it when done. + +## GitHub Actions + +The [CI workflow](../.github/workflows/ci.yml) checks formatting, Clippy, and tests. The [container workflow](../.github/workflows/build.yml) builds for `linux/amd64`. Both use standard GitHub-hosted Ubuntu runners. Pull requests build and smoke-test the image without publishing it. + +A push to `main` publishes a candidate to `ghcr.io//:sha-`, using the current GitHub repository name. After CI and the build pass, the promotion job smoke-tests that exact image digest and updates `:stable` and `:latest` without rebuilding. Failed checks leave those tags unchanged. Manual runs publish and promote only on `main`. + +The workflow uses `GITHUB_TOKEN` with package write permission. Enable GitHub Actions and permit package publishing in the repository or organization settings. New container packages are private by default; make the package public or configure registry credentials for your deployment. See [GitHub's container registry guide](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry). + +For a registry deployment, use the digest recorded in the promotion job summary or the promoted `:stable` tag. Compose builds a local image by default; it does not pull the published image. The published image targets amd64. Build locally on another architecture. diff --git a/docs/operations.md b/docs/operations.md new file mode 100644 index 0000000..925246e --- /dev/null +++ b/docs/operations.md @@ -0,0 +1,54 @@ +# Operations + +## Health and logs + +- `GET /healthz` returns `200` when the HTTP server is running. +- `GET /readyz` returns `200` when the delivery worker is active, or `503` otherwise. It does not check Discord connectivity. + +Logs go to stderr. They include webhook decisions, delivery results, and retry attempts. They exclude credentials, webhook URLs, and request bodies. With Compose: + +```sh +docker compose logs -f router +``` + +The default log level is `INFO`. Set `RUST_LOG=github_release_router=debug` for more delivery details. Compose passes this variable to the container. Avoid HTTP wire logging because it can expose credentials. + +Sentry reporting is optional. Set `SENTRY_DSN` to enable it and `SENTRY_ENVIRONMENT` to label the deployment. Compose passes both variables through. Without a DSN, reporting is disabled. Preview does not initialize Sentry. + +## Delivery and recovery + +The service accepts signed GitHub release events and queues matching announcements before returning `202`. Other event types and release actions return `204`. An unmatched published release returns `202` without a job. + +The queue holds up to 64 jobs, including the active request and delayed retries. If all new destinations cannot fit, the service returns `503` without adding jobs or recording the delivery ID. Redeliver the event after capacity becomes available. + +One worker sends one request at a time. It waits for Discord to confirm message creation. Rate limits pause all destinations for the required delay. Network errors, HTTP `408`/`5xx`, and missing confirmation retry with exponential delay and jitter. Each job gets up to 12 attempts. Other HTTP errors fail immediately. Permanent and exhausted failures appear in the logs and in Sentry when enabled. + +Keep one service instance. Queue state, cooldowns, and duplicate detection are held in memory. **Stopping the process discards pending jobs and recent delivery history.** HTTP `202` does not guarantee delivery. A lost response or a redelivery after restart can create a duplicate announcement. + +Delivery IDs and successful `(repository, release ID, destination)` keys are each retained for up to 30 days, with a limit of 4,096 entries per cache. Active jobs stay deduplicated until completion. Edits are not reposted while a release key is retained. + +To recover a failed delivery or one lost during a restart: + +1. Fix the cause shown in the service logs. +2. Open the repository or organization webhook's **Recent deliveries** in GitHub. +3. Select the event and choose **Redeliver**. +4. Check the logs for a successful Discord delivery. + +Failed destinations can be retried by redelivery. Successful destinations remain deduplicated while their keys are cached. + +## Updates and shutdown + +After changing configuration, recreate the service: + +```sh +docker compose up --build -d --force-recreate --wait +curl --fail http://127.0.0.1:8080/readyz +``` + +Use `docker compose stop` to stop it. On SIGINT or SIGTERM, the service stops intake and waits for the active send to finish. An outgoing request has a 5-second connect timeout and a 30-second total timeout. Pending jobs and retries do not drain during shutdown. Before a planned restart, check delivery logs and allow accepted work to finish. Redeliver lost events afterward. + +## Message format + +Each announcement includes a linked release title, repository name, and notes. The tag is the fallback title when the release has no name. Supported Markdown is retained, and all mention parsing is disabled. + +Notes that exceed the embed description limit use an excerpt and a complete `release-notes.md` attachment. Unicode truncation preserves character boundaries. The input body limit also bounds the attachment size. diff --git a/examples/release.json b/examples/release.json index e30edad..a75f493 100644 --- a/examples/release.json +++ b/examples/release.json @@ -1,11 +1,11 @@ { "action": "published", - "repository": { "full_name": "actix/actix-web" }, + "repository": { "full_name": "example/app" }, "release": { "id": 123456, - "tag_name": "web-v4.0.0", - "name": "Actix Web 4.0.0", - "html_url": "https://github.com/actix/actix-web/releases/tag/web-v4.0.0", + "tag_name": "v1.0.0", + "name": "App 1.0.0", + "html_url": "https://github.com/example/app/releases/tag/v1.0.0", "published_at": "2026-09-24T10:00:00Z", "prerelease": false, "body": "## Changes\n\n- Improve request handling.\n- Fix an edge case.\n\nThank you to all contributors!" diff --git a/justfile b/justfile index 823815d..4c2ce32 100644 --- a/justfile +++ b/justfile @@ -24,7 +24,7 @@ container-build: docker build -t github-release-router:local . container-run: - docker compose up --build -d + docker compose up --build -d --wait # Requires Docker, OpenSSL, and ripgrep. Uses no external network. container-smoke image="github-release-router:local": diff --git a/k8s/README.md b/k8s/README.md new file mode 100644 index 0000000..00b47a4 --- /dev/null +++ b/k8s/README.md @@ -0,0 +1,44 @@ +# Kubernetes deployment + +These manifests run one replica as UID 10001 with a read-only filesystem. They mount configuration and credentials as files and expose a ClusterIP service. No persistent volume is required. + +Run these commands from the project root. + +## Configure the deployment + +1. Edit `k8s/configmap.yaml`. Replace both instances of `example/app` with your repository's `owner/name`. Use the same source names, destinations, and route options described in the [configuration guide](../docs/configuration.md). +2. Edit `k8s/deployment.yaml`. Replace the placeholder image with your published image, preferably pinned to the digest from a successful promotion. The included container workflow publishes for `linux/amd64`; use an amd64 node or build an image for your cluster's architecture. For a private registry, configure image-pull credentials. +3. Create `secrets/github_webhook_secret` and `secrets/discord_webhook_url` as described in the [Compose setup](../README.md#deploy-with-docker-compose). You do not need a local `config.toml` for Kubernetes. + +## Apply the resources + +```sh +kubectl apply -f k8s/namespace.yaml +kubectl -n github-release-router create secret generic github-release-router-secrets \ + --from-file=github_webhook_secret=secrets/github_webhook_secret \ + --from-file=discord_webhook_url=secrets/discord_webhook_url +kubectl apply -k k8s/ +kubectl -n github-release-router rollout status deployment/github-release-router +``` + +The [Secret template](secret.example.yaml) shows the required keys. It is excluded from `kustomization.yaml`; do not apply its placeholder values or commit credentials. + +To check readiness locally: + +```sh +kubectl -n github-release-router port-forward service/github-release-router 8080:8080 +# In another terminal: +curl --fail http://127.0.0.1:8080/readyz +``` + +## Expose the webhook + +Adapt `k8s/ingress.example.yaml` to your hostname, ingress controller, and TLS certificate. It uses nginx annotations and permits bodies up to 2 MiB. Create the TLS Secret with your certificate manager or cluster tooling, then apply the ingress: + +```sh +kubectl apply -f k8s/ingress.example.yaml +``` + +Configure GitHub to send release events to `https://YOUR_HOST/webhooks/github/releases` with your webhook secret, as described in the [GitHub setup](../README.md#5-connect-github). + +Keep one replica. Duplicate detection and Discord cooldowns are local to the process. The `Recreate` strategy prevents pods from overlapping. A deployment clears pending deliveries and recent history. After changing the ConfigMap or Secret, run `kubectl -n github-release-router rollout restart deployment/github-release-router`. See [operations](../docs/operations.md) for recovery steps. diff --git a/k8s/configmap.yaml b/k8s/configmap.yaml index bf9dc7b..cf176b5 100644 --- a/k8s/configmap.yaml +++ b/k8s/configmap.yaml @@ -7,28 +7,14 @@ data: config.toml: | bind = "0.0.0.0:8080" - [sources.actix] - repositories = ["actix/actix-web"] - secret = { file = "/run/secrets/actix_github_secret" } + [sources.releases] + repositories = ["example/app"] + secret = { file = "/run/secrets/github_webhook_secret" } - [sources.personal] - repositories = ["robjtede/actix-web-lab"] - secret = { file = "/run/secrets/personal_github_secret" } - - [destinations.web] + [destinations.releases] webhook = { file = "/run/secrets/discord_webhook_url" } [[routes]] - name = "actix-web" - repository = "actix/actix-web" - include_tags = ["^web-"] - include_prereleases = false - destinations = ["web"] - - [[routes]] - name = "actix-web-lab" - repository = "robjtede/actix-web-lab" - include_tags = ["^lab-"] - # exclude_tags = ["^actix-web-lab-derive-.*$"] - include_prereleases = false - destinations = ["web"] + name = "app-releases" + repository = "example/app" + destinations = ["releases"] diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml index 5dd310e..41c178b 100644 --- a/k8s/deployment.yaml +++ b/k8s/deployment.yaml @@ -26,8 +26,8 @@ spec: type: RuntimeDefault containers: - name: router - image: ghcr.io/replace-me/github-release-router:latest - imagePullPolicy: IfNotPresent + image: ghcr.io/replace-me/github-release-router:stable + imagePullPolicy: Always args: ["--config", "/etc/router/config.toml", "serve"] ports: - name: http diff --git a/k8s/secret.example.yaml b/k8s/secret.example.yaml index 80a372d..2391dfa 100644 --- a/k8s/secret.example.yaml +++ b/k8s/secret.example.yaml @@ -6,6 +6,5 @@ metadata: type: Opaque stringData: # Replace every value before applying. Keep this file out of source control. - actix_github_secret: replace-me - personal_github_secret: replace-me + github_webhook_secret: replace-me discord_webhook_url: https://discord.com/api/v10/webhooks/replace-me/replace-me diff --git a/scripts/docker-smoke.sh b/scripts/docker-smoke.sh index 92fabd1..4bd8e70 100755 --- a/scripts/docker-smoke.sh +++ b/scripts/docker-smoke.sh @@ -14,14 +14,14 @@ chmod 755 "$smoke_dir" cp examples/release.json "$smoke_dir/release.json" cat > "$smoke_dir/config.toml" <<'CONFIG' [sources.test] -repositories = ["actix/actix-web"] +repositories = ["example/app"] secret = { env = "TEST_GITHUB_SECRET" } -[destinations.web] +[destinations.releases] webhook = { env = "TEST_DISCORD_URL" } [[routes]] name = "smoke" -repository = "actix/actix-web" -destinations = ["web"] +repository = "example/app" +destinations = ["releases"] CONFIG chmod 644 "$smoke_dir"/* signature=$(openssl dgst -sha256 -hmac test-secret "$smoke_dir/release.json" | awk '{print $NF}') diff --git a/src/tests.rs b/src/tests.rs index 3b6e857..59dbfce 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -24,18 +24,18 @@ fn config() -> Config { Config { bind: "127.0.0.1:8080".into(), sources: BTreeMap::from([( - "org".into(), + "releases".into(), Source { secret: Secret { env: None, file: None, }, - repositories: vec!["actix/actix-web".into()], + repositories: vec!["example/app".into()], key: "test-secret".into(), }, )]), destinations: BTreeMap::from([( - "web".into(), + "releases".into(), Destination { webhook: Secret { env: None, @@ -45,12 +45,12 @@ fn config() -> Config { }, )]), routes: vec![Route { - name: "web".into(), - repository: "actix/actix-web".into(), - include_tags: vec![regex::Regex::new("(?i)^web-").unwrap()], + name: "releases".into(), + repository: "example/app".into(), + include_tags: vec![regex::Regex::new("(?i)^v").unwrap()], exclude_tags: Vec::new(), include_prereleases: false, - destinations: vec!["web".into()], + destinations: vec!["releases".into()], }], } } @@ -83,7 +83,7 @@ async fn signatures_cover_exact_bytes_and_chunked_payloads() { (None, false), ] { let mut builder = test::TestRequest::post() - .param("source", "org") + .param("source", "releases") .insert_header(("content-type", "application/json")) .app_data(Data::new(config())); if let Some(signature) = signature { @@ -152,7 +152,7 @@ async fn incoming_filters_authorizes_limits_and_deduplicates() { ] { let body = value.to_string(); let request = test::TestRequest::post() - .uri("/webhooks/github/org") + .uri("/webhooks/github/releases") .insert_header(("content-type", "application/json")) .insert_header(("x-hub-signature-256", sign(body.as_bytes()))) .insert_header(("x-github-delivery", id)) @@ -169,7 +169,7 @@ async fn incoming_filters_authorizes_limits_and_deduplicates() { assert!(queue.claim().await.is_none()); let huge = json!({"body": "x".repeat(github::MAX_BODY)}).to_string(); let request = test::TestRequest::post() - .uri("/webhooks/github/org") + .uri("/webhooks/github/releases") .insert_header(("content-type", "application/json")) .insert_header(("x-hub-signature-256", sign(huge.as_bytes()))) .set_payload(huge) @@ -188,32 +188,32 @@ async fn incoming_filters_authorizes_limits_and_deduplicates() { #[actix_web::test] async fn incoming_applies_case_insensitive_tag_regexes_before_queueing_announcements() { for (tag, expected_job) in [ - ("actix-web-lab-derive-v0.1.0", false), - ("actix-web-lab-derive-", false), - ("actix-web-lab-v0.27.0-internal", false), - ("actix-web-lab-v0.27.0-TEST", false), - ("actix-web-lab-v0.27.0", true), - ("ACTIX-WEB-LAB-v0.27.0", true), - ("actix-web-lab-Derive-v0.1.0", false), - ("actix-web-lab-test-v0.1.0", true), - ("actix-web-lab-v0.27.0-internal-more", true), - ("other-actix-web-lab-v0.27.0", false), - ("lab-v0.27.0", true), - ("LAB-v0.27.0", true), - ("lab-v0.27.0-internal", false), - ("other-lab-v0.27.0", false), - ("web-v4.0.0", false), + ("toolkit-derive-v0.1.0", false), + ("toolkit-derive-", false), + ("toolkit-v0.27.0-internal", false), + ("toolkit-v0.27.0-TEST", false), + ("toolkit-v0.27.0", true), + ("TOOLKIT-v0.27.0", true), + ("toolkit-Derive-v0.1.0", false), + ("toolkit-test-v0.1.0", true), + ("toolkit-v0.27.0-internal-more", true), + ("other-toolkit-v0.27.0", false), + ("sdk-v0.27.0", true), + ("SDK-v0.27.0", true), + ("sdk-v0.27.0-internal", false), + ("other-sdk-v0.27.0", false), + ("v1.0.0", false), ] { let mut config = config(); - config.sources.get_mut("org").unwrap().repositories = vec!["robjtede/actix-web-lab".into()]; + config.sources.get_mut("releases").unwrap().repositories = vec!["example/toolkit".into()]; config.routes = vec![ toml::from_str( r#" - name = "lab" - repository = "robjtede/actix-web-lab" - include_tags = ["^actix-web-lab-", "^lab-v[0-9]+[.][0-9]+[.][0-9]+$"] - exclude_tags = ["^actix-web-lab-derive-.*$", "-(internal|test)$"] - destinations = ["web"] + name = "toolkit" + repository = "example/toolkit" + include_tags = ["^toolkit-", "^sdk-v[0-9]+[.][0-9]+[.][0-9]+$"] + exclude_tags = ["^toolkit-derive-.*$", "-(internal|test)$"] + destinations = ["releases"] "#, ) .unwrap(), @@ -229,11 +229,11 @@ async fn incoming_applies_case_insensitive_tag_regexes_before_queueing_announcem .await; let mut value = event(); - value["repository"]["full_name"] = json!("robjtede/actix-web-lab"); + value["repository"]["full_name"] = json!("example/toolkit"); value["release"]["tag_name"] = json!(tag); let body = value.to_string(); let request = test::TestRequest::post() - .uri("/webhooks/github/org") + .uri("/webhooks/github/releases") .insert_header(("content-type", "application/json")) .insert_header(("x-hub-signature-256", sign(body.as_bytes()))) .insert_header(("x-github-delivery", "tag-filter")) @@ -259,10 +259,10 @@ async fn routes_apply_tag_filters_per_route() { toml::from_str( r#" name = "filtered" - repository = "actix/actix-web" - include_tags = ["lab", "^http-v"] - exclude_tags = ["^actix-web-lab-derive-.*$"] - destinations = ["web", "another"] + repository = "example/app" + include_tags = ["toolkit", "^http-v"] + exclude_tags = ["^toolkit-derive-.*$"] + destinations = ["releases", "another"] "#, ) .unwrap(), @@ -271,24 +271,27 @@ async fn routes_apply_tag_filters_per_route() { let mut release: github::Release = serde_json::from_value(event()["release"].clone()).unwrap(); for (tag, expected_filtered) in [ - ("ACTIX-WEB-LAB-DERIVE-v0.1.0", false), - ("ACTIX-WEB-LAB-v0.27.0", true), + ("TOOLKIT-DERIVE-v0.1.0", false), + ("TOOLKIT-v0.27.0", true), ("HTTP-v3.0.0", true), - ("web-v4.0.0", false), + ("v1.0.0", false), ] { release.tag_name = tag.into(); let expected = if expected_filtered { BTreeMap::from([ - ("web".into(), vec!["web".into(), "filtered".into()]), + ( + "releases".into(), + vec!["releases".into(), "filtered".into()], + ), ("another".into(), vec!["filtered".into()]), ]) } else { - BTreeMap::from([("web".into(), vec!["web".into()])]) + BTreeMap::from([("releases".into(), vec!["releases".into()])]) }; assert_eq!( - routing::destinations(&config, "actix/actix-web", &release), + routing::destinations(&config, "example/app", &release), expected, "{tag}" ); @@ -305,10 +308,10 @@ async fn routes_allow_all_tags_before_exclusions_when_inclusion_is_omitted_or_em toml::from_str(&format!( r#" name = "all" - repository = "actix/actix-web" + repository = "example/app" {inclusion} exclude_tags = ["^private-"] - destinations = ["web"] + destinations = ["releases"] "#, )) .unwrap(), @@ -318,7 +321,7 @@ async fn routes_allow_all_tags_before_exclusions_when_inclusion_is_omitted_or_em release.tag_name = tag.into(); assert_eq!( - routing::destinations(&config, "actix/actix-web", &release).contains_key("web"), + routing::destinations(&config, "example/app", &release).contains_key("releases"), expected_match, "{inclusion}: {tag}" ); @@ -331,42 +334,42 @@ async fn routes_union_destinations_and_include_prereleases_per_route() { let mut config = config(); config.routes.push(Route { name: "all".into(), - repository: "actix/actix-web".into(), + repository: "example/app".into(), include_tags: Vec::new(), exclude_tags: Vec::new(), include_prereleases: true, - destinations: vec!["web".into(), "another".into()], + destinations: vec!["releases".into(), "another".into()], }); let mut release: github::Release = serde_json::from_value(event()["release"].clone()).unwrap(); - let matched = routing::destinations(&config, "actix/actix-web", &release); + let matched = routing::destinations(&config, "example/app", &release); assert_eq!(matched.len(), 2); - assert_eq!(matched["web"], ["web", "all"]); + assert_eq!(matched["releases"], ["releases", "all"]); release.prerelease = true; assert_eq!( - routing::destinations(&config, "actix/actix-web", &release)["web"], + routing::destinations(&config, "example/app", &release)["releases"], ["all"] ); release.tag_name = "unprefixed".into(); assert_eq!( - routing::destinations(&config, "actix/actix-web", &release).len(), + routing::destinations(&config, "example/app", &release).len(), 2 ); - assert!(routing::destinations(&config, "actix/other", &release).is_empty()); + assert!(routing::destinations(&config, "example/other", &release).is_empty()); } #[actix_web::test] async fn embed_title_uses_only_the_release_name_and_links_to_the_release() { let mut release: github::Release = serde_json::from_value(event()["release"].clone()).unwrap(); - let message = discord::render("actix/actix-web", &release); + let message = discord::render("example/app", &release); let embed = &message.payload["embeds"][0]; - assert_eq!(embed["title"], "Actix Web 4.0.0"); + assert_eq!(embed["title"], "App 1.0.0"); assert_eq!(embed["url"], release.html_url); assert!(embed.get("timestamp").is_none()); release.name = None; - let message = discord::render("actix/actix-web", &release); - assert_eq!(message.payload["embeds"][0]["title"], "web-v4.0.0"); + let message = discord::render("example/app", &release); + assert_eq!(message.payload["embeds"][0]["title"], "v1.0.0"); } #[actix_web::test] @@ -452,7 +455,7 @@ async fn fake_discord_checks_payload_attachments_and_failure_classes() { actix_web::rt::spawn(server); let client = worker::client().unwrap(); let mut release: github::Release = serde_json::from_value(event()["release"].clone()).unwrap(); - let message = discord::render("actix/actix-web", &release); + let message = discord::render("example/app", &release); for path in ["ok", "limited", "transient", "permanent", "unconfirmed"] { let outcome = worker::send(&client, &format!("http://{address}/{path}"), &message, 1).await; assert!(match path { @@ -476,7 +479,7 @@ async fn fake_discord_checks_payload_attachments_and_failure_classes() { }); } release.body = Some("🚀\n".repeat(3000)); - let long = discord::render("actix/actix-web", &release); + let long = discord::render("example/app", &release); assert!(matches!( worker::send(&client, &format!("http://{address}/upload"), &long, 1).await, worker::Outcome::Sent @@ -508,15 +511,15 @@ async fn config_validates_references_and_redacts_secrets() { .unwrap(); let input = format!( r#" - [sources.org] - repositories = ["actix/actix-web"] + [sources.releases] + repositories = ["example/app"] secret = {{ file = {:?} }} - [destinations.web] + [destinations.releases] webhook = {{ file = {:?} }} [[routes]] - name = "web" - repository = "actix/actix-web" - destinations = ["web"] + name = "releases" + repository = "example/app" + destinations = ["releases"] "#, key.to_str().unwrap(), hook.to_str().unwrap() @@ -524,30 +527,33 @@ async fn config_validates_references_and_redacts_secrets() { let path = dir.path().join("config.toml"); std::fs::write(&path, &input).unwrap(); let loaded = Config::load(&path).unwrap(); - assert_eq!(loaded.sources["org"].key, "test-secret"); + assert_eq!(loaded.sources["releases"].key, "test-secret"); assert_eq!(loaded.bind, "0.0.0.0:8080"); assert!(loaded.routes[0].include_tags.is_empty()); assert!(loaded.routes[0].exclude_tags.is_empty()); for field in ["include_tags", "exclude_tags"] { - for patterns in ["[]", r#"["^web-derive-.*$", "-(internal|test)$"]"#] { + for patterns in ["[]", r#"["^app-derive-.*$", "-(internal|test)$"]"#] { std::fs::write(&path, format!("{input}\n{field} = {patterns}\n")).unwrap(); Config::load(&path).unwrap(); } } for invalid in [ - input.replace("destinations = [\"web\"]", "destinations = [\"missing\"]"), - input.replace("name = \"web\"", "name = \"\""), input.replace( - "repository = \"actix/actix-web\"", + "destinations = [\"releases\"]", + "destinations = [\"missing\"]", + ), + input.replace("name = \"releases\"", "name = \"\""), + input.replace( + "repository = \"example/app\"", "repository = \"other/repo\"", ), format!("unknown = \"private-token\"\n{input}"), - format!("{input}\ntag_prefix = \"web-\"\n"), - format!("{input}\ninclude_tags = [\"web-[\"]\n"), + format!("{input}\ntag_prefix = \"app-\"\n"), + format!("{input}\ninclude_tags = [\"app-[\"]\n"), format!("{input}\ninclude_tags = [\"private-token(\"]\n"), - format!("{input}\nexclude_tags = [\"web-[\"]\n"), + format!("{input}\nexclude_tags = [\"app-[\"]\n"), format!("{input}\nexclude_tags = [\"private-token(\"]\n"), ] { std::fs::write(&path, invalid).unwrap(); @@ -612,16 +618,16 @@ async fn worker_retries_fake_discord_and_finishes_active_send_on_shutdown() { actix_web::rt::spawn(server); let queue = Queue::default(); let mut config = config(); - config.destinations.get_mut("web").unwrap().url = format!("http://{address}/webhook"); + config.destinations.get_mut("releases").unwrap().url = format!("http://{address}/webhook"); let config = Arc::new(config); let release = serde_json::from_value(event()["release"].clone()).unwrap(); queue .enqueue( "worker-test", - "actix/actix-web", + "example/app", 123, - &routing::destinations(&config, "actix/actix-web", &release), - &discord::render("actix/actix-web", &release), + &routing::destinations(&config, "example/app", &release), + &discord::render("example/app", &release), ) .await .unwrap(); @@ -666,7 +672,7 @@ async fn chunked_size_limit_and_ambiguous_signature_headers_are_rejected() { ), ] { let mut builder = test::TestRequest::post() - .param("source", "org") + .param("source", "releases") .insert_header(("content-type", "application/json")) .app_data(Data::new(config())); for header in headers { @@ -686,7 +692,7 @@ async fn chunked_size_limit_and_ambiguous_signature_headers_are_rejected() { } let request = test::TestRequest::post() - .param("source", "org") + .param("source", "releases") .insert_header(("content-type", "application/json")) .insert_header(("x-hub-signature-256", sign(body))) .app_data(Data::new(config())) @@ -716,11 +722,11 @@ async fn chunked_size_limit_and_ambiguous_signature_headers_are_rejected() { async fn queue_deduplicates_retries_and_resets_on_restart() { let queue = Queue::default(); let release = serde_json::from_value(event()["release"].clone()).unwrap(); - let message = discord::render("actix/actix-web", &release); - let destinations = routing::destinations(&config(), "actix/actix-web", &release); + let message = discord::render("example/app", &release); + let destinations = routing::destinations(&config(), "example/app", &release); assert_eq!( queue - .enqueue("first", "actix/actix-web", 123, &destinations, &message) + .enqueue("first", "example/app", 123, &destinations, &message) .await .unwrap() .jobs_inserted, @@ -728,7 +734,7 @@ async fn queue_deduplicates_retries_and_resets_on_restart() { ); assert!( !queue - .enqueue("first", "actix/actix-web", 123, &destinations, &message) + .enqueue("first", "example/app", 123, &destinations, &message) .await .unwrap() .delivery_inserted @@ -738,7 +744,7 @@ async fn queue_deduplicates_retries_and_resets_on_restart() { assert!(queue.claim().await.is_none()); assert_eq!( queue - .enqueue("second", "actix/actix-web", 123, &destinations, &message) + .enqueue("second", "example/app", 123, &destinations, &message) .await .unwrap() .jobs_inserted, @@ -746,7 +752,7 @@ async fn queue_deduplicates_retries_and_resets_on_restart() { ); queue.finish(job, true, 10, false, true).await; queue - .enqueue("other", "actix/actix-web", 124, &destinations, &message) + .enqueue("other", "example/app", 124, &destinations, &message) .await .unwrap(); assert!(queue.claim().await.is_none()); @@ -759,7 +765,7 @@ async fn queue_deduplicates_retries_and_resets_on_restart() { queue.finish(retry, false, 0, true, false).await; assert_eq!( queue - .enqueue("third", "actix/actix-web", 123, &destinations, &message) + .enqueue("third", "example/app", 123, &destinations, &message) .await .unwrap() .jobs_inserted, @@ -770,7 +776,7 @@ async fn queue_deduplicates_retries_and_resets_on_restart() { assert!(restarted.claim().await.is_none()); assert_eq!( restarted - .enqueue("first", "actix/actix-web", 123, &destinations, &message) + .enqueue("first", "example/app", 123, &destinations, &message) .await .unwrap() .jobs_inserted, @@ -780,7 +786,7 @@ async fn queue_deduplicates_retries_and_resets_on_restart() { tokio::time::advance(std::time::Duration::from_secs(30 * 24 * 60 * 60)).await; assert_eq!( queue - .enqueue("first", "actix/actix-web", 123, &destinations, &message) + .enqueue("first", "example/app", 123, &destinations, &message) .await .unwrap() .jobs_inserted, @@ -792,13 +798,13 @@ async fn queue_deduplicates_retries_and_resets_on_restart() { async fn full_queue_rejects_atomically_and_failed_jobs_allow_redelivery() { let queue = Queue::default(); let release = serde_json::from_value(event()["release"].clone()).unwrap(); - let message = discord::render("actix/actix-web", &release); - let destinations = routing::destinations(&config(), "actix/actix-web", &release); + let message = discord::render("example/app", &release); + let destinations = routing::destinations(&config(), "example/app", &release); for id in 0..63 { queue .enqueue( &format!("fill-{id}"), - "actix/actix-web", + "example/app", id, &destinations, &message, @@ -806,9 +812,9 @@ async fn full_queue_rejects_atomically_and_failed_jobs_allow_redelivery() { .await .unwrap(); } - let two = BTreeMap::from([("web".into(), vec![]), ("other".into(), vec![])]); + let two = BTreeMap::from([("releases".into(), vec![]), ("other".into(), vec![])]); let error = queue - .enqueue("overflow", "actix/actix-web", 100, &two, &message) + .enqueue("overflow", "example/app", 100, &two, &message) .await .err() .unwrap(); @@ -817,14 +823,14 @@ async fn full_queue_rejects_atomically_and_failed_jobs_allow_redelivery() { // An in-flight job still consumes capacity. assert!( queue - .enqueue("overflow", "actix/actix-web", 100, &two, &message) + .enqueue("overflow", "example/app", 100, &two, &message) .await .is_err() ); queue.finish(job, false, 0, false, false).await; assert_eq!( queue - .enqueue("overflow", "actix/actix-web", 100, &two, &message) + .enqueue("overflow", "example/app", 100, &two, &message) .await .unwrap() .jobs_inserted, @@ -835,7 +841,7 @@ async fn full_queue_rejects_atomically_and_failed_jobs_allow_redelivery() { queue.finish(job, false, 0, false, false).await; assert_eq!( queue - .enqueue(&delivery, "actix/actix-web", 1, &destinations, &message) + .enqueue(&delivery, "example/app", 1, &destinations, &message) .await .unwrap() .jobs_inserted, @@ -847,13 +853,13 @@ async fn full_queue_rejects_atomically_and_failed_jobs_allow_redelivery() { async fn full_queue_returns_503_and_accepts_the_same_delivery_after_capacity_frees() { let queue = Queue::default(); let release = serde_json::from_value(event()["release"].clone()).unwrap(); - let message = discord::render("actix/actix-web", &release); - let destinations = routing::destinations(&config(), "actix/actix-web", &release); + let message = discord::render("example/app", &release); + let destinations = routing::destinations(&config(), "example/app", &release); for id in 0..64 { queue .enqueue( &format!("fill-{id}"), - "actix/actix-web", + "example/app", id, &destinations, &message, @@ -872,7 +878,7 @@ async fn full_queue_returns_503_and_accepts_the_same_delivery_after_capacity_fre for expected in [503, 202] { let body = event().to_string(); let request = test::TestRequest::post() - .uri("/webhooks/github/org") + .uri("/webhooks/github/releases") .insert_header(("content-type", "application/json")) .insert_header(("x-hub-signature-256", sign(body.as_bytes()))) .insert_header(("x-github-delivery", "overflow")) @@ -899,11 +905,11 @@ async fn full_queue_returns_503_and_accepts_the_same_delivery_after_capacity_fre async fn redelivery_retries_only_failed_destinations() { let queue = Queue::default(); let release = serde_json::from_value(event()["release"].clone()).unwrap(); - let message = discord::render("actix/actix-web", &release); + let message = discord::render("example/app", &release); let destinations = BTreeMap::from([("a".into(), vec![]), ("b".into(), vec![])]); let (first, duplicate) = tokio::join!( - queue.enqueue("delivery", "actix/actix-web", 123, &destinations, &message), - queue.enqueue("delivery", "actix/actix-web", 123, &destinations, &message), + queue.enqueue("delivery", "example/app", 123, &destinations, &message), + queue.enqueue("delivery", "example/app", 123, &destinations, &message), ); assert_eq!( first.unwrap().jobs_inserted + duplicate.unwrap().jobs_inserted, @@ -916,7 +922,7 @@ async fn redelivery_retries_only_failed_destinations() { queue.finish(failed, false, 0, false, false).await; assert_eq!( queue - .enqueue("delivery", "actix/actix-web", 123, &destinations, &message) + .enqueue("delivery", "example/app", 123, &destinations, &message) .await .unwrap() .jobs_inserted,