-
Notifications
You must be signed in to change notification settings - Fork 2
184 lines (163 loc) · 6.3 KB
/
Copy pathrelease.yml
File metadata and controls
184 lines (163 loc) · 6.3 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
172
173
174
175
176
177
178
179
180
181
182
183
184
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g. 1.4.0). Leave empty to auto-detect from commits.'
required: false
type: string
use_existing_tag:
description: 'Use existing latest tag instead of creating a new one'
required: false
default: false
type: boolean
dry_run:
description: 'Dry run (do not create tag or release)'
required: false
default: false
type: boolean
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
tag: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff
- name: Get latest tag
id: latest_tag
run: |
LATEST=$(git tag --list 'v*' --sort=-version:refname | head -1)
echo "tag=${LATEST:-v0.0.0}" >> "$GITHUB_OUTPUT"
echo "Latest tag: ${LATEST:-v0.0.0}"
- name: Auto-detect version bump
id: version_bump
if: ${{ !inputs.version && !inputs.use_existing_tag }}
run: |
LATEST="${{ steps.latest_tag.outputs.tag }}"
MAJOR=$(echo "$LATEST" | sed 's/v//' | cut -d. -f1)
MINOR=$(echo "$LATEST" | sed 's/v//' | cut -d. -f2)
PATCH=$(echo "$LATEST" | sed 's/v//' | cut -d. -f3)
# Check commits since last tag for breaking changes or features
COMMITS=$(git log "${LATEST}..HEAD" --pretty=format:"%s")
echo "Commits since $LATEST:"
echo "$COMMITS"
if echo "$COMMITS" | grep -qE '^\[!!!\]'; then
NEXT="$((MAJOR + 1)).0.0"
BUMP="major"
elif echo "$COMMITS" | grep -qE '^\[FEATURE\]'; then
NEXT="${MAJOR}.$((MINOR + 1)).0"
BUMP="minor"
else
NEXT="${MAJOR}.${MINOR}.$((PATCH + 1))"
BUMP="patch"
fi
echo "version=${NEXT}" >> "$GITHUB_OUTPUT"
echo "bump=${BUMP}" >> "$GITHUB_OUTPUT"
echo "Auto-detected bump: $BUMP → v$NEXT"
- name: Resolve version
id: version
run: |
if [ -n "${{ inputs.version }}" ]; then
VERSION="${{ inputs.version }}"
elif [ "${{ inputs.use_existing_tag }}" = "true" ]; then
VERSION="${{ steps.latest_tag.outputs.tag }}"
echo "Using existing tag: $VERSION"
else
VERSION="${{ steps.version_bump.outputs.version }}"
fi
# Strip leading 'v' for normalization, then re-add
VERSION="${VERSION#v}"
echo "version=v${VERSION}" >> "$GITHUB_OUTPUT"
echo "version_plain=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Release version: v${VERSION}"
- name: Check tag does not exist
if: ${{ !inputs.use_existing_tag }}
run: |
if git rev-parse "${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "Tag ${{ steps.version.outputs.version }} already exists!"
exit 1
fi
- name: Generate changelog
id: changelog
if: ${{ !inputs.use_existing_tag }}
run: |
LATEST="${{ steps.latest_tag.outputs.tag }}"
# Generate changelog for this release only (since last tag)
git cliff ${LATEST}..HEAD \
--config cliff.toml \
--tag "${{ steps.version.outputs.version }}" \
--output RELEASE_NOTES.md
cat RELEASE_NOTES.md
# Also update the full CHANGELOG.md
git cliff --config cliff.toml \
--tag "${{ steps.version.outputs.version }}" \
--output CHANGELOG.md
- name: Generate changelog for existing tag
if: ${{ inputs.use_existing_tag }}
run: |
CURRENT_TAG="${{ steps.version.outputs.version }}"
PREVIOUS_TAG=$(git tag --list 'v*' --sort=-version:refname | grep -A1 "^${CURRENT_TAG}$" | tail -n1)
echo "Generating changelog between ${PREVIOUS_TAG} and ${CURRENT_TAG}"
# Generate changelog for this release only
git cliff ${PREVIOUS_TAG}..${CURRENT_TAG} \
--config cliff.toml \
--output RELEASE_NOTES.md || echo "# Release $CURRENT_TAG" > RELEASE_NOTES.md
cat RELEASE_NOTES.md
- name: Show release summary (dry run)
if: ${{ inputs.dry_run }}
run: |
echo "=== DRY RUN ==="
if [ "${{ inputs.use_existing_tag }}" = "true" ]; then
echo "Would use existing tag: ${{ steps.version.outputs.version }}"
else
echo "Would create tag: ${{ steps.version.outputs.version }}"
fi
echo ""
cat RELEASE_NOTES.md
- name: Commit CHANGELOG.md
if: ${{ !inputs.dry_run && !inputs.use_existing_tag }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git diff --staged --quiet || git commit -m "[TASK] Update CHANGELOG.md for ${{ steps.version.outputs.version }}"
- name: Create tag
if: ${{ !inputs.dry_run && !inputs.use_existing_tag }}
run: |
git tag -a "${{ steps.version.outputs.version }}" \
-m "Release ${{ steps.version.outputs.version }}"
if [ "${{ github.ref_type }}" = "branch" ]; then
git push origin "HEAD:${{ github.ref_name }}"
fi
git push origin "${{ steps.version.outputs.version }}"
- name: Create GitHub Release
if: ${{ !inputs.dry_run && !inputs.use_existing_tag }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.version }}
body_path: RELEASE_NOTES.md
draft: false
prerelease: false
ter-release:
name: TYPO3 TER Release
needs: release
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.release.outputs.tag }}
- name: Publish to TYPO3 TER
uses: tomasnorre/typo3-upload-ter@v2
with:
api-token: ${{ secrets.TYPO3_API_TOKEN }}