diff --git a/README.md b/README.md index c6d5feb..ca36fa6 100644 --- a/README.md +++ b/README.md @@ -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 + +```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", } } } ``` + + 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, }); } -``` - +``` \ No newline at end of file diff --git a/tools/announceybot/announceybot.py b/tools/announceybot/announceybot.py index e976357..6be8fa2 100644 --- a/tools/announceybot/announceybot.py +++ b/tools/announceybot/announceybot.py @@ -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) diff --git a/tools/announceybot/release-dep-update-template.md b/tools/announceybot/release-dep-update-template.md new file mode 100644 index 0000000..b56ee3a --- /dev/null +++ b/tools/announceybot/release-dep-update-template.md @@ -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}", + } + } +} +``` diff --git a/tools/announceybot/update_readme.py b/tools/announceybot/update_readme.py new file mode 100644 index 0000000..9ee73d7 --- /dev/null +++ b/tools/announceybot/update_readme.py @@ -0,0 +1,62 @@ +# +# ```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", +# } +# } +# +# } +# ``` +# + +import os +import sys +import subprocess + +TAG_NAME = os.getenv('TAG_NAME', sys.argv[1]) + +REPLACE_BEGIN_MARKER = '' +REPLACE_END_MARKER = '' + + +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)) diff --git a/tools/pkghash.zig b/tools/pkghash.zig index 6d30f7b..9bb5561 100644 --- a/tools/pkghash.zig +++ b/tools/pkghash.zig @@ -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 {