-
Notifications
You must be signed in to change notification settings - Fork 217
153 lines (145 loc) · 4.5 KB
/
publish_release.yml
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
name: Publish the latest release on PyPI
on:
push:
tags:
- 'v*'
branches:
- release # Restricts the workflow to only run on tags pushed to the release branch
workflow_dispatch: # allows manual control
inputs:
version:
description: 'Override the version number'
required: false
rollback:
description: 'Trigger a rollback to the previous stable version'
required: false
default: false
jobs:
validate-tag:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- name: Validate Tag Format
run: |
TAG_REGEX='^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9\-\.]+)?$'
echo "Regex to match: $TAG_REGEX"
TAG="${GITHUB_REF/refs\/tags\//}"
echo "Tag extracted: $TAG"
if [[ "$TAG" =~ $TAG_REGEX ]]; then
echo "Tag format is valid."
else
echo "::error::Tag $TAG does not match the 'vMAJOR.MINOR.PATCH' or 'vMAJOR.MINOR.PATCH-pre-release' format."
exit 1
fi
shell: bash
build-and-package:
needs: validate-tag
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry and dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry env use python${{ matrix.python-version }}
cd lightrag
poetry install --no-dev
- name: Build the distribution
run: |
cd lightrag
poetry build
- name: Upload distribution for publishing
uses: actions/upload-artifact@v2
with:
name: dist
path: lightrag/dist/**
dry-run-publish:
needs: build-and-package
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Download distribution
uses: actions/download-artifact@v2
with:
name: dist
path: dist
- name: Install Poetry and perform dry run publish
run: |
python -m pip install --upgrade pip
pip install poetry
cd dist
poetry publish --dry-run -v
publish-to-pypi:
needs:
- validate-tag
- build-and-package
- dry-run-publish
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Download distribution
uses: actions/download-artifact@v2
with:
name: dist
path: dist
- name: Install Poetry and publish to PyPI
run: |
python -m pip install --upgrade pip
pip install poetry
cd dist
poetry publish --username __token__ --password ${{ secrets.PYPI_KEY }} --verbose
create-github-release:
needs: publish-to-pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Create Release on GitHub
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
body: 'Automated release of version ${{ github.ref_name }}'
draft: false
prerelease: false
rollback:
needs: publish-to-pypi
if: ${{ github.event.inputs.rollback == 'true' }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Rollback to previous stable version
run: |
echo "Rolling back to previous stable version..."
# Add rollback logic here