-
-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (91 loc) · 4.26 KB
/
main.yml
File metadata and controls
106 lines (91 loc) · 4.26 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
name: Create Release from CHANGELOG
on:
push:
branches: [main]
paths:
- "CHANGELOG.md" # Only trigger when CHANGELOG.md is updated
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false # Don't cancel running releases
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Validate CHANGELOG format
run: |
if [[ ! -f "CHANGELOG.md" ]]; then
echo "::error::CHANGELOG.md not found"
exit 1
fi
if ! grep -q "^## \[" CHANGELOG.md && ! grep -q "^## v" CHANGELOG.md; then
echo "::error::CHANGELOG.md does not contain valid version headers"
echo "::error::Expected format: '## [X.Y.Z]' or '## vX.Y.Z'"
exit 1
fi
- name: Extract latest version and notes
id: changelog
run: ./scripts/extract_changelog.sh
- name: Validate semantic version
if: steps.changelog.outputs.is_unreleased != 'true'
run: |
VERSION=${{ steps.changelog.outputs.version }}
# Remove 'v' prefix if present
VERSION=${VERSION#v}
# Validate semantic versioning format
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?(\+[a-zA-Z0-9.]+)?$ ]]; then
echo "::error::Version '$VERSION' does not follow semantic versioning"
echo "::error::Expected format: MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD]"
exit 1
fi
echo "::notice::Version $VERSION is valid semantic version"
- name: Check for existing release
if: steps.changelog.outputs.is_unreleased != 'true'
id: check_release
run: |
VERSION=${{ steps.changelog.outputs.version }}
TAG="v$VERSION"
if gh release view "$TAG" &>/dev/null; then
echo "::notice::Release already exists: $TAG"
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "::notice::No existing release found for: $TAG"
echo "exists=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
if: steps.changelog.outputs.is_unreleased != 'true' && steps.check_release.outputs.exists == 'false'
uses: softprops/action-gh-release@v2.5.0
with:
tag_name: v${{ steps.changelog.outputs.version }}
name: "Release v${{ steps.changelog.outputs.version }}"
body: ${{ steps.changelog.outputs.notes }}
draft: false
prerelease: ${{ contains(steps.changelog.outputs.version, '-') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Verify Release Created
if: steps.changelog.outputs.is_unreleased != 'true' && steps.check_release.outputs.exists == 'false'
run: |
TAG="v${{ steps.changelog.outputs.version }}"
# Wait a moment for release to be fully created
sleep 5
# Verify release exists
if gh release view "$TAG" &>/dev/null; then
RELEASE_URL=$(gh release view "$TAG" --json url --jq '.url')
echo "::notice::Release successfully created: $RELEASE_URL"
else
echo "::error::Release verification failed for $TAG"
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Notify on Failure
if: failure()
run: |
echo "::error::Release workflow failed"
echo "::error::Please check CHANGELOG.md format and workflow logs"