-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (124 loc) · 4.85 KB
/
release.yml
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
name: Release
on:
pull_request:
types: [closed]
branches:
- main
permissions:
contents: write
pull-requests: write
issues: write
jobs:
create-release:
name: Create Release
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine Version
id: version
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
run: |
# Get latest release tag (if any)
latest_tag=$(gh release view --json tagName --jq .tagName || echo "v0.0.0")
# Extract major, minor, patch numbers
if [[ $latest_tag =~ v([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
patch="${BASH_REMATCH[3]}"
else
major=0
minor=0
patch=0
fi
# Determine version bump type from PR labels
labels=$(echo '${{ toJSON(github.event.pull_request.labels.*.name) }}')
if echo "$labels" | jq -e 'any(. == "major")' > /dev/null; then
major=$((major + 1))
minor=0
patch=0
elif echo "$labels" | jq -e 'any(. == "minor")' > /dev/null; then
minor=$((minor + 1))
patch=0
else
# Default to patch bump if no major/minor label
patch=$((patch + 1))
fi
new_version="v${major}.${minor}.${patch}"
echo "New version will be: $new_version"
echo "version=$new_version" >> $GITHUB_OUTPUT
- name: Generate Release Notes
id: release-notes
run: |
# Get PR description
DESCRIPTION="${{ github.event.pull_request.body }}"
# Get list of changes since last release
CHANGES=$(gh pr list \
--base main \
--state merged \
--json title,number,mergedAt,labels \
--search "merged:>=$(gh release view --json publishedAt --jq .publishedAt || echo "v0.0.0")")
# Extract PR description and format it
DESCRIPTION=$(echo "$DESCRIPTION" | sed '/<!--.*-->/d')
# Format the release notes
NOTES="## What's Changed
${DESCRIPTION}
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}
## Installation
Add to your \`Package.swift\`:
\`\`\`swift
dependencies: [
.package(url: \"https://github.com/vamsii777/SwiftTZ.git\", from: \"${{ steps.version.outputs.version }}\")
]
\`\`\`
"
# Save to file (handles multiline better than environment variables)
echo "$NOTES" > release_notes.md
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.version }}
name: Release ${{ steps.version.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: false
token: ${{ secrets.TOKEN }}
- name: Update Documentation
if: success()
run: |
# Add any documentation update steps here
echo "Documentation updated for version ${{ steps.version.outputs.version }}"
- name: Notify on Failure
if: failure()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ Failed to create release. Please check the workflow logs for details.'
})
- name: Update README.md Version
if: success()
run: |
VERSION="${{ steps.version.outputs.version }}"
VERSION_NO_V="${VERSION#v}" # Remove 'v' prefix
# Update version in README.md
sed -i.bak 's/\.package(url: "https:\/\/github\.com\/vamsii777\/SwiftTZ\.git", from: "[0-9]*\.[0-9]*\.[0-9]*")/\.package(url: "https:\/\/github\.com\/vamsii777\/SwiftTZ\.git", from: "'$VERSION_NO_V'")/' README.md
rm README.md.bak
- name: Commit Version Updates
if: success()
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add Package.swift README.md
git commit -m "chore: bump version to ${{ steps.version.outputs.version }}"
git push