From ce1dbe4f8355c7940ed2f309494701e31ca9fc1d Mon Sep 17 00:00:00 2001 From: Roman Melnikov Date: Wed, 20 Sep 2023 15:59:59 +0200 Subject: [PATCH] fixup! Add helper script for creating GitHub releases using gh --- overlay/github.nix | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 overlay/github.nix diff --git a/overlay/github.nix b/overlay/github.nix new file mode 100644 index 0000000..05fd201 --- /dev/null +++ b/overlay/github.nix @@ -0,0 +1,45 @@ +{ gh, git }: +{ + # autorelease [release-tag] + # + # release-assets + # A path to the directory with release assets, typically something like "$(nix build .#release)" + # release-notes + # Either a path to the file or bare text to use as release notes. + # release-tag (optional) + # A tag for the release to be pushed and also to be used as a release title. + # Default value to be used is 'auto-release'. + # + # If 'release-tag' is 'autorelease' or 'PRERELEASE' env variable is set to 'true' + # created release is marked as 'prerelease'. + # + # Usage examples: + # autorelease "$(nix build .#release)" "Automatic release on "$(date +\"%Y%m%d%H%M\")"" + # + # autorelease "$(nix build .#release)" ./release-notes.md "v1.0" + autorelease = pkgs.writeShellApplication { + name = "autorelease"; + runtimeInputs = [ gh git ]; + text = '' + release_assets="$1" + release_notes="$2"; + release_tag="''${3:-auto-release}" + + # gh expects 'GH_TOKEN' env variable to be set + # Delete release if it exists + gh release delete "$release_tag" || true + + typeset -a release_args + # Create release + if [[ $release_tag == "auto-release" || ''${PRERELEASE:-false} == true ]]; then + release_args+=("--prerelease") + fi + if [[ -f $release_notes ]]; + release_args+=("--notes-file" "$release_notes") + else + release_args+=("--notes" "$release_notes") + fi + gh release create "$release_tag" --target "$(git rev-parse HEAD)" --title "$release_tag" "''${release_args[@]}" "$release_assets/*" + ''; + } +} \ No newline at end of file