From 9189b960da3653cfdc24718eab065d68888c29cf Mon Sep 17 00:00:00 2001 From: botoddly <250804054+botoddly@users.noreply.github.com> Date: Sat, 21 Nov 2026 21:49:38 +0100 Subject: [PATCH 1/2] Publish the development feed to Cloudflare R2 behind nuget.stanoddly.dev instead of Backblaze B2 --- .github/PUBLISHING.md | 38 +++++++++++------ .github/workflows/publish-development.yml | 52 +++++++++++++++-------- .github/workflows/publish-nuget.yml | 9 ++-- 3 files changed, 63 insertions(+), 36 deletions(-) diff --git a/.github/PUBLISHING.md b/.github/PUBLISHING.md index 5160e51a..d2cb2e7c 100644 --- a/.github/PUBLISHING.md +++ b/.github/PUBLISHING.md @@ -4,31 +4,41 @@ Pixely is packed once for every `main` commit. The resulting package is publishe ## Development feed -Pull requests run the complete build, test, integration, NativeAOT, and package-consumer slice on Linux ARM64. After merge, the **Publish to development feed** workflow packs the commit and publishes the `.nupkg` through Sleet as soon as the pack finishes, storing the matching `.snupkg` and checksum manifest under `promotion/pixely//` in B2. In parallel, it runs the full validation on Linux x64, Windows x64, and macOS ARM64 and validates the canonical package through isolated consumers on those three platforms. A development version can therefore be on the feed while its validation is still running or has failed. Publication attempts are serialized, reruns reuse the first stored files, and existing content is never overwritten. +Pull requests run the complete build, test, integration, NativeAOT, and package-consumer slice on Linux ARM64. After merge, the **Publish to development feed** workflow packs the commit and publishes the `.nupkg` through Sleet as soon as the pack finishes, storing the matching `.snupkg` and checksum manifest under `promotion/pixely//` in the R2 bucket. In parallel, it runs the full validation on Linux x64, Windows x64, and macOS ARM64 and validates the canonical package through isolated consumers on those three platforms. A development version can therefore be on the feed while its validation is still running or has failed. Publication attempts are serialized, reruns reuse the first stored files, and existing content is never overwritten. The merged pull request receives two comments. The publish job posts the version and a direct package download link as soon as the package is on the feed. When the whole run completes, the **Report development publication** workflow posts the platform validation result, naming the failed jobs, and a link to the run. Each rerun is reported separately. Both use the temporary repository-scoped `GITHUB_TOKEN`; they require no additional secrets. Versions use the form `0.0.N`. The source commit's absolute first-parent height plus the fixed migration offset `-281` determines `N`, making the first automatically published `main` commit version `0.0.9`; every later first-parent commit increments `N`. The package repository metadata records the complete source commit. -Cloudflare Pages hosts the service index at `https://nuget.stanoddly.dev/index.json`. Its resource URLs point to the public `pixely` Backblaze B2 bucket, so adding packages or versions does not require another Pages deployment. +The feed is served at `https://nuget.stanoddly.dev/index.json` from the Cloudflare R2 bucket `nuget` through its custom domain, with Cloudflare's cache in front. The bucket can hold other packages in the same feed. -## B2 configuration +## R2 configuration The bucket has these settings: -- name: `pixely` -- S3 endpoint: `https://s3.eu-central-003.backblazeb2.com` -- public file access -- lifecycle: keep only the last version of each file +- name: `nuget` +- S3 endpoint: `https://.r2.cloudflarestorage.com` +- default storage class: Standard +- custom domain: `nuget.stanoddly.dev` +- public development URL (`r2.dev`): disabled -Create a bucket-restricted application key with Read and Write access, no filename prefix, and **Allow List All Bucket Names** enabled. Add its values as these GitHub Actions repository secrets: +Create an Account API token for R2 with **Object Read & Write** on the `nuget` bucket only. Add these GitHub Actions repository secrets: -- `B2_KEY_ID`: application key ID -- `B2_APPLICATION_KEY`: application key secret +- `R2_ACCOUNT_ID`: the Cloudflare account ID +- `R2_ACCESS_KEY_ID`: the token's access key ID +- `R2_SECRET_ACCESS_KEY`: the token's secret access key -The workflow installs Sleet 7.2.0 and creates its configuration in the runner's temporary directory. The key needs read, list, write, and delete access because Sleet reads feed state and creates and removes a root `.feedlock` while publishing. If Object Lock is enabled on the bucket, do not apply default retention to feed files because it would prevent Sleet from removing this lock. +The workflow installs Sleet 7.2.0 and creates its configuration in the runner's temporary directory. The token needs read, list, write, and delete access because Sleet reads feed state and creates and removes a root `.feedlock` while publishing. R2 does not support the AWS SDK's streaming uploads, so the configuration sets `disablePayloadSigning` and the workflow sets `AWS_REQUEST_CHECKSUM_CALCULATION` and `AWS_RESPONSE_CHECKSUM_VALIDATION` to `when_required`. -To rotate the credential, create a replacement with the same restrictions, update both GitHub secrets, wait for or rerun a successful development publication, and then delete the previous key. +Sleet uploads packages and other versioned files with `Cache-Control: public, max-age=31536000, immutable` and feed JSON with `Cache-Control: public, max-age=60`. Promotion files use the immutable value. The `stanoddly.dev` zone has these rules for `nuget.stanoddly.dev`: + +- a Cache Rule that makes requests eligible for cache, with Edge TTL set to use the `Cache-Control` header if present and bypass the cache if not, and Browser TTL set to respect the origin +- Smart Tiered Cache +- a URL Rewrite Rule that serves `/index.json` for `/` + +Missing files return 404 without `Cache-Control`, so a 404 is never cached and a new package is readable as soon as it is uploaded. + +To rotate the credential, create a replacement with the same restrictions, update both key secrets, wait for or rerun a successful development publication, and then delete the previous token. ## nuget.org configuration @@ -44,10 +54,10 @@ No NuGet API key is stored in GitHub. If nuget.org marks a new policy as pending Open **Actions**, select **Publish to nuget.org**, and enter an exact version already present in the development feed. The version must advance beyond the highest numbered Pixely version on nuget.org unless the run is recovering that same version. -The workflow downloads the `.nupkg`, `.snupkg`, and manifest from B2, verifies their SHA-256 hashes, validates the version-to-commit mapping, requires a successful **Publish to development feed** run for the source commit, and publishes the existing files through nuget.org trusted publishing. It does not build or pack. After publication, it tags the recorded source commit and creates the GitHub release. Not every development version needs to be published, so the nuget.org sequence can contain gaps. +The workflow downloads the `.nupkg`, `.snupkg`, and manifest from the development feed, verifies their SHA-256 hashes, validates the version-to-commit mapping, requires a successful **Publish to development feed** run for the source commit, and publishes the existing files through nuget.org trusted publishing. It does not build or pack. After publication, it tags the recorded source commit and creates the GitHub release. Not every development version needs to be published, so the nuget.org sequence can contain gaps. ## Recovery -Development-feed publication is idempotent. Rerunning the same `main` workflow uses the same version, Sleet skips its existing package, and the workflow reuses the first stored package and symbol archives as the canonical publication artifacts. It verifies their version and source commit before deriving the immutable checksum manifest. +Development-feed publication is idempotent. Rerunning the same `main` workflow uses the same version, Sleet skips its existing package, and the workflow reuses the first stored package and symbol archives as the canonical publication artifacts. It verifies their version and source commit before deriving the immutable checksum manifest. Do not rerun a run from before the move to R2: a rerun uses its original workflow file, which publishes to Backblaze B2. Publishing to nuget.org is also rerunnable. Duplicate uploads are skipped, an existing tag must point to the recorded source commit, and an existing GitHub release is retained. A checksum, version, commit, or tag mismatch stops the workflow instead of modifying published state. diff --git a/.github/workflows/publish-development.yml b/.github/workflows/publish-development.yml index a1b44673..a5524546 100644 --- a/.github/workflows/publish-development.yml +++ b/.github/workflows/publish-development.yml @@ -8,7 +8,9 @@ permissions: contents: read env: + PIXELY_FEED_URL: https://nuget.stanoddly.dev PIXELY_VERSION_HEIGHT_OFFSET: '-281' + R2_BUCKET: nuget jobs: platform-validation: @@ -164,25 +166,32 @@ jobs: - name: Publish package to development feed shell: bash env: - B2_APPLICATION_KEY: ${{ secrets.B2_APPLICATION_KEY }} - B2_KEY_ID: ${{ secrets.B2_KEY_ID }} + # R2 does not support the streaming SigV4 uploads and default checksums of the AWS SDK. + AWS_REQUEST_CHECKSUM_CALCULATION: when_required + AWS_RESPONSE_CHECKSUM_VALIDATION: when_required + R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} + R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }} + R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} run: | set -euo pipefail - if [[ -z "$B2_KEY_ID" || -z "$B2_APPLICATION_KEY" ]]; then - echo "B2_KEY_ID and B2_APPLICATION_KEY repository secrets are required." + if [[ -z "$R2_ACCOUNT_ID" || -z "$R2_ACCESS_KEY_ID" || -z "$R2_SECRET_ACCESS_KEY" ]]; then + echo "R2_ACCOUNT_ID, R2_ACCESS_KEY_ID and R2_SECRET_ACCESS_KEY repository secrets are required." exit 1 fi sleet_config="$RUNNER_TEMP/sleet.json" jq --null-input \ - '{sources: [{name: "pixely", type: "s3", path: "https://pixely.s3.eu-central-003.backblazeb2.com/", baseURI: "https://pixely.s3.eu-central-003.backblazeb2.com/", bucketName: "pixely", serviceURL: "https://s3.eu-central-003.backblazeb2.com", accessKeyId: "$B2_KEY_ID$", secretAccessKey: "$B2_APPLICATION_KEY$"}]}' \ + --arg feedUrl "$PIXELY_FEED_URL/" \ + --arg bucketName "$R2_BUCKET" \ + --arg serviceUrl "https://$R2_ACCOUNT_ID.r2.cloudflarestorage.com" \ + '{sources: [{name: "nuget", type: "s3", path: $feedUrl, baseURI: $feedUrl, bucketName: $bucketName, serviceURL: $serviceUrl, accessKeyId: "$R2_ACCESS_KEY_ID$", secretAccessKey: "$R2_SECRET_ACCESS_KEY$", disablePayloadSigning: true, immutableCacheControl: "public, max-age=31536000, immutable", mutableCacheControl: "public, max-age=60"}]}' \ > "$sleet_config" "$RUNNER_TEMP/dotnet-tools/sleet" push \ "artifacts/package-to-publish/Pixely.$PIXELY_VERSION.nupkg" \ --config "$sleet_config" \ - --source pixely \ + --source nuget \ --skip-existing - name: Report package availability @@ -197,7 +206,7 @@ jobs: set -euo pipefail pull_request_number="$(gh api "repos/$REPOSITORY/commits/$REPOSITORY_COMMIT/pulls" --jq '.[0].number')" - package_url="https://pixely.s3.eu-central-003.backblazeb2.com/flatcontainer/pixely/$PIXELY_VERSION/pixely.$PIXELY_VERSION.nupkg" + package_url="$PIXELY_FEED_URL/flatcontainer/pixely/$PIXELY_VERSION/pixely.$PIXELY_VERSION.nupkg" message="$(printf '📦 Development package [`Pixely %s`](%s) is available.' "$PIXELY_VERSION" "$package_url")" body="$(printf '%s\n\n[Workflow run (attempt %s)](%s)' "$message" "$RUN_ATTEMPT" "$RUN_URL")" gh api --method POST "repos/$REPOSITORY/issues/$pull_request_number/comments" --field body="$body" >/dev/null @@ -205,24 +214,26 @@ jobs: - name: Store promotion artifacts shell: bash env: - AWS_ACCESS_KEY_ID: ${{ secrets.B2_KEY_ID }} - AWS_DEFAULT_REGION: eu-central-003 + AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} + AWS_DEFAULT_REGION: auto AWS_REQUEST_CHECKSUM_CALCULATION: when_required AWS_RESPONSE_CHECKSUM_VALIDATION: when_required - AWS_SECRET_ACCESS_KEY: ${{ secrets.B2_APPLICATION_KEY }} - B2_S3_ENDPOINT: https://s3.eu-central-003.backblazeb2.com + AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} + R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }} REPOSITORY_COMMIT: ${{ github.sha }} run: | set -euo pipefail + s3_endpoint="https://$R2_ACCOUNT_ID.r2.cloudflarestorage.com" + get_object() { local key="$2" local head_error local target="$1" head_error="$(mktemp)" - if aws --endpoint-url "$B2_S3_ENDPOINT" s3api head-object --bucket pixely --key "$key" >/dev/null 2>"$head_error"; then - aws --endpoint-url "$B2_S3_ENDPOINT" s3api get-object --bucket pixely --key "$key" "$target" >/dev/null + if aws --endpoint-url "$s3_endpoint" s3api head-object --bucket "$R2_BUCKET" --key "$key" >/dev/null 2>"$head_error"; then + aws --endpoint-url "$s3_endpoint" s3api get-object --bucket "$R2_BUCKET" --key "$key" "$target" >/dev/null return 0 fi @@ -239,8 +250,8 @@ jobs: local key="$2" local content_type="$3" - aws --endpoint-url "$B2_S3_ENDPOINT" s3api put-object \ - --bucket pixely \ + aws --endpoint-url "$s3_endpoint" s3api put-object \ + --bucket "$R2_BUCKET" \ --key "$key" \ --body "$source" \ --cache-control 'public, max-age=31536000, immutable' \ @@ -264,13 +275,18 @@ jobs: nupkg="$promotion_directory/Pixely.$PIXELY_VERSION.nupkg" snupkg="$promotion_directory/Pixely.$PIXELY_VERSION.snupkg" manifest="$promotion_directory/manifest.json" - nupkg_url="https://pixely.s3.eu-central-003.backblazeb2.com/flatcontainer/pixely/$PIXELY_VERSION/pixely.$PIXELY_VERSION.nupkg" - snupkg_url="https://pixely.s3.eu-central-003.backblazeb2.com/$promotion_prefix/Pixely.$PIXELY_VERSION.snupkg" + package_key="flatcontainer/pixely/$PIXELY_VERSION/pixely.$PIXELY_VERSION.nupkg" symbol_key="$promotion_prefix/Pixely.$PIXELY_VERSION.snupkg" manifest_key="$promotion_prefix/manifest.json" + nupkg_url="$PIXELY_FEED_URL/$package_key" + snupkg_url="$PIXELY_FEED_URL/$symbol_key" mkdir -p "$promotion_directory" - curl --fail --silent --show-error "$nupkg_url" --output "$nupkg" + # The feed's stored package is canonical; reading it through the S3 API keeps the CDN cache out of the check. + if ! get_object "$nupkg" "$package_key"; then + echo "The feed does not contain $package_key." + exit 1 + fi validate_package "$nupkg" if get_object "$snupkg" "$symbol_key"; then diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml index c2c22546..a418df54 100644 --- a/.github/workflows/publish-nuget.yml +++ b/.github/workflows/publish-nuget.yml @@ -18,6 +18,7 @@ permissions: id-token: write env: + PIXELY_FEED_URL: https://nuget.stanoddly.dev PIXELY_VERSION_HEIGHT_OFFSET: '-281' jobs: @@ -48,8 +49,8 @@ jobs: fi promotion_directory="artifacts/promotion" - promotion_url="https://pixely.s3.eu-central-003.backblazeb2.com/promotion/pixely/$PIXELY_VERSION" - package_url="https://pixely.s3.eu-central-003.backblazeb2.com/flatcontainer/pixely/$PIXELY_VERSION/pixely.$PIXELY_VERSION.nupkg" + promotion_url="$PIXELY_FEED_URL/promotion/pixely/$PIXELY_VERSION" + package_url="$PIXELY_FEED_URL/flatcontainer/pixely/$PIXELY_VERSION/pixely.$PIXELY_VERSION.nupkg" mkdir -p "$promotion_directory" curl --fail --silent --show-error "$promotion_url/manifest.json" --output "$promotion_directory/manifest.json" curl --fail --silent --show-error "$package_url" --output "$promotion_directory/Pixely.$PIXELY_VERSION.nupkg" @@ -65,8 +66,8 @@ jobs: manifest="$promotion_directory/manifest.json" nupkg="$promotion_directory/Pixely.$PIXELY_VERSION.nupkg" snupkg="$promotion_directory/Pixely.$PIXELY_VERSION.snupkg" - expected_nupkg_url="https://pixely.s3.eu-central-003.backblazeb2.com/flatcontainer/pixely/$PIXELY_VERSION/pixely.$PIXELY_VERSION.nupkg" - expected_snupkg_url="https://pixely.s3.eu-central-003.backblazeb2.com/promotion/pixely/$PIXELY_VERSION/Pixely.$PIXELY_VERSION.snupkg" + expected_nupkg_url="$PIXELY_FEED_URL/flatcontainer/pixely/$PIXELY_VERSION/pixely.$PIXELY_VERSION.nupkg" + expected_snupkg_url="$PIXELY_FEED_URL/promotion/pixely/$PIXELY_VERSION/Pixely.$PIXELY_VERSION.snupkg" jq --exit-status \ --arg packageVersion "$PIXELY_VERSION" \ --arg nupkgUrl "$expected_nupkg_url" \ From 672cd84af45df98cc8dc430ec79fdc649b5fac0f Mon Sep 17 00:00:00 2001 From: botoddly <250804054+botoddly@users.noreply.github.com> Date: Sat, 21 Nov 2026 22:00:22 +0100 Subject: [PATCH 2/2] Clarify cache timing, secret rotation and bucket locks in the R2 publishing notes --- .github/PUBLISHING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/PUBLISHING.md b/.github/PUBLISHING.md index d2cb2e7c..7d660c0d 100644 --- a/.github/PUBLISHING.md +++ b/.github/PUBLISHING.md @@ -28,7 +28,7 @@ Create an Account API token for R2 with **Object Read & Write** on the `nuget` b - `R2_ACCESS_KEY_ID`: the token's access key ID - `R2_SECRET_ACCESS_KEY`: the token's secret access key -The workflow installs Sleet 7.2.0 and creates its configuration in the runner's temporary directory. The token needs read, list, write, and delete access because Sleet reads feed state and creates and removes a root `.feedlock` while publishing. R2 does not support the AWS SDK's streaming uploads, so the configuration sets `disablePayloadSigning` and the workflow sets `AWS_REQUEST_CHECKSUM_CALCULATION` and `AWS_RESPONSE_CHECKSUM_VALIDATION` to `when_required`. +The workflow installs Sleet 7.2.0 and creates its configuration in the runner's temporary directory. The token needs read, list, write, and delete access because Sleet reads feed state and creates and removes a root `.feedlock` while publishing. Do not add a bucket lock rule that covers `.feedlock` because it would prevent Sleet from removing this lock. R2 does not support the AWS SDK's streaming uploads, so the configuration sets `disablePayloadSigning` and the workflow sets `AWS_REQUEST_CHECKSUM_CALCULATION` and `AWS_RESPONSE_CHECKSUM_VALIDATION` to `when_required`. Sleet uploads packages and other versioned files with `Cache-Control: public, max-age=31536000, immutable` and feed JSON with `Cache-Control: public, max-age=60`. Promotion files use the immutable value. The `stanoddly.dev` zone has these rules for `nuget.stanoddly.dev`: @@ -36,9 +36,9 @@ Sleet uploads packages and other versioned files with `Cache-Control: public, ma - Smart Tiered Cache - a URL Rewrite Rule that serves `/index.json` for `/` -Missing files return 404 without `Cache-Control`, so a 404 is never cached and a new package is readable as soon as it is uploaded. +Missing files return 404 without `Cache-Control`, so a 404 is never cached. A new version's files are readable as soon as they are uploaded, and the version list shows it within a minute. -To rotate the credential, create a replacement with the same restrictions, update both key secrets, wait for or rerun a successful development publication, and then delete the previous token. +To rotate the credential, create a replacement with the same restrictions, update `R2_ACCESS_KEY_ID` and `R2_SECRET_ACCESS_KEY`, wait for or rerun a successful development publication, and then delete the previous token. ## nuget.org configuration