Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions .github/PUBLISHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<version>/` 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/<version>/` 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://<account ID>.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. 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`.

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. 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 `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

Expand All @@ -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.
52 changes: 34 additions & 18 deletions .github/workflows/publish-development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -197,32 +206,34 @@ 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

- 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

Expand All @@ -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' \
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ permissions:
id-token: write

env:
PIXELY_FEED_URL: https://nuget.stanoddly.dev
PIXELY_VERSION_HEIGHT_OFFSET: '-281'

jobs:
Expand Down Expand Up @@ -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"
Expand All @@ -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" \
Expand Down