forked from PrimeIntellect-ai/prime
-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (176 loc) · 6.27 KB
/
release.yml
File metadata and controls
194 lines (176 loc) · 6.27 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Tag and Release
on:
push:
branches:
- main
workflow_dispatch:
inputs:
tag:
description: 'Tag to create release from (e.g. v1.2.3)'
required: false
type: string
jobs:
tag-and-release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
outputs:
version: ${{ steps.version.outputs.version }}
release_created: ${{ steps.release_status.outputs.created }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
# Get version from package source on push
- name: Get version from src/prime_cli/__init__.py
if: github.event_name == 'push'
id: auto_version
run: |
VERSION=$(grep -E "^__version__[[:space:]]*=" src/prime_cli/__init__.py | head -n1 | sed -E "s/^__version__[[:space:]]*=[[:space:]]*['\"]([^'\"]+)['\"].*/\1/")
if [ -z "$VERSION" ]; then
echo "Error: Unable to parse __version__" >&2
exit 1
fi
echo "VERSION=$VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Get version from manual input
- name: Get version from input
if: github.event_name == 'workflow_dispatch' && inputs.tag != ''
id: manual_version
run: |
VERSION=${{ inputs.tag }}
VERSION=${VERSION#v}
echo "VERSION=$VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Combine versions and verify
- name: Set final version
id: version
run: |
VERSION="${{ steps.auto_version.outputs.version || steps.manual_version.outputs.version }}"
if [ -z "$VERSION" ]; then
echo "Error: No version found"
exit 1
fi
echo "VERSION=$VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Check if tag exists
- name: Check for existing tag
id: check_tag
run: |
if git tag -l "v${{ steps.version.outputs.version }}" | grep -q .; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag v${{ steps.version.outputs.version }} already exists. Skipping release."
exit 0
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
# Create new tag if it doesn't exist
- name: Create tag
if: steps.check_tag.outputs.exists != 'true'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
# Setup Python for build
- name: Set up Python
if: steps.check_tag.outputs.exists != 'true'
uses: actions/setup-python@v4
with:
python-version: '3.11'
# Install uv and build tools
- name: Install uv
if: steps.check_tag.outputs.exists != 'true'
uses: astral-sh/setup-uv@v3
- name: Create virtual environment and install build tools
if: steps.check_tag.outputs.exists != 'true'
run: |
uv venv
source .venv/bin/activate
uv pip install build twine
# Build package
- name: Build package
if: steps.check_tag.outputs.exists != 'true'
run: |
source .venv/bin/activate
python -m build
- name: Upload build artifacts
if: steps.check_tag.outputs.exists != 'true'
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/*
# Create GitHub Release
- name: Create GitHub Release
if: steps.check_tag.outputs.exists != 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.version.outputs.version }}
files: dist/*
generate_release_notes: true
# Publish to PyPI
- name: Publish to PyPI
if: steps.check_tag.outputs.exists != 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
source .venv/bin/activate
twine upload dist/*
- name: Set release status
id: release_status
run: |
if [ "${{ steps.check_tag.outputs.exists }}" = "true" ]; then
echo "created=false" >> "$GITHUB_OUTPUT"
else
echo "created=true" >> "$GITHUB_OUTPUT"
fi
docker-images:
needs: tag-and-release
if: needs.tag-and-release.outputs.release_created == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist
- name: Log in to GitHub Container Registry
env:
CR_PAT: ${{ github.token }}
run: echo "$CR_PAT" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and push Docker image
env:
VERSION: ${{ needs.tag-and-release.outputs.version }}
PYTHON_VERSION: ${{ matrix.python-version }}
REPOSITORY: ${{ github.repository }}
run: |
IMAGE_PATH=$(echo "$REPOSITORY" | tr '[:upper:]' '[:lower:]')
IMAGE="ghcr.io/$IMAGE_PATH"
PY_TAG="py${PYTHON_VERSION}"
docker build --build-arg PRIME_VERSION="$VERSION" \
--build-arg PYTHON_VERSION="$PYTHON_VERSION" \
-t "$IMAGE:$VERSION-$PY_TAG" \
-t "$IMAGE:v$VERSION-$PY_TAG" \
-t "$IMAGE:$PY_TAG" .
docker push "$IMAGE:$VERSION-$PY_TAG"
docker push "$IMAGE:v$VERSION-$PY_TAG"
docker push "$IMAGE:$PY_TAG"
if [ "$PYTHON_VERSION" = "3.11" ]; then
docker tag "$IMAGE:$VERSION-$PY_TAG" "$IMAGE:$VERSION"
docker tag "$IMAGE:$VERSION-$PY_TAG" "$IMAGE:v$VERSION"
docker tag "$IMAGE:$VERSION-$PY_TAG" "$IMAGE:latest"
docker push "$IMAGE:$VERSION"
docker push "$IMAGE:v$VERSION"
docker push "$IMAGE:latest"
fi