-
Notifications
You must be signed in to change notification settings - Fork 26
140 lines (126 loc) · 5.01 KB
/
publish.yml
File metadata and controls
140 lines (126 loc) · 5.01 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
name: "Publish"
on:
push:
branches:
- main
paths:
- 'codeflash/version.py'
- 'codeflash-benchmark/codeflash_benchmark/version.py'
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
codeflash: ${{ steps.filter.outputs.codeflash }}
benchmark: ${{ steps.filter.outputs.benchmark }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Detect which packages changed
id: filter
run: |
if git diff --name-only HEAD~1 HEAD | grep -q '^codeflash/version.py$'; then
echo "codeflash=true" >> $GITHUB_OUTPUT
else
echo "codeflash=false" >> $GITHUB_OUTPUT
fi
if git diff --name-only HEAD~1 HEAD | grep -q '^codeflash-benchmark/codeflash_benchmark/version.py$'; then
echo "benchmark=true" >> $GITHUB_OUTPUT
else
echo "benchmark=false" >> $GITHUB_OUTPUT
fi
publish:
needs: detect-changes
if: >-
needs.detect-changes.outputs.codeflash == 'true'
|| needs.detect-changes.outputs.benchmark == 'true'
strategy:
fail-fast: false
matrix:
include:
- package: codeflash
version_file: codeflash/version.py
tag_prefix: v
build_cmd: uv build
flag: codeflash
release_name_prefix: "Release"
- package: codeflash-benchmark
version_file: codeflash-benchmark/codeflash_benchmark/version.py
tag_prefix: benchmark-v
build_cmd: uv build --package codeflash-benchmark
flag: benchmark
release_name_prefix: "codeflash-benchmark"
runs-on: ubuntu-latest
environment:
name: pypi
permissions:
id-token: write
contents: write
steps:
- name: Check if this matrix leg should run
id: should_run
run: |
if [[ "${{ matrix.flag }}" == "codeflash" && "${{ needs.detect-changes.outputs.codeflash }}" == "true" ]]; then
echo "run=true" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.flag }}" == "benchmark" && "${{ needs.detect-changes.outputs.benchmark }}" == "true" ]]; then
echo "run=true" >> $GITHUB_OUTPUT
else
echo "run=false" >> $GITHUB_OUTPUT
fi
- name: Checkout
if: steps.should_run.outputs.run == 'true'
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Extract version from version.py
if: steps.should_run.outputs.run == 'true'
id: extract_version
run: |
VERSION=$(grep -oP '__version__ = "\K[^"]+' ${{ matrix.version_file }})
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=${{ matrix.tag_prefix }}$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Check if tag already exists
if: steps.should_run.outputs.run == 'true'
id: check_tag
run: |
if git rev-parse "${{ steps.extract_version.outputs.tag }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag ${{ steps.extract_version.outputs.tag }} already exists, skipping release"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Tag ${{ steps.extract_version.outputs.tag }} does not exist, proceeding with release"
fi
- name: Create and push git tag
if: steps.should_run.outputs.run == 'true' && steps.check_tag.outputs.exists == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.extract_version.outputs.tag }}" -m "Release ${{ steps.extract_version.outputs.tag }}"
git push origin "${{ steps.extract_version.outputs.tag }}"
- name: Install uv
if: steps.should_run.outputs.run == 'true' && steps.check_tag.outputs.exists == 'false'
uses: astral-sh/setup-uv@v8.1.0
with:
enable-cache: true
- name: Build
if: steps.should_run.outputs.run == 'true' && steps.check_tag.outputs.exists == 'false'
run: ${{ matrix.build_cmd }}
- name: Publish to PyPI
if: steps.should_run.outputs.run == 'true' && steps.check_tag.outputs.exists == 'false'
run: uv publish
- name: Create GitHub Release
if: steps.should_run.outputs.run == 'true' && steps.check_tag.outputs.exists == 'false'
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.extract_version.outputs.tag }}
name: ${{ matrix.release_name_prefix }} ${{ steps.extract_version.outputs.tag }}
body: |
## What's Changed
Release ${{ steps.extract_version.outputs.version }} of ${{ matrix.package }}.
**Full Changelog**: https://github.com/${{ github.repository }}/commits/${{ steps.extract_version.outputs.tag }}
draft: false
prerelease: false
files: |
dist/*