Generate Github release link

A bash script to easily generate a link for Github to create a new release with a new tag on the main branch.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash

# Get all tags
git fetch --tags

latest=$(git tag --sort=committerdate | tail -1)

# Get previous branch
next=$(echo ${latest} | awk -F. -v OFS=. '{$NF += 1 ; print}')

# Get remote URL, assumes ssh
remote=$(git config --get remote.origin.url)

# Replace some parts
remote=${remote/git@github.com:/}
remote=${remote/\.git/}

# Today
today=$(date +%d-%m-%Y)

# Final URL
url="https://github.com/$remote/releases/new?target=main&tag=$next&title=Deploy%20$today"

# Output to screen
echo $url

# Mac OSX copy to clipboard with pbcopy
( which pbcopy >/dev/null 2>&1 ) &&
echo "$url" | pbcopy &&
echo "[+] Copied to clipboard"

# Linux copy to both the selection buffer and clipboard with xclip.
( which xclip >/dev/null 2>&1 ) &&
echo "$url" | xclip -i -sel c -f |xclip -i -sel p &&
echo "[+] Copied to clipboard"