Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Jun 7, 2024
1 parent 7dd5efe commit 25a2244
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ A Cloudflare Worker for managing ZLS build artifacts.

The API Endpoint is `releases.zigtools.org`.

## /v1/select-zls-version?zig_version=${VERSION}
## /v1/select-zls-version?zig_version=${VERSION}&compatibility=${COMPATIBILITY}

> [!IMPORTANT]
> If you are developing a tool that automatically installs ZLS then you came to the right place!
Will respond with metadata about a ZLS build that is compatible with the given Zig version.
Will respond with metadata about a ZLS build that is useable with the given Zig version.
The response body is similar to Zig's [index.json](https://ziglang.org/download/index.json).

The `compatibility` query-string must be either `only-runtime` or `full`:

- `full`: Request a ZLS build that can be built and used with the given Zig version.
- `only-runtime`: Request a ZLS build that can be used at runtime with the given Zig version but may not be able to build ZLS from source.

<details>
<summary>Example 1</summary>

```bash
curl "https://releases.zigtools.org/v1/select-zls-version?zig_version=0.13.0-dev.7%2B73c6c13a" # 0.13.0-dev.7+73c6c13a
curl "https://releases.zigtools.org/v1/select-zls-version?zig_version=0.13.0-dev.7%2B73c6c13a&compatibility=only-runtime" # 0.13.0-dev.7+73c6c13a
```

```json
Expand Down Expand Up @@ -225,7 +230,7 @@ The response body imitates Zig's [index.json](https://ziglang.org/download/index

</details>

## /v1/publish
## /publish

> [!IMPORTANT]
> This request is only intended to be used by ZLS's GitHub CI.
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
switch (url.pathname) {
case "/v1/select-zls-version":
return handleSelectZLSVersion(request, env);
case "/v1/publish":
case "/publish":
return handlePublish(request, env);
default:
return new Response(null, {
Expand Down
20 changes: 10 additions & 10 deletions test/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function searchZLSRelease(
async function sendPublishForm(form: FormData): Promise<Response> {
assert(typeof env.API_TOKEN === "string" && env.API_TOKEN);
return await SELF.fetch(
new Request("https://example.com/v1/publish", {
new Request("https://example.com/publish", {
body: form,
method: "POST",
headers: {
Expand Down Expand Up @@ -104,9 +104,9 @@ function getSampleArtifacts(
];
}

describe("/v1/publish", () => {
describe("/publish", () => {
test("expect POST method", async () => {
const response = await SELF.fetch("https://example.com/v1/publish");
const response = await SELF.fetch("https://example.com/publish");
expect(await response.text()).toBe("method must be 'POST'");
expect(response.status).toBe(405);
});
Expand All @@ -115,7 +115,7 @@ describe("/v1/publish", () => {
"check for invalid API_TOKEN: %j",
async (value) => {
const response = await handlePublish(
new Request("https://example.com/v1/publish", {
new Request("https://example.com/publish", {
method: "POST",
}),
{
Expand All @@ -131,7 +131,7 @@ describe("/v1/publish", () => {

describe("check authorization", () => {
test("missing Authorization header", async () => {
const response = await SELF.fetch("https://example.com/v1/publish", {
const response = await SELF.fetch("https://example.com/publish", {
method: "POST",
});

Expand All @@ -140,7 +140,7 @@ describe("/v1/publish", () => {
});

test("invalid Authorization header", async () => {
const response = await SELF.fetch("https://example.com/v1/publish", {
const response = await SELF.fetch("https://example.com/publish", {
body: null,
method: "POST",
headers: {
Expand All @@ -154,7 +154,7 @@ describe("/v1/publish", () => {
});

test("non Basic Authorization header", async () => {
const response = await SELF.fetch("https://example.com/v1/publish", {
const response = await SELF.fetch("https://example.com/publish", {
body: null,
method: "POST",
headers: {
Expand All @@ -168,7 +168,7 @@ describe("/v1/publish", () => {
});

test("invalid Basic Authorization header", async () => {
const response = await SELF.fetch("https://example.com/v1/publish", {
const response = await SELF.fetch("https://example.com/publish", {
body: null,
method: "POST",
headers: {
Expand All @@ -182,7 +182,7 @@ describe("/v1/publish", () => {
});

test("wrong username", async () => {
const response = await SELF.fetch("https://example.com/v1/publish", {
const response = await SELF.fetch("https://example.com/publish", {
body: null,
method: "POST",
headers: {
Expand All @@ -194,7 +194,7 @@ describe("/v1/publish", () => {
});

test("wrong password", async () => {
const response = await SELF.fetch("https://example.com/v1/publish", {
const response = await SELF.fetch("https://example.com/publish", {
body: null,
method: "POST",
headers: {
Expand Down

0 comments on commit 25a2244

Please sign in to comment.