-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (144 loc) · 4.85 KB
/
Copy pathrelease.yml
File metadata and controls
166 lines (144 loc) · 4.85 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: Release
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: 'true'
on:
workflow_dispatch:
inputs:
tag:
description: Release tag to create, for example v0.1.0
required: true
type: string
target:
description: Branch or commit SHA to release from
required: false
default: main
type: string
title:
description: Optional release title
required: false
default: ""
type: string
prerelease:
description: Mark the release as a prerelease
required: false
default: false
type: boolean
draft:
description: Save the release as a draft instead of publishing it
required: false
default: true
type: boolean
latest:
description: Mark this as the latest release
required: false
default: true
type: boolean
notes_start_tag:
description: Optional previous tag for generated release notes
required: false
default: ""
type: string
jobs:
build_installers:
name: Build release installers
uses: ./.github/workflows/build-installers.yml
with:
git_ref: ${{ inputs.target }}
artifact_prefix: release-${{ github.run_id }}
secrets: inherit
publish_release:
name: Publish GitHub release
needs: build_installers
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout target
uses: actions/checkout@v6
with:
ref: ${{ inputs.target }}
- name: Validate release tag matches project version
shell: bash
env:
RELEASE_TAG: ${{ inputs.tag }}
run: |
python - "$RELEASE_TAG" <<'PY'
import re
from pathlib import Path
import sys
release_tag = sys.argv[1]
pyproject = Path("pyproject.toml").read_text()
pyproject_match = re.search(r'^version = "([^"]+)"$', pyproject, re.MULTILINE)
if pyproject_match is None:
raise SystemExit("Could not find version in pyproject.toml")
pyproject_version = pyproject_match.group(1)
module = Path("openbeat/__init__.py").read_text()
module_match = re.search(r'^__version__ = "([^"]+)"$', module, re.MULTILINE)
if module_match is None:
raise SystemExit("Could not find __version__ in openbeat/__init__.py")
module_version = module_match.group(1)
if pyproject_version != module_version:
raise SystemExit(
f"Version mismatch: pyproject.toml={pyproject_version}, "
f"openbeat/__init__.py={module_version}"
)
expected_tag = f"v{pyproject_version}"
if release_tag != expected_tag:
raise SystemExit(
f"Release tag must match project version. "
f"Expected {expected_tag}, got {release_tag}."
)
PY
- name: Download installer artifacts
uses: actions/download-artifact@v8
with:
pattern: release-${{ github.run_id }}-*
path: dist/release-assets
merge-multiple: true
- name: Create GitHub release
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ inputs.tag }}
RELEASE_TITLE: ${{ inputs.title }}
RELEASE_TARGET: ${{ inputs.target }}
RELEASE_NOTES_START_TAG: ${{ inputs.notes_start_tag }}
RELEASE_PRERELEASE: ${{ inputs.prerelease }}
RELEASE_DRAFT: ${{ inputs.draft }}
RELEASE_LATEST: ${{ inputs.latest }}
run: |
mapfile -t assets < <(find dist/release-assets -maxdepth 1 -type f | sort)
if [[ ${#assets[@]} -eq 0 ]]; then
echo "No release assets were downloaded."
exit 1
fi
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
echo "Release $RELEASE_TAG already exists."
exit 1
fi
release_title="$RELEASE_TITLE"
if [[ -z "$release_title" ]]; then
release_title="OpenBeat $RELEASE_TAG"
fi
args=(
release create "$RELEASE_TAG"
--title "$release_title"
--target "$RELEASE_TARGET"
--generate-notes
)
if [[ "$RELEASE_LATEST" == "true" ]]; then
args+=(--latest)
else
args+=(--latest=false)
fi
if [[ "$RELEASE_PRERELEASE" == "true" ]]; then
args+=(--prerelease)
fi
if [[ "$RELEASE_DRAFT" == "true" ]]; then
args+=(--draft)
fi
if [[ -n "$RELEASE_NOTES_START_TAG" ]]; then
args+=(--notes-start-tag "$RELEASE_NOTES_START_TAG")
fi
args+=("${assets[@]}")
gh "${args[@]}"