-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (134 loc) · 5.87 KB
/
auto-release.yml
File metadata and controls
162 lines (134 loc) · 5.87 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
155
156
157
158
159
160
161
162
name: Auto Release on Push
on:
push:
branches: [ main, master ]
paths-ignore:
- '**.md'
- '.github/**'
- 'CHANGELOG.md'
jobs:
auto-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.AI_GITHUB_TOKEN }}
ssh-strict: false
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Install GitHub CLI
run: |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt-get update
sudo apt-get install gh -y
- name: Run tests
run: |
python -m pytest tests/ -v --cov=cost_katana --cov-report=xml
python -m pytest test_basic_functionality.py -v
- name: Run linting
run: |
python -m flake8 cost_katana/ tests/ --count --select=E9,F63,F7,F82 --show-source --statistics
python -m flake8 cost_katana/ tests/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Build package
run: |
python setup.py sdist bdist_wheel
- name: Get current version
id: current_version
run: |
CURRENT_VERSION=$(python setup.py --version)
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Calculate new version
id: new_version
run: |
CURRENT_VERSION="${{ steps.current_version.outputs.current_version }}"
# Split version into components
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]}"
MINOR="${VERSION_PARTS[1]}"
PATCH="${VERSION_PARTS[2]}"
# Always bump patch version for auto-releases
NEW_MAJOR=$MAJOR
NEW_MINOR=$MINOR
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$NEW_MAJOR.$NEW_MINOR.$NEW_PATCH"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Update version in setup.py
run: |
sed -i "s/version=\"[^\"]*\"/version=\"${{ steps.new_version.outputs.new_version }}\"/" setup.py
echo "Updated setup.py version to ${{ steps.new_version.outputs.new_version }}"
- name: Verify PyPI token
run: |
if [ -n "${{ secrets.PYPI_TOKEN }}" ]; then
echo "PYPI_TOKEN is available"
echo "[pypi]" > ~/.pypirc
echo "username = __token__" >> ~/.pypirc
echo "password = ${{ secrets.PYPI_TOKEN }}" >> ~/.pypirc
else
echo "PYPI_TOKEN is not available"
exit 1
fi
- name: Publish to PyPI
run: |
echo "[pypi]" > ~/.pypirc
echo "username = __token__" >> ~/.pypirc
echo "password = ${{ secrets.PYPI_TOKEN }}" >> ~/.pypirc
python -m twine upload --repository pypi dist/*
echo "Successfully published cost-katana@${{ steps.new_version.outputs.new_version }} to PyPI"
- name: Create and push tag
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Configure git to use the token for authentication
git remote set-url origin https://x-access-token:${{ secrets.AI_GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
# Verify the remote URL is set correctly
echo "Remote URL: $(git remote get-url origin)"
# Add and commit changes
git add setup.py
git commit -m "Auto-release: Bump version to ${{ steps.new_version.outputs.new_version }}"
# Create tag
git tag -a "v${{ steps.new_version.outputs.new_version }}" -m "Auto-release version ${{ steps.new_version.outputs.new_version }}"
# Push with explicit authentication
if ! git push origin HEAD:${{ github.ref }}; then
echo "Git push failed, trying with GitHub CLI..."
gh auth login --with-token <<< "${{ secrets.AI_GITHUB_TOKEN }}"
git push origin HEAD:${{ github.ref }}
fi
if ! git push origin "v${{ steps.new_version.outputs.new_version }}"; then
echo "Tag push failed, trying with GitHub CLI..."
gh auth login --with-token <<< "${{ secrets.AI_GITHUB_TOKEN }}"
git push origin "v${{ steps.new_version.outputs.new_version }}"
fi
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.AI_GITHUB_TOKEN }}
with:
tag_name: v${{ steps.new_version.outputs.new_version }}
release_name: Auto-release v${{ steps.new_version.outputs.new_version }}
body: |
## Auto-release v${{ steps.new_version.outputs.new_version }}
This is an automatic release triggered by changes to the main branch.
### Installation
```bash
pip install cost-katana==${{ steps.new_version.outputs.new_version }}
```
### Changes
- Automatic version bump and release
- Updated dependencies and improvements
- Enhanced Python package structure
- Better error handling
draft: false
prerelease: false