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

@ -143,21 +143,24 @@ With an existing zig project, adding zap to it is easy:
To add zap to `build.zig.zon`:
<!-- 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)``:
@ -316,4 +319,3 @@ pub fn main() !void {
});
}
```

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 {