-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (122 loc) · 3.34 KB
/
Copy pathrelease.yml
File metadata and controls
140 lines (122 loc) · 3.34 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: release
on:
push:
tags:
- "v*"
workflow_call:
inputs:
tag_name:
required: true
type: string
prerelease:
required: true
type: boolean
environment_name:
required: true
type: string
workflow_dispatch:
inputs:
tag_name:
description: "Tag to release"
required: true
type: string
prerelease:
description: "Publish as prerelease"
required: true
type: boolean
environment_name:
description: "GitHub environment to use"
required: true
type: choice
options:
- release
- release-rc
permissions:
contents: write
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.vars.outputs.tag_name }}
prerelease: ${{ steps.vars.outputs.prerelease }}
environment_name: ${{ steps.vars.outputs.environment_name }}
steps:
- name: Resolve release parameters
id: vars
run: |
tag_name="${{ inputs.tag_name || github.ref_name }}"
prerelease="${{ inputs.prerelease }}"
environment_name="${{ inputs.environment_name }}"
if [[ -z "$prerelease" ]]; then
if [[ "$tag_name" == *-rc.* ]]; then
prerelease=true
else
prerelease=false
fi
fi
if [[ -z "$environment_name" ]]; then
if [[ "$tag_name" == *-rc.* ]]; then
environment_name=release-rc
else
environment_name=release
fi
fi
echo "tag_name=$tag_name" >> "$GITHUB_OUTPUT"
echo "prerelease=$prerelease" >> "$GITHUB_OUTPUT"
echo "environment_name=$environment_name" >> "$GITHUB_OUTPUT"
build:
runs-on: ubuntu-latest
needs: prepare
steps:
- name: Check out repository
uses: actions/checkout@v7
with:
ref: refs/tags/${{ needs.prepare.outputs.tag_name }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Build distributions
run: |
python -m pip install --upgrade pip build
python -m build
- name: Upload build artifacts
uses: actions/upload-artifact@v7
with:
name: dist
path: dist/*
publish:
runs-on: ubuntu-latest
environment:
name: ${{ needs.prepare.outputs.environment_name }}
needs:
- prepare
- build
steps:
- name: Download build artifacts
uses: actions/download-artifact@v8
with:
name: dist
path: dist
- name: Create GitHub release
run: |
tag="${{ needs.prepare.outputs.tag_name }}"
title="Release: ${tag}"
if gh release view "$tag" >/dev/null 2>&1; then
echo "Release $tag already exists, skipping."
exit 0
fi
args=(
release create "$tag"
dist/*
--title "$title"
--generate-notes
)
if [[ "${{ needs.prepare.outputs.prerelease }}" == "true" ]]; then
args+=(--prerelease)
fi
gh "${args[@]}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}