forked from microsoft/fabric-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (136 loc) · 6.18 KB
/
create-release.yml
File metadata and controls
169 lines (136 loc) · 6.18 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
name: 🚀 Create GitHub Release
on:
workflow_dispatch:
inputs:
version:
description: 'The version to release (e.g., v1.2.0)'
required: true
commit_sha:
description: 'Optional: Commit SHA to create the tag on. If not provided, the tag will be created on the latest commit of the current branch (HEAD)'
required: false
default: ''
jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required to access full commit history for validation
- name: Display workflow information
run: |
if [ -n "${{ github.event.inputs.commit_sha }}" ]; then
TARGET_INFO="- **Target Commit:** \`${{ github.event.inputs.commit_sha }}\`"
else
TARGET_INFO="- **Target Commit:** Latest commit on current branch (HEAD)"
fi
cat >> $GITHUB_STEP_SUMMARY << EOF
# 🚀 Create Release Workflow
## ℹ️ Workflow Information
- **Version:** ${{ github.event.inputs.version }}
$TARGET_INFO
EOF
- name: Validate commit SHA (if provided)
if: ${{ github.event.inputs.commit_sha != '' }}
run: |
COMMIT_SHA="${{ github.event.inputs.commit_sha }}"
if ! git rev-parse --verify "$COMMIT_SHA^{commit}" >/dev/null 2>&1; then
cat >> $GITHUB_STEP_SUMMARY << EOF
## ❌ Error: Invalid Commit SHA
The provided commit SHA \`$COMMIT_SHA\` is not valid or does not exist in this repository.
### 📝 Troubleshooting
- Verify the commit SHA exists in the repository
- Ensure you are using the full commit SHA (or at least 7 characters)
- Check that the commit is in the current branch history
EOF
echo "Error: Invalid commit SHA: $COMMIT_SHA"
exit 1
fi
echo "✅ Commit SHA validated successfully: $COMMIT_SHA"
- name: Set up release variables
id: set_vars
run: |
VERSION="${{ github.event.inputs.version }}"
COMMIT_SHA="${{ github.event.inputs.commit_sha }}"
# Use provided commit SHA or default to HEAD
if [ -n "$COMMIT_SHA" ]; then
TARGET_COMMIT="$COMMIT_SHA"
else
TARGET_COMMIT="HEAD"
fi
echo "tag_name=$VERSION" >> $GITHUB_OUTPUT
echo "changelog_file_path=.changes/${VERSION}.md" >> $GITHUB_OUTPUT
echo "target_commit=$TARGET_COMMIT" >> $GITHUB_OUTPUT
# Get the actual commit SHA for display
ACTUAL_SHA=$(git rev-parse "$TARGET_COMMIT")
echo "actual_sha=$ACTUAL_SHA" >> $GITHUB_OUTPUT
echo "✅ Release variables set:"
echo " - Tag name: $VERSION"
echo " - Target commit: $ACTUAL_SHA"
echo " - Changelog file: .changes/${VERSION}.md"
- name: Validate release notes file
run: |
CHANGELOG_FILE="${{ steps.set_vars.outputs.changelog_file_path }}"
if [ ! -f "$CHANGELOG_FILE" ]; then
cat >> $GITHUB_STEP_SUMMARY << EOF
## ❌ Error: Release Notes File Not Found
The release notes file was not found at the expected location:
\`\`\`
$CHANGELOG_FILE
\`\`\`
### 📝 What to do:
1. Ensure you have created the changelog file for version \`${{ steps.set_vars.outputs.tag_name }}\`
2. The file should be located at: \`.changes/${{ steps.set_vars.outputs.tag_name }}.md\`
3. You can use \`changie batch <version>\` to generate the changelog file
### 📂 Available changelog files:
\`\`\`
$(ls -1 .changes/*.md 2>/dev/null || echo "No changelog files found")
\`\`\`
EOF
echo "Error: Release notes file not found at $CHANGELOG_FILE"
exit 1
fi
echo "✅ Release notes file found at: $CHANGELOG_FILE"
- name: Create Release with GitHub CLI
env:
GH_TOKEN: ${{ github.token }}
run: |
cat >> $GITHUB_STEP_SUMMARY << EOF
## 🏗️ Creating Release
Creating release with the following details:
- **Tag:** \`${{ steps.set_vars.outputs.tag_name }}\`
- **Target Commit:** \`${{ steps.set_vars.outputs.actual_sha }}\`
- **Notes File:** \`${{ steps.set_vars.outputs.changelog_file_path }}\`
EOF
# Create the release with the target commit
if gh release create ${{ steps.set_vars.outputs.tag_name }} \
--title "${{ steps.set_vars.outputs.tag_name }}" \
--notes-file "${{ steps.set_vars.outputs.changelog_file_path }}" \
--target "${{ steps.set_vars.outputs.target_commit }}"; then
cat >> $GITHUB_STEP_SUMMARY << EOF
## ✅ Release Created Successfully!
🎉 **Release \`${{ steps.set_vars.outputs.tag_name }}\` has been created!**
### 📋 Release Details:
- **Tag:** \`${{ steps.set_vars.outputs.tag_name }}\`
- **Commit:** \`${{ steps.set_vars.outputs.actual_sha }}\`
- **Release URL:** [View Release](https://github.com/${{ github.repository }}/releases/tag/${{ steps.set_vars.outputs.tag_name }})
EOF
else
cat >> $GITHUB_STEP_SUMMARY << EOF
## ❌ Error: Failed to Create Release
The GitHub CLI failed to create the release. This could be due to:
### 🔍 Common Issues:
- A release with tag \`${{ steps.set_vars.outputs.tag_name }}\` already exists
- Insufficient permissions to create releases
- Network connectivity issues
- Invalid release notes format
### 📝 Next Steps:
1. Check if the tag already exists: \`git tag -l '${{ steps.set_vars.outputs.tag_name }}'\`
2. Verify you have the necessary permissions to create releases
3. Review the workflow run logs for detailed error messages
EOF
echo "Error: Failed to create release"
exit 1
fi