Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper script for creating GitHub releases using gh #143

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions overlay/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,6 @@ in
'';
};
};

github = import ./github.nix { inherit (final) gh git writeShellApplication; };
}
52 changes: 52 additions & 0 deletions overlay/github.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{ gh, git, writeShellApplication }:
{
# autorelease <release-assets> <release-notes> [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'.
#
# 'OVERWRITE_RELEASE' env variable is set to 'true' an existing release with 'release-tag'
# will be deleted prior to recreation.
#
# This script expects 'GH_TOKEN' env variable to be set to a GitHub PAT that is capable of
# managing releases in the target repository.
#
# 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 = writeShellApplication {
name = "autorelease";
runtimeInputs = [ gh git ];
text = ''
release_assets="$1"
release_notes="$2";
release_tag="''${3:-auto-release}"

if [[ ''${OVERWRITE_RELEASE:-false} == true ]]; then
# Delete release if it exists
gh release delete "$release_tag" --yes || true
fi

typeset -a release_args
# Create release
if [[ $release_tag == "auto-release" || ''${PRERELEASE:-false} == true ]]; then
release_args+=("--prerelease")
fi
if [[ -f $release_notes ]]; then
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"/*
'';
};
}