Repository navigation
Expand file tree
/
Copy pathrelease-create-cli-release.yaml
More file actions
154 lines (128 loc) · 5.18 KB
/
Copy pathrelease-create-cli-release.yaml
File metadata and controls
154 lines (128 loc) · 5.18 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
154
---
name: Release - Create CLI GitHub Release
'on':
push:
tags:
- 'v*.*.*' # Trigger on version tags like v1.0.0, v2.1.3, etc.
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Extract version from tag
id: version
run: |
# Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0)
VERSION="${GITHUB_REF#refs/tags/}"
VERSION="${VERSION#v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$GITHUB_REF_NAME" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION from tag $GITHUB_REF_NAME"
- name: Validate version consistency
run: |
TAG_VERSION="${{ steps.version.outputs.version }}"
# Extract version from pyproject.toml
PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
# Extract version from cli/__init__.py
CLI_VERSION=$(grep '^__version__ = ' cli/__init__.py | sed 's/__version__ = "\(.*\)"/\1/')
echo "Tag version: $TAG_VERSION"
echo "pyproject.toml: $PYPROJECT_VERSION"
echo "cli/__init__.py: $CLI_VERSION"
echo ""
# Check if all versions match
if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) does not match pyproject.toml version ($PYPROJECT_VERSION)"
echo "Please update pyproject.toml to version $TAG_VERSION before creating the release."
exit 1
fi
if [ "$TAG_VERSION" != "$CLI_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) does not match cli/__init__.py version ($CLI_VERSION)"
echo "Please update cli/__init__.py to version $TAG_VERSION before creating the release."
exit 1
fi
echo "Version consistency check passed"
echo "All version strings match: $TAG_VERSION"
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.14'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: python -m build
- name: Check distribution
run: |
echo "Built packages:"
ls -lh dist/
echo ""
echo "Checking package integrity:"
twine check dist/*
# PyPI publishing disabled for now - install via GitHub releases
# - name: Publish to PyPI
# if: >
# ${{ !contains(steps.version.outputs.version, 'alpha') &&
# !contains(steps.version.outputs.version, 'beta') &&
# !contains(steps.version.outputs.version, 'rc') }}
# env:
# TWINE_USERNAME: __token__
# TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
# run: |
# echo "Publishing to PyPI..."
# twine upload dist/*
- name: Extract changelog for this version
id: changelog
run: |
# Extract the changelog for this version from CHANGELOG.md
VERSION="${{ steps.version.outputs.version }}"
# First try to extract the section for this specific version
CHANGELOG=$(awk -v ver="$VERSION" '/^## \[/{if($0 ~ "\\[" ver "\\]"){flag=1; next} else if(flag){exit}} flag' CHANGELOG.md)
# If empty, fall back to [Unreleased] section
if [ -z "$CHANGELOG" ]; then
CHANGELOG=$(awk '/^## \[Unreleased\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md)
fi
if [ -z "$CHANGELOG" ]; then
echo "No changelog entries found for this release"
CHANGELOG="See commit history for details."
fi
# Save to output using heredoc to handle multiline
{
echo 'content<<EOF'
echo "$CHANGELOG"
echo EOF
} >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Release ${{ steps.version.outputs.tag }}
body: |
## Boilerplates CLI ${{ steps.version.outputs.tag }}
${{ steps.changelog.outputs.content }}
---
### Installation
Install using the installation script:
```bash
curl -fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh | bash
```
Or install a specific version:
```bash
curl -fsSL https://raw.githubusercontent.com/christianlempa/boilerplates/main/scripts/install.sh |
bash -s -- --version ${{ steps.version.outputs.tag }}
```
draft: false
prerelease: >
${{ contains(steps.version.outputs.version, 'alpha') ||
contains(steps.version.outputs.version, 'beta') ||
contains(steps.version.outputs.version, 'rc') }}
files: |
dist/*.whl
dist/*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}