-
Notifications
You must be signed in to change notification settings - Fork 218
156 lines (148 loc) · 4.61 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
154
155
156
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:
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
steps:
- uses: actions/checkout@v3
- name: Validate Tag Format
run: |
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
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
else
echo "No tag associated with push, skipping tag validation."
exit 78 # Exiting with neutral status
fi
shell: bash
build-and-package:
needs: validate-tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- 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 poetry
poetry install --no-dev
- name: Build the distribution
run: poetry build
- name: Upload distribution for publishing
uses: actions/upload-artifact@v2
with:
name: dist
path: dist/**
dry-run-publish:
needs: build-and-package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Download distribution
uses: actions/download-artifact@v2
with:
name: dist
path: dist
- name: Dry run publish to PyPI
run: |
poetry publish --dry-run --build
# Uncomment the following lines to enable TestPyPI publishing
# test-publish-to-testpypi:
# needs: build-and-package
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: '3.11'
# - name: Download distribution
# uses: actions/download-artifact@v2
# with:
# name: dist
# path: dist
# - name: Publish to TestPyPI
# run: |
# poetry config repositories.testpypi https://test.pypi.org/legacy/
# poetry publish --repository testpypi --username __token__ --password ${{ secrets.TEST_PYPI_API_TOKEN }}
# publish-to-pypi:
# needs:
# - validate-tag
# - build-and-package
# - dry-run-publish
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Download distribution
# uses: actions/download-artifact@v2
# with:
# name: dist
# path: dist
# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: '3.11'
# - name: Publish to PyPI
# uses: pypa/[email protected]
# with:
# user: __token__
# password: ${{ secrets.PYPI_KEY }}
# 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
# steps:
# - uses: actions/checkout@v3
# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: '3.11'
# - name: Rollback to previous stable version
# run: |
# echo "Rolling back to previous stable version..."
# # Add rollback logic here