1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

added auto readme update, announceybot fixes

This commit is contained in:
Rene Schallner 2023-05-22 01:48:31 +02:00
parent b8e00f3a72
commit 27ab749281
5 changed files with 126 additions and 28 deletions

View file

@ -31,7 +31,7 @@ Here's what works:
- **[hello](examples/hello/hello.zig)**: welcomes you with some static
HTML
- **[routes](examples/routes/routes.zig)**: a super easy example
dispatching on the HTTP path
dispatching on the HTTP path
- **[serve](examples/serve/serve.zig)**: the traditional static web
server with optional dynamic request handling
- **[sendfile](examples/sendfile/sendfile.zig)**: simple example of how to send
@ -112,18 +112,18 @@ See more details in [blazingly-fast.md](blazingly-fast.md).
```shell
$ git clone https://github.com/zigzap/zap.git
$ cd zap
$ cd zap
$ zig build run-hello
$ # open http://localhost:3000 in your browser
```
... and open [http://localhost:3000](http://locahhost:3000) in your browser.
## Using ⚡zap⚡ in your own projects
## Using ⚡zap⚡ in your own projects
If you don't have an existing zig project, create one like this:
```shell
```shell
$ mkdir zaptest && cd zaptest
$ zig init-exe
$ git init ## (optional)
@ -138,30 +138,33 @@ fetch zig master.
With an existing zig project, adding zap to it is easy:
1. Add zap to your `build.zig.zon`
2. Add zap to your `build.zig`
1. Add zap to your `build.zig.zon`
2. Add zap to your `build.zig`
To add zap to `build.zig.zon`:
```zig
<!-- INSERT_DEP_BEGIN -->
```zig
.{
.name = "myapp",
.name = "My example project",
.version = "0.0.1",
.dependencies = .{
// zap release-0.0.24
// zap release-0.0.23
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/release-0.0.24.tar.gz",
.hash = "1220f520fcdd4b3adbca918deeb42f512f7ef4a827680eea8af9abc64b90ed7a5e78",
.url = "https://github.com/zigzap/zap/archive/refs/tags/release-0.0.23.tar.gz",
.hash = "122001f1a749bdeba74be3e89f60730aa630c5e706eba1d7f91e225a87429005cffc",
}
}
}
```
<!-- INSERT_DEP_END -->
Then, in your `build.zig`'s `build` function, add the following before
`b.installArtifact(exe)``:
```zig
```zig
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
@ -175,7 +178,7 @@ examples to see how to use zap.
## Updating your project to the latest version of zap
You can change the URL to zap in your `build.zig.zon`
You can change the URL to zap in your `build.zig.zon`
- easiest: use a tagged release
- or to one of the tagged versions, e.g. `0.0.9`
@ -196,12 +199,12 @@ to copy the URL to put into your `build.zig.zon`.
After changing the `.url` field, you will get an error like this at the next
attempt to `zig build`:
```
.../build.zig.zon:8:21: error: hash mismatch:
expected: 12205fd0b60720fb2a40d82118ee75c15cb5589bb9faf901c8a39a93551dd6253049,
found: 1220f4ea8be4a85716ae1362d34c077dca10f10d1baf9196fc890e658c56f78b7424
```
.../build.zig.zon:8:21: error: hash mismatch:
expected: 12205fd0b60720fb2a40d82118ee75c15cb5589bb9faf901c8a39a93551dd6253049,
found: 1220f4ea8be4a85716ae1362d34c077dca10f10d1baf9196fc890e658c56f78b7424
.hash = "12205fd0b60720fb2a40d82118ee75c15cb5589bb9faf901c8a39a93551dd6253049",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
**Note:** If you don't get this error, clean your global zig cache: `rm -fr
@ -243,7 +246,7 @@ You can also reach me on [the zig showtime discord
server](https://discord.gg/CBzE3VMb) under the handle renerocksai
(renerocksai#1894).
## Support ⚡zap⚡
## Support ⚡zap⚡
Being blazingly fast requires a constant feed of caffeine. I usually manage to
provide that to myself for myself. However, to support keeping the juices
@ -265,8 +268,8 @@ $ ./zig-out/bin/[EXAMPLE]
Example: building and running the hello example:
```shell
$ zig build hello
```shell
$ zig build hello
$ ./zig-out/bin/hello
```
@ -315,5 +318,4 @@ pub fn main() !void {
.workers = 2,
});
}
```
```

View file

@ -2,6 +2,7 @@ import sys
import os
from discord_webhook import DiscordWebhook
from git import Repo
import subprocess
URL = os.getenv("WEBHOOK_URL")
TAG_NAME = os.getenv("TAG_NAME", sys.argv[1])
@ -17,17 +18,36 @@ def send_to_discord(message):
def get_tag_annotation(tagname):
repo = Repo('../..')
repo = Repo('.')
tag = repo.tags[tagname]
return tag.tag.message
def get_replacement():
ret = subprocess.run([
"./zig-out/bin/pkghash",
"-g", f"--tag={TAG_NAME}",
"--template=./tools/announceybot/release-dep-update-template.md",
], capture_output=True)
text = ret.stdout.decode("utf-8")
return text
if __name__ == '__main__':
annotation = get_tag_annotation(TAG_NAME)
message = f'''New release {TAG_NAME}!
zon_update = get_replacement()
message = f'''# New release {TAG_NAME}!
## Updates
Updates:
{annotation}
See the release page: https://github.com/zigzap/zap/releases for more information!'''
## Using it
Modify your `build.zig.zon` like this:
'''
message += zon_update + "\n"
message += 'See the [release page](https://github.com/zigzap/zap/releases/'
message += f'{TAG_NAME}) for more information!'
send_to_discord(message)

View file

@ -0,0 +1,14 @@
```zig
.{
.name = "My example project",
.version = "0.0.1",
.dependencies = .{
// zap {tag}
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/{tag}.tar.gz",
.hash = "{hash}",
}
}
}
```

View file

@ -0,0 +1,62 @@
# <!-- INSERT_DEP_BEGIN -->
# ```zig
# .{
# .name = "myapp",
# .version = "0.0.1",
# .dependencies = .{
# // zap release-0.0.24
# .zap = .{
# .url = "https://github.com/zigzap/zap/archive/refs/tags/release-0.0.24.tar.gz",
# .hash = "1220f520fcdd4b3adbca918deeb42f512f7ef4a827680eea8af9abc64b90ed7a5e78",
# }
# }
#
# }
# ```
# <!-- INSERT_DEP_END -->
import os
import sys
import subprocess
TAG_NAME = os.getenv('TAG_NAME', sys.argv[1])
REPLACE_BEGIN_MARKER = '<!-- INSERT_DEP_BEGIN -->'
REPLACE_END_MARKER = '<!-- INSERT_DEP_END -->'
def get_replacement():
ret = subprocess.run([
"./zig-out/bin/pkghash",
"-g", f"--tag={TAG_NAME}",
"--template=./tools/announceybot/release-dep-update-template.md",
], capture_output=True)
text = ret.stdout.decode("utf-8")
return text
out_lines = []
with open('README.md', 'rt') as f:
in_replace_block = False
update_lines = get_replacement().split("\n")
print("Updating with:")
print('\n'.join(update_lines))
lines = [l.rstrip() for l in f.readlines()]
for line in lines:
if in_replace_block:
if line.startswith(REPLACE_END_MARKER):
in_replace_block = False
continue
# ignore the line
if line.startswith(REPLACE_BEGIN_MARKER):
out_lines.append(REPLACE_BEGIN_MARKER)
in_replace_block = True
# append the stuff
out_lines.extend(update_lines)
out_lines.append(REPLACE_END_MARKER)
continue
out_lines.append(line)
with open('README.md', 'wt') as f:
f.write('\n'.join(out_lines))

View file

@ -239,7 +239,7 @@ fn renderTemplate(gpa: std.mem.Allocator, tag: []const u8, template: []const u8,
const s2 = try std.mem.replaceOwned(u8, gpa, s1, "{hash}", hash);
defer gpa.free(s2);
std.debug.print("{s}\n", .{s2});
try std.io.getStdOut().writer().writeAll(s2);
}
pub fn cmdPkg(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {