-
Notifications
You must be signed in to change notification settings - Fork 1
129 lines (116 loc) · 3.83 KB
/
release.yml
File metadata and controls
129 lines (116 loc) · 3.83 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g. 0.2.0)"
required: true
type: string
dry_run:
description: "Preview without making changes"
required: false
type: boolean
default: false
jobs:
release:
if: github.repository == 'EndstoneMC/dwarf2cpp'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Validate version
run: |
VERSION="${{ inputs.version }}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid version format: $VERSION (expected X.Y.Z)"
exit 1
fi
if git tag -l "v$VERSION" | grep -q .; then
echo "::error::Tag v$VERSION already exists"
exit 1
fi
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Extract unreleased changelog
run: |
BODY=$(sed -n '/^## \[Unreleased\]/,/^## \[/{/^## \[/d; p}' CHANGELOG.md)
BODY=$(echo "$BODY" | sed '/./,$!d' | sed -e :a -e '/^\n*$/{$d;N;ba}')
if [ -z "$BODY" ]; then
echo "::error::Unreleased section in CHANGELOG.md is empty"
exit 1
fi
echo "$BODY" > /tmp/release_body.md
echo "Extracted changelog:"
echo "$BODY"
- name: Preview
if: inputs.dry_run
run: |
DATE=$(date -u +%Y-%m-%d)
echo "=== Dry Run ==="
echo "Version: $VERSION"
echo "Tag: v$VERSION"
echo "Date: $DATE"
echo ""
echo "=== Release Body ==="
cat /tmp/release_body.md
- name: Update version in pyproject.toml
if: ${{ !inputs.dry_run }}
run: sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml
- name: Update CHANGELOG.md
if: ${{ !inputs.dry_run }}
run: |
DATE=$(date -u +%Y-%m-%d)
sed -i "s/^## \[Unreleased\]/## [Unreleased]\n\n## [$VERSION] - $DATE/" CHANGELOG.md
- name: Commit and tag
if: ${{ !inputs.dry_run }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md pyproject.toml
git commit -m "Release $VERSION"
git tag "v$VERSION"
- name: Push
if: ${{ !inputs.dry_run }}
run: |
git push origin main
git push origin "v$VERSION"
- name: Create GitHub release
if: ${{ !inputs.dry_run }}
env:
GH_TOKEN: ${{ github.token }}
run: |
PREV_TAG=$(git tag --sort=-v:refname | sed -n '2p')
if [ -n "$PREV_TAG" ]; then
printf '\n**Full Changelog**: https://github.com/%s/compare/%s...v%s\n' \
"${{ github.repository }}" "$PREV_TAG" "$VERSION" >> /tmp/release_body.md
fi
gh release create "v$VERSION" \
--title "v$VERSION" \
--notes-file /tmp/release_body.md
build_wheels:
if: ${{ !inputs.dry_run }}
needs: [ release ]
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-14 ]
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: v${{ inputs.version }}
- name: Build wheels
uses: pypa/cibuildwheel@v3.4.0
env:
CIBW_SKIP: "*-win32 *-manylinux_i686"
- name: Attach wheels to release
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "v${{ inputs.version }}" wheelhouse/*.whl