-
Notifications
You must be signed in to change notification settings - Fork 0
167 lines (144 loc) · 6.28 KB
/
Copy pathrelease.yml
File metadata and controls
167 lines (144 loc) · 6.28 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
name: Release DataConnect Python Package
on:
push:
branches: [ main ]
workflow_dispatch:
inputs:
version:
description: 'Version to release (leave empty for auto from pyproject.toml)'
required: false
default: ''
concurrency:
group: ${{ github.event.pull_request.number || github.ref }}-release
cancel-in-progress: true
jobs:
build-and-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Get package info
id: pkg-info
run: |
PKG_VERSION=$(grep '^version' pyproject.toml | head -1 | awk -F'"' '{print $2}')
PKG_NAME=$(grep '^name' pyproject.toml | head -1 | awk -F'"' '{print $2}')
echo "version=$PKG_VERSION" >> $GITHUB_OUTPUT
echo "name=$PKG_NAME" >> $GITHUB_OUTPUT
echo "Package: $PKG_NAME, Version: $PKG_VERSION"
- name: Check existing tag
id: check_tag
run: |
if git rev-parse "v${{ steps.pkg-info.outputs.version }}" >/dev/null 2>&1; then
echo "tag_exists=true" >> $GITHUB_OUTPUT
echo "Tag v${{ steps.pkg-info.outputs.version }} already exists, will not create duplicate"
else
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "Tag v${{ steps.pkg-info.outputs.version }} does not exist yet"
fi
- name: Build package
if: steps.check_tag.outputs.tag_exists != 'true'
run: poetry build
- name: Find previous tag
id: find-previous-tag
if: steps.check_tag.outputs.tag_exists != 'true'
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
echo "No previous tag found - will generate changelog from all commits"
echo "previous_tag=" >> $GITHUB_OUTPUT
echo "from_ref=$(git rev-list --max-parents=0 HEAD)" >> $GITHUB_OUTPUT
else
echo "Previous tag found: $PREVIOUS_TAG"
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
echo "from_ref=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
fi
- name: Generate changelog
id: generate-changelog
if: steps.check_tag.outputs.tag_exists != 'true'
run: |
FROM_REF="${{ steps.find-previous-tag.outputs.from_ref }}"
echo "Generating changelog from $FROM_REF to HEAD..."
mkdir -p .github
CURRENT_VERSION="${{ steps.pkg-info.outputs.version }}"
CURRENT_DATE=$(date +"%Y-%m-%d")
BRANCH_NAME=$(git branch --show-current 2>/dev/null || echo "")
JIRA_TICKETS=$(echo "$BRANCH_NAME" | grep -o 'MCC-[0-9]*' | sort -u | tr '\n' ' ')
echo "# Release Notes for v$CURRENT_VERSION ($CURRENT_DATE)" > .github/release-notes.md
echo "" >> .github/release-notes.md
if [ ! -z "$JIRA_TICKETS" ]; then
echo "## Related Issues" >> .github/release-notes.md
for ticket in $JIRA_TICKETS; do
echo "- $ticket" >> .github/release-notes.md
done
echo "" >> .github/release-notes.md
fi
git log $FROM_REF..HEAD --pretty=format:"%s" > .github/all-commits.txt
extract_commits() {
local type=$1
local emoji=$2
local title=$3
echo "## $emoji $title" > .github/section-$type.md
grep -E "^$type(\([^)]*\))?!?:" .github/all-commits.txt | \
sed -E "s/^$type(\([^)]*\))?!?:\s*/- /" >> .github/section-$type.md || true
if [ $(wc -l < .github/section-$type.md) -gt 1 ]; then
cat .github/section-$type.md >> .github/release-notes.md
echo "" >> .github/release-notes.md
return 0
else
return 1
fi
}
extract_commits "feat" "🚀" "Features" || true
extract_commits "fix" "🐛" "Bug Fixes" || true
extract_commits "perf" "⚡" "Performance Improvements" || true
extract_commits "refactor" "♻️" "Refactoring" || true
extract_commits "docs" "📚" "Documentation" || true
extract_commits "chore" "🔧" "Maintenance" || true
extract_commits "ci" "👷" "CI/CD" || true
OTHER_COMMITS=$(grep -vE "^(feat|fix|perf|refactor|docs|chore|ci)(\([^)]*\))?!?:" \
.github/all-commits.txt | grep -v "^Merge " || true)
if [ ! -z "$OTHER_COMMITS" ]; then
echo "## 📝 Other Changes" >> .github/release-notes.md
echo "$OTHER_COMMITS" | sed 's/^/- /' >> .github/release-notes.md
echo "" >> .github/release-notes.md
fi
BREAKING=$(grep -E "^[a-z]+(\([^)]*\))?!:" .github/all-commits.txt || true)
if [ ! -z "$BREAKING" ]; then
echo "## ⚠️ Breaking Changes" >> .github/release-notes.md
echo "$BREAKING" | sed 's/^/- /' >> .github/release-notes.md
echo "" >> .github/release-notes.md
fi
- name: Display release notes
if: steps.check_tag.outputs.tag_exists != 'true'
run: |
echo "--- Release Notes Content ---"
cat .github/release-notes.md || echo "No release notes were generated"
echo "-----------------------------"
- name: Create Release
if: steps.check_tag.outputs.tag_exists != 'true'
uses: ncipollo/release-action@v1
with:
name: "Release ${{ steps.pkg-info.outputs.version }}"
tag: "v${{ steps.pkg-info.outputs.version }}"
commit: ${{ github.sha }}
artifacts: "dist/*"
bodyFile: .github/release-notes.md
token: ${{ secrets.GITHUB_TOKEN }}
draft: false
prerelease: ${{ contains(steps.pkg-info.outputs.version, 'rc') || contains(steps.pkg-info.outputs.version, 'b') || contains(steps.pkg-info.outputs.version, 'a') }}
skipIfReleaseExists: true