-
Notifications
You must be signed in to change notification settings - Fork 46
134 lines (120 loc) · 3.97 KB
/
Copy pathrelease.yml
File metadata and controls
134 lines (120 loc) · 3.97 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
name: Release
on:
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g. v1.16). Leave blank to skip GitHub Release.'
required: false
type: string
default: ""
publish_to_testpypi:
description: 'Publish wheels/sdist to TestPyPI'
type: boolean
default: false
push:
tags:
- v*
permissions:
contents: write
id-token: write
jobs:
validate-tag:
runs-on: ubuntu-latest
if: inputs.tag != '' || github.event_name == 'push'
outputs:
tag: ${{ steps.set-tag.outputs.tag }}
steps:
- name: Determine tag
id: set-tag
run: |
if [ "${{ github.event_name }}" = "push" ]; then
TAG="${{ github.ref_name }}"
else
TAG="${{ inputs.tag }}"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
- name: Check tag format
run: |
TAG="${{ steps.set-tag.outputs.tag }}"
if [[ ! "${TAG}" =~ ^v[0-9]+\.[0-9]+(\.[0-9]+)?(-[a-zA-Z0-9._-]+)?$ ]]; then
echo "::error::Tag '${TAG}' is not valid. Must match vMAJOR.MINOR[.PATCH][-prerelease]"
exit 1
fi
echo "Tag '${TAG}' is valid."
build-linux:
uses: ./.github/workflows/build-linux.yml
build-macos:
uses: ./.github/workflows/build-macos.yml
build-windows:
uses: ./.github/workflows/build-windows.yml
publish-testpypi:
name: Publish to TestPyPI
needs: [build-linux, build-macos, build-windows]
if: inputs.publish_to_testpypi
runs-on: ubuntu-latest
environment:
name: release
url: https://test.pypi.org/p/python-lzo
steps:
- uses: actions/download-artifact@v6
with:
path: dist
- run: |
mv dist/*/*.whl dist/ 2>/dev/null || true
mv dist/*/*.tar.gz dist/ 2>/dev/null || true
find dist -mindepth 1 -type d -delete
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
publish-github-release:
name: Publish GitHub Release
needs: [validate-tag, build-linux, build-macos, build-windows]
if: |
always() &&
needs.validate-tag.result == 'success' &&
!cancelled() &&
!contains(needs.*.result, 'failure')
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.validate-tag.outputs.tag }}
steps:
- name: Checkout repo
uses: actions/checkout@v6
with:
fetch-depth: 0
persist-credentials: true
- name: Download all artifacts
uses: actions/download-artifact@v6
with:
path: dist
- name: Flatten artifacts
run: |
mv dist/*/*.whl dist/ 2>/dev/null || true
mv dist/*/*.tar.gz dist/ 2>/dev/null || true
find dist -mindepth 1 -type d -delete
- name: List artifacts
run: ls -lh dist/
- name: Create git tag if it does not exist
run: |
if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q "${TAG}"; then
echo "Tag ${TAG} already exists — skipping tag creation."
else
echo "Tag ${TAG} does not exist — creating it from HEAD."
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${TAG}" -m "Release ${TAG}"
git push origin "${TAG}"
echo "Tag ${TAG} pushed."
fi
- name: Create or update GitHub release
run: |
if gh release view "${TAG}" > /dev/null 2>&1; then
echo "Release for ${TAG} already exists — replacing assets."
gh release upload "${TAG}" dist/*.whl dist/*.tar.gz --clobber
else
echo "No release for ${TAG} yet — creating release and uploading assets."
gh release create "${TAG}" dist/*.whl dist/*.tar.gz \
--title "${TAG}" \
--generate-notes
fi