forked from clouddrove/github-shared-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (107 loc) · 3.93 KB
/
Copy pathrelease-changelog.yml
File metadata and controls
119 lines (107 loc) · 3.93 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
---
name: CHANGELOG
on:
workflow_call:
inputs:
branch:
required: true
type: string
description: "Branch to update CHANGELOG from"
tag_format:
required: false
default: 'vX.Y.Z'
type: string
description: "Repository tag format (e.g., vX.Y.Z or X.Y.Z)"
release_tag:
required: true
type: string
description: "Actual release tag to validate and use"
secrets:
GITHUB:
required: true
description: 'PAT of the user to run the jobs.'
jobs:
tag-validation:
runs-on: ubuntu-latest
outputs:
valid: ${{ steps.check.outputs.valid }}
final_tag: ${{ steps.check.outputs.final_tag }}
steps:
- name: Validate release tag matches repository format
id: check
run: |
REPO_TAG_FORMAT="${{ inputs.tag_format }}"
RELEASE_TAG="${{ inputs.release_tag }}"
echo "📋 Repository tag format: $REPO_TAG_FORMAT"
echo "🏷️ Release tag: $RELEASE_TAG"
echo "================"
# Check if repository uses v-prefixed tags
if [[ "$REPO_TAG_FORMAT" == v* ]]; then
# Repository uses v-prefixed format (vX.Y.Z)
if [[ "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "valid=true" >> $GITHUB_OUTPUT
echo "final_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
echo "✅ Release tag matches repository format (v-prefixed)"
else
echo "valid=false" >> $GITHUB_OUTPUT
echo "❌ Repository uses v-prefixed tags (vX.Y.Z) but release tag is: $RELEASE_TAG"
exit 1
fi
else
# Repository uses plain format (X.Y.Z)
if [[ "$RELEASE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "valid=true" >> $GITHUB_OUTPUT
echo "final_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
echo "✅ Release tag matches repository format (plain)"
else
echo "valid=false" >> $GITHUB_OUTPUT
echo "❌ Repository uses plain tags (X.Y.Z) but release tag is: $RELEASE_TAG"
exit 1
fi
fi
create_changelog:
needs: tag-validation
if: needs.tag-validation.outputs.valid == 'true'
runs-on: ubuntu-latest
steps:
- name: 📦 Checkout Repository
uses: actions/checkout@v7
with:
token: ${{ secrets.GITHUB }}
ref: ${{ inputs.release_tag }}
- name: 📝 Generate Changelog
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ secrets.GITHUB }}
tag: ${{ inputs.release_tag }}
includeInvalidCommits: false
writeToFile: true
changelogFilePath: CHANGELOG.md
includeRefIssues: true
useGitmojis: true
reverseOrder: false
- name: 🚀 Create Release
uses: ncipollo/release-action@v1.21.0
with:
token: ${{ secrets.GITHUB }}
tag: ${{ inputs.release_tag }}
name: ${{ inputs.release_tag }}
allowUpdates: true
draft: false
makeLatest: true
body: ${{ steps.changelog.outputs.changes }}
- name: 💾 Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v7
with:
branch: ${{ inputs.branch }}
commit_user_name: clouddrove-ci
commit_user_email: 84795582+clouddrove-ci@users.noreply.github.com
commit_author: "CloudDrove CI <84795582+clouddrove-ci@users.noreply.github.com>"
commit_message: 'docs: update CHANGELOG.md for ${{ inputs.release_tag }}'
file_pattern: CHANGELOG.md
- name: 📋 Release Summary
run: |
echo "✅ Release ${{ inputs.release_tag }} created successfully."
echo "🏷️ Version type: ${{ inputs.version_type }}"
echo "📝 Changelog has been updated and committed."