-
Notifications
You must be signed in to change notification settings - Fork 5
153 lines (135 loc) · 4.21 KB
/
release.yml
File metadata and controls
153 lines (135 loc) · 4.21 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g. 0.5.0)"
required: true
type: string
dry_run:
description: "Preview without making changes"
required: false
type: boolean
default: false
jobs:
release:
if: github.repository == 'EndstoneMC/python-example-plugin'
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
echo ""
echo "=== CHANGELOG.md will become ==="
echo "## [Unreleased]"
echo ""
echo "## [$VERSION] - $DATE"
- 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
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:
if: ${{ !inputs.dry_run }}
needs: [ release ]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: v${{ inputs.version }}
fetch-depth: 0
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.10"
- name: Install
run: uv sync --extra dev
- name: Lint
run: uv run ruff check src/
publish:
needs: [ build ]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: v${{ inputs.version }}
fetch-depth: 0
- name: Set up uv
uses: astral-sh/setup-uv@v7
- name: Build
run: uv build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Attach wheel to GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "v${{ inputs.version }}" dist/*.whl