From 165d1da142c2c358250bbeb1c7fb3996f268b509 Mon Sep 17 00:00:00 2001 From: ahuston-0 Date: Tue, 27 May 2025 00:09:55 -0400 Subject: [PATCH] inject file directly --- .github/workflows/flake-update.yml | 30 ++++++++++++++++++----------- utils/inject-diff.py | 31 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 11 deletions(-) create mode 100755 utils/inject-diff.py diff --git a/.github/workflows/flake-update.yml b/.github/workflows/flake-update.yml index eb75004..75123cb 100644 --- a/.github/workflows/flake-update.yml +++ b/.github/workflows/flake-update.yml @@ -51,7 +51,7 @@ jobs: id: upload-diff uses: actions/upload-artifact@v3 with: - name: nix flake diff + name: nix-flake-diff.log path: post-diff compression-level: 9 if-no-files-found: error @@ -61,25 +61,33 @@ jobs: with: path: pr_body.template contents: | - - The following Nix Flake inputs were updated: + - The following Nix Flake inputs were updated: - ``` - ${{ env.UPDATE_LOG }} - ``` + Flake input changes: - Flake Diff can be found here: - ${{ steps.upload-diff.outputs.artifact-url }} + ```shell + ${{ env.UPDATE_LOG }} + ``` - Auto-generated by [update.yml][1] with the help of - [create-pull-request][2]. + Flake evaluation diff: - [1]: https://nayeonie.com/ahuston-0/nix-dotfiles/src/branch/main/.github/workflows/flake-update.yml - [2]: https://forgejo.stefka.eu/jiriks74/create-pull-request + ```shell + nix-diff-placeholder + ``` + + Auto-generated by [update.yml][1] with the help of + [create-pull-request][2]. + + [1]: https://nayeonie.com/ahuston-0/nix-dotfiles/src/branch/main/.github/workflows/flake-update.yml + [2]: https://forgejo.stefka.eu/jiriks74/create-pull-request - name: Generate PR body uses: pedrolamas/handlebars-action@v2.4.0 # v2.4.0 with: files: "pr_body.template" output-filename: "pr_body.md" + - name: template diff into PR body + run: | + nix utils/inject-diff.py - name: Save PR body id: pr_body uses: juliangruber/read-file-action@v1 diff --git a/utils/inject-diff.py b/utils/inject-diff.py new file mode 100755 index 0000000..ee46794 --- /dev/null +++ b/utils/inject-diff.py @@ -0,0 +1,31 @@ +#!/usr/bin/env nix +#! nix shell nixpkgs#python3 --command python +import logging + +def inject_diff(): + source_file = 'post-diff' + target_file = 'pr_body.md' + placeholder = "nix-diff-placeholder" + + logging.info(f"injecting '{source_file}' into '{target_file}' using '{placeholder}' as a placeholder") + + out = [] + with open(source_file,'r') as src: + src_content = src.read() + with open(target_file,'r') as tgt: + for line in tgt.readlines(): + if placeholder in line: + out.append(line.replace(placeholder,src_content)) + else: + out.append(line) + logging.info(out) + + with open(target_file,'w') as tgt: + tgt.writelines(out) + + + + +if __name__ == "__main__": + logging.basicConfig( level=logging.INFO) + inject_diff()