Skip to content

Commit bc10c7a

Browse files
author
ChidcGithub
committed
Add auto-release workflow on successful tests
- Create GitHub release automatically when tests pass - Only create release if tag doesn't exist (version change) - Release body includes version, build info, timestamp - Publish to PyPI after successful release
1 parent 76d5211 commit bc10c7a

1 file changed

Lines changed: 59 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
branches: [main, master]
66
pull_request:
77
branches: [main, master]
8-
release:
9-
types: [published]
108

119
jobs:
1210
test:
@@ -99,10 +97,67 @@ jobs:
9997
name: dist
10098
path: dist/
10199

100+
release:
101+
needs: [test, lint, build]
102+
runs-on: ubuntu-latest
103+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
104+
permissions:
105+
contents: write
106+
outputs:
107+
released: ${{ steps.check_tag.outputs.exists == 'false' }}
108+
version: ${{ steps.version.outputs.version }}
109+
110+
steps:
111+
- uses: actions/checkout@v4
112+
with:
113+
fetch-depth: 0
114+
115+
- name: Download artifacts
116+
uses: actions/download-artifact@v4
117+
with:
118+
name: dist
119+
path: dist/
120+
121+
- name: Get version
122+
id: version
123+
run: |
124+
VERSION=$(python -c "import sys; sys.path.insert(0, '.'); from cognipy import __version__; print(__version__)")
125+
echo "version=$VERSION" >> $GITHUB_OUTPUT
126+
127+
- name: Check if tag exists
128+
id: check_tag
129+
run: |
130+
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
131+
echo "exists=true" >> $GITHUB_OUTPUT
132+
else
133+
echo "exists=false" >> $GITHUB_OUTPUT
134+
fi
135+
136+
- name: Create Release
137+
if: steps.check_tag.outputs.exists == 'false'
138+
uses: softprops/action-gh-release@v1
139+
with:
140+
tag_name: v${{ steps.version.outputs.version }}
141+
name: Release v${{ steps.version.outputs.version }}
142+
body: |
143+
## Version
144+
v${{ steps.version.outputs.version }}
145+
146+
## Build Info
147+
- Runner OS: ${{ runner.os }}
148+
- Build Time: ${{ github.event.head_commit.timestamp }}
149+
- Commit: ${{ github.sha }}
150+
- Branch: ${{ github.ref_name }}
151+
files: dist/*
152+
draft: false
153+
prerelease: false
154+
env:
155+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
156+
102157
publish:
103-
needs: build
158+
needs: release
104159
runs-on: ubuntu-latest
105-
if: github.event_name == 'release'
160+
if: needs.release.outputs.released == 'true'
106161
permissions:
107162
id-token: write
108163

0 commit comments

Comments
 (0)