-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (150 loc) · 6.05 KB
/
github-release.yml
File metadata and controls
171 lines (150 loc) · 6.05 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Create GitHub Release
on:
workflow_call:
inputs:
tag:
description: 'Git tag for the release (e.g., v1.0.0)'
required: true
type: string
release_title:
description: 'Release title (defaults to github_ref if not provided)'
required: false
type: string
default: ''
release_notes:
description: 'Release notes (supports Markdown)'
required: false
type: string
default: ''
draft:
description: 'Create as draft release'
required: false
type: boolean
default: false
prerelease:
description: 'Mark as pre-release'
required: false
type: boolean
default: false
generate_notes:
description: 'Auto-generate release notes from commits'
required: false
type: boolean
default: false
secrets:
gh_token:
description: 'GitHub Personal Access Token with repo permissions'
required: true
outputs:
release_url:
description: 'URL of the created release'
value: ${{ jobs.create-release.outputs.release_url }}
release_id:
description: 'ID of the created release'
value: ${{ jobs.create-release.outputs.release_id }}
jobs:
create-release:
name: Create GitHub Release
runs-on: [self-hosted]
timeout-minutes: 10
outputs:
release_url: ${{ steps.create.outputs.url }}
release_id: ${{ steps.create.outputs.id }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Prepare release information
id: prepare
run: |
# Use provided title or default to tag
TITLE="${{ inputs.release_title }}"
if [ -z "$TITLE" ]; then
TITLE="${{ inputs.tag }}"
fi
echo "title=$TITLE" >> $GITHUB_OUTPUT
echo "Release Title: $TITLE"
- name: Create release notes file
if: inputs.release_notes != ''
run: |
cat > release_notes.md << 'EOF'
${{ inputs.release_notes }}
EOF
echo "Release notes saved to file"
- name: Create GitHub Release
id: create
timeout-minutes: 5
env:
GH_TOKEN: ${{ secrets.gh_token }}
run: |
FLAGS=()
FLAGS+=("--title" "${{ steps.prepare.outputs.title }}")
# Add release notes if provided
if [ -n "${{ inputs.release_notes }}" ]; then
FLAGS+=("--notes-file" "release_notes.md")
elif [ "${{ inputs.generate_notes }}" == "true" ]; then
FLAGS+=("--generate-notes")
else
FLAGS+=("--notes" "")
fi
# Add draft flag if specified
if [ "${{ inputs.draft }}" == "true" ]; then
FLAGS+=("--draft")
fi
# Add prerelease flag if specified
if [ "${{ inputs.prerelease }}" == "true" ]; then
FLAGS+=("--prerelease")
fi
echo "Creating release for tag: ${{ inputs.tag }}"
echo "Flags: ${FLAGS[@]}"
# Create the release and capture URL
RELEASE_URL=$(gh release create "${{ inputs.tag }}" "${FLAGS[@]}")
# Get release ID from the API
RELEASE_ID=$(gh api "repos/${{ github.repository }}/releases/tags/${{ inputs.tag }}" --jq '.id')
echo "url=$RELEASE_URL" >> $GITHUB_OUTPUT
echo "id=$RELEASE_ID" >> $GITHUB_OUTPUT
echo "✅ Release created successfully!"
echo "Release URL: $RELEASE_URL"
echo "Release ID: $RELEASE_ID"
- name: Add summary
run: |
echo "# 🎉 GitHub Release Created Successfully" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Add quick access link
echo "🔗 **[View Release](${{ steps.create.outputs.url }})**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📦 Release Information" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY
echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY
echo "| Tag | \`${{ inputs.tag }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Title | **${{ steps.prepare.outputs.title }}** |" >> $GITHUB_STEP_SUMMARY
echo "| Draft | ${{ inputs.draft }} |" >> $GITHUB_STEP_SUMMARY
echo "| Pre-release | ${{ inputs.prerelease }} |" >> $GITHUB_STEP_SUMMARY
echo "| Auto-generated Notes | ${{ inputs.generate_notes }} |" >> $GITHUB_STEP_SUMMARY
echo "| Release ID | \`${{ steps.create.outputs.id }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Repository | \`${{ github.repository }}\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Add release notes if provided
if [ -n "${{ inputs.release_notes }}" ]; then
echo "## 📝 Release Notes" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "${{ inputs.release_notes }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
# Add status indicators
echo "## ✅ Status" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ inputs.draft }}" == "true" ]; then
echo "⚠️ This release was created as a **draft** and is not publicly visible yet." >> $GITHUB_STEP_SUMMARY
else
echo "✅ Release is **published** and publicly visible." >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ inputs.prerelease }}" == "true" ]; then
echo "🚧 This release is marked as a **pre-release**." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "📅 Created: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY