-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (112 loc) · 4.27 KB
/
release.yml
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Create Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name for the release'
required: true
default: 'v1.0.0'
release_type:
description: 'Release type (stable, beta, rc)'
required: true
default: 'stable'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install -y gh
- name: Authenticate GitHub CLI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh auth setup-git
- name: Determine release type
id: release_type
run: |
TAG_NAME=${{ github.ref_name }}
if [[ "$TAG_NAME" == *beta* ]]; then
echo "release_type=Pre-release (Beta)" >> $GITHUB_ENV
echo "prerelease=true" >> $GITHUB_ENV
elif [[ "$TAG_NAME" == *rc* ]]; then
echo "release_type=Pre-release (Release Candidate)" >> $GITHUB_ENV
echo "prerelease=true" >> $GITHUB_ENV
else
echo "release_type=Stable" >> $GITHUB_ENV
echo "prerelease=false" >> $GITHUB_ENV
fi
- name: Get commits since last tag
id: commits
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
echo "No previous tag found, using initial commit."
COMMITS=$(git log --format="- %s (@%an)" HEAD)
else
COMMITS="<ul>"
declare -A FIXUPS
# Procházení commitů od posledního tagu
while read -r commit_hash; do
COMMIT_MSG=$(git log -n 1 --pretty=format:"%s" "$commit_hash")
commit_url="https://github.com/${{ github.repository }}/commit/$commit_hash"
AUTHOR=$(gh api "/repos/${{ github.repository }}/commits/$commit_hash" --jq '.author.login')
# Kontrola, zda jde o fixup commit
if [[ "$COMMIT_MSG" == fixup!* ]]; then
# Najít původní commit hash
ORIGINAL_HASH=$(git log -n 1 --format="%H" "$commit_hash"^)
FIXUPS["$ORIGINAL_HASH"]+="$commit_hash "
continue
fi
# Přidání zprávy commitu
COMMITS+="<li>$COMMIT_MSG (@$AUTHOR)"
# Přidání fixup commitů, pokud existují
if [[ -n "${FIXUPS[$commit_hash]}" ]]; then
COMMITS+=" (fixups: ${FIXUPS[$commit_hash]})"
fi
# Vyhledání referencí v Issues
ISSUE_URLS=$(gh api "/repos/${{ github.repository }}/issues" --jq "[.[] | select(.body and (.body | contains(\"$commit_url\")))][].html_url")
if [[ -n "$ISSUE_URLS" ]]; then
COMMITS+=" (Referenced in Issues: "
for ISSUE_URL in $ISSUE_URLS; do
COMMITS+="[Link]($ISSUE_URL), "
done
COMMITS=${COMMITS%, }
COMMITS+=")"
fi
# Vyhledání referencí v PRs
PR_URLS=$(gh api "/repos/${{ github.repository }}/pulls" --jq "[.[] | select(.body and (.body | contains(\"$commit_url\")))][].html_url")
if [[ -n "$PR_URLS" ]]; then
COMMITS+=" (Referenced in PRs: "
for PR_URL in $PR_URLS; do
COMMITS+="[Link]($PR_URL), "
done
COMMITS=${COMMITS%, }
COMMITS+=")"
fi
COMMITS+="</li>"
done < <(git log --format="%H" $PREV_TAG..HEAD)
COMMITS+="</ul>"
fi
COMMITS=$(echo "$COMMITS" | sed 's/[[:cntrl:]]//g')
echo "commits=$COMMITS" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create release
uses: ncipollo/release-action@v1
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: ${{ github.ref_name }}
body: |
${{ env.commits }}
draft: false
prerelease: ${{ env.prerelease }}
name: ${{ github.ref_name }} - ${{ env.release_type }}