From 66e1a31efbb43a763ec139d379c2840b92de4255 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Mon, 22 May 2023 02:02:04 +0200 Subject: [PATCH] release workflow, first cut --- .github/workflows/release.yml | 66 +++++++++++++++++++++ tools/announceybot/announceybot.py | 4 +- tools/announceybot/generate_releasenotes.py | 27 +++++++++ tools/announceybot/release-note-template.md | 47 +++++++++++++++ 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100644 tools/announceybot/generate_releasenotes.py create mode 100644 tools/announceybot/release-note-template.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..23aa019 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,66 @@ +name: Create Release, update README, send announceybot + +on: + push: + tags: + - 'v*' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install discord-webhook GitPython + + - name: Set tag name + id: tag + run: | + echo "::set-output name=version::${GITHUB_REF#refs/tags/}" + + - name: Generate release notes + id: release_notes + run: | + echo "::set-output name=notes::$(python tools/announceybot/generate_releasenotes.py "${{ steps.tag.outputs.version }}")" + + - name: Run script to update README + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG_NAME: ${{ steps.tag.outputs.version }} + run: | + python tools/announceybot/update_readme.py "${TAG_NAME}" + + - name: Commit and push if it has changed + run: | + git diff + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git commit -am "Update README" + git push + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ steps.tag.outputs.version }} # Remove 'refs/tags/' from the tag name + body: ${{ steps.release_notes.outputs.notes }} # Use the release notes from the output of the previous step + + - name: Announce Release + env: + TAG_NAME: ${{ steps.tag.outputs.version }} + WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} + run: | + python tools/announceybot/announceybot.py "${TAG_NAME}" diff --git a/tools/announceybot/announceybot.py b/tools/announceybot/announceybot.py index 6be8fa2..17f59bc 100644 --- a/tools/announceybot/announceybot.py +++ b/tools/announceybot/announceybot.py @@ -36,7 +36,9 @@ def get_replacement(): if __name__ == '__main__': annotation = get_tag_annotation(TAG_NAME) zon_update = get_replacement() - message = f'''# New release {TAG_NAME}! + message = f'''# TEST-RUN TEST-RUN TEST-RUN + + # New release {TAG_NAME}! ## Updates diff --git a/tools/announceybot/generate_releasenotes.py b/tools/announceybot/generate_releasenotes.py new file mode 100644 index 0000000..2f1bd00 --- /dev/null +++ b/tools/announceybot/generate_releasenotes.py @@ -0,0 +1,27 @@ +import sys +import os +from git import Repo +import subprocess + +TAG_NAME = os.getenv("TAG_NAME", sys.argv[1]) + + +def get_tag_annotation(tagname): + 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-note-template.md", + ], capture_output=True) + text = ret.stdout.decode("utf-8") + return text + + +if __name__ == '__main__': + annotation = get_tag_annotation(TAG_NAME) + print(get_replacement().replace("{{UPDATES}}", annotation)) diff --git a/tools/announceybot/release-note-template.md b/tools/announceybot/release-note-template.md new file mode 100644 index 0000000..ded935e --- /dev/null +++ b/tools/announceybot/release-note-template.md @@ -0,0 +1,47 @@ +# ZAP Release {tag} + +## Updates + +{{UPDATES}} + +## Using it + +To use in your own projects, put this dependency into your `build.zig.zon`: + +```zig + // zap {tag} + .zap = .{ + .url = "https://github.com/zigzap/zap/archive/refs/tags/{tag}.tar.gz", + .hash = "{hash}", + } +``` + +Here is a complete `build.zig.zon` example: + +```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}", + } + } +} + +``` + +Then, in your `build.zig`'s `build` function, add the following before +`exe.install()`: + +```zig + const zap = b.dependency("zap", .{ + .target = target, + .optimize = optimize, + }); + exe.addModule("zap", zap.module("zap")); + exe.linkLibrary(zap.artifact("facil.io")); +```