-
Notifications
You must be signed in to change notification settings - Fork 1
116 lines (101 loc) · 4.64 KB
/
release.yml
File metadata and controls
116 lines (101 loc) · 4.64 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
name: Release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.11
- name: Install dependencies
run: uv sync --all-extras
- name: Run tests
run: uv run pytest tests -v --tb=short
- name: Get version from pyproject.toml
id: version
run: |
VERSION=$(uv run python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "::notice::📦 Version in pyproject.toml: $VERSION"
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "::notice::🔄 Tag v${{ steps.version.outputs.version }} already exists - skipping release"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "::notice::🚀 New version detected! Will create release v${{ steps.version.outputs.version }}"
fi
- name: Check PyPI for existing version
id: check_pypi
if: steps.check_tag.outputs.exists == 'false'
run: |
VERSION="${{ steps.version.outputs.version }}"
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/getlate/$VERSION/json")
if [ "$HTTP_STATUS" = "200" ]; then
echo "::error::❌ Version $VERSION already exists on PyPI! Bump the version in pyproject.toml"
exit 1
else
echo "::notice::✅ Version $VERSION not found on PyPI - ready to publish"
fi
- name: Release Summary
run: |
echo "## 📋 Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Item | Value |" >> $GITHUB_STEP_SUMMARY
echo "|------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Version | \`${{ steps.version.outputs.version }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Tag exists | ${{ steps.check_tag.outputs.exists }} |" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check_tag.outputs.exists }}" = "true" ]; then
echo "| Action | ⏭️ **Skipped** (version already released) |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> 💡 To release a new version, update \`version\` in \`pyproject.toml\`" >> $GITHUB_STEP_SUMMARY
else
echo "| Action | 🚀 **New Release** |" >> $GITHUB_STEP_SUMMARY
echo "| GitHub Release | v${{ steps.version.outputs.version }} |" >> $GITHUB_STEP_SUMMARY
echo "| PyPI | getlate==${{ steps.version.outputs.version }} |" >> $GITHUB_STEP_SUMMARY
fi
- name: Build package
if: steps.check_tag.outputs.exists == 'false'
run: |
uv build
echo "::notice::📦 Built: $(ls dist/)"
- name: Create GitHub Release
if: steps.check_tag.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
name: v${{ steps.version.outputs.version }}
files: dist/*
generate_release_notes: true
- name: Publish to PyPI
if: steps.check_tag.outputs.exists == 'false'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Post-release Summary
if: steps.check_tag.outputs.exists == 'false'
run: |
echo "" >> $GITHUB_STEP_SUMMARY
echo "## ✅ Release Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- 🏷️ GitHub: [v${{ steps.version.outputs.version }}](https://github.com/${{ github.repository }}/releases/tag/v${{ steps.version.outputs.version }})" >> $GITHUB_STEP_SUMMARY
echo "- 📦 PyPI: [getlate ${{ steps.version.outputs.version }}](https://pypi.org/project/getlate/${{ steps.version.outputs.version }}/)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Install with:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "pip install getlate==${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY