-
-
Notifications
You must be signed in to change notification settings - Fork 16
182 lines (169 loc) · 7.48 KB
/
Copy pathpublish.yml
File metadata and controls
182 lines (169 loc) · 7.48 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# Publish crate to crates.io https://crates.io/crates/ultralytics-inference
name: Publish to crates.io
on:
push:
branches: [main]
workflow_dispatch:
inputs:
publish:
type: boolean
description: Publish to crates.io
default: false
jobs:
check:
if: github.repository == 'ultralytics/inference' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
increment: ${{ steps.check_version.outputs.increment }}
current_tag: ${{ steps.check_version.outputs.current_tag }}
previous_tag: ${{ steps.check_version.outputs.previous_tag }}
crate_url: https://crates.io/crates/ultralytics-inference
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: "3.x"
- uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
enable-cache: false
- name: Install ultralytics-actions
run: uv pip install --system --no-cache ultralytics-actions
- name: Fetch tags
run: git fetch --tags --force
- id: check_version
shell: python
run: |
import os
import re
import subprocess
from pathlib import Path
version = None
with open("Cargo.toml") as f:
for line in f:
m = re.search(r'version\s*=\s*"([^"]+)"', line)
if m:
version = m.group(1)
break
if not version:
raise SystemExit("Version not found in Cargo.toml")
current_tag = f"v{version}"
tags = subprocess.run(
["git", "tag", "--sort=-creatordate"],
text=True,
capture_output=True,
check=True,
).stdout.strip().splitlines()
previous_tag = next((t for t in tags if t != current_tag), "")
remote = subprocess.run(
["git", "ls-remote", "--exit-code", "--tags", "origin", f"refs/tags/{current_tag}"],
text=True,
capture_output=True,
)
if remote.returncode not in (0, 2):
raise SystemExit(remote.stderr.strip() or "Failed to check remote tag")
tag_exists = current_tag in tags or remote.returncode == 0
increment = str(not tag_exists)
print(f"Local version: {version}")
print(f"Current tag: {current_tag}")
print(f"Previous tag: {previous_tag or '<none>'}")
print(f"Tag exists: {tag_exists}")
with Path(os.environ["GITHUB_OUTPUT"]).open("a") as f:
print(f"increment={increment}", file=f)
print(f"current_tag={current_tag}", file=f)
print(f"previous_tag={previous_tag}", file=f)
if increment == "True":
print("Ready to publish new version to crates.io ✅.")
- name: Tag and Release
if: steps.check_version.outputs.increment == 'True' && (github.event_name == 'push' || inputs.publish == true)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CURRENT_TAG: ${{ steps.check_version.outputs.current_tag }}
PREVIOUS_TAG: ${{ steps.check_version.outputs.previous_tag }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
git config --global user.name "UltralyticsAssistant"
git config --global user.email "web@ultralytics.com"
git tag -a "$CURRENT_TAG" -m "$(git log -1 --pretty=%B)"
git push origin "$CURRENT_TAG"
ultralytics-actions-summarize-release
uv cache prune --ci
build:
needs: check
if: needs.check.outputs.increment == 'True' && (github.event_name == 'push' || inputs.publish == true)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
- run: cargo fmt --all -- --check
- run: cargo clippy --all-targets --no-default-features --features annotate -- -D warnings
- run: cargo test --no-default-features --features annotate
- run: cargo package --locked --list
- run: cargo publish --dry-run --locked
publish:
needs: [check, build]
if: needs.check.outputs.increment == 'True' && (github.event_name == 'push' || inputs.publish == true)
runs-on: ubuntu-latest
environment:
name: Release - crates.io
url: ${{ needs.check.outputs.crate_url }}
permissions:
contents: read
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
- run: cargo publish --locked
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
sbom:
needs: [check, build, publish]
if: needs.check.outputs.increment == 'True' && (github.event_name == 'push' || inputs.publish == true)
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
- name: Generate Cargo.lock for SBOM
run: cargo generate-lockfile
- uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
with:
format: spdx-json
output-file: sbom.spdx.json
path: .
- run: gh release upload ${{ needs.check.outputs.current_tag }} sbom.spdx.json --clobber
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
notify:
needs: [check, build, publish, sbom]
if: always() && needs.check.outputs.increment == 'True' && (github.event_name == 'push' || inputs.publish == true)
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Notify Success
if: needs.build.result == 'success' && needs.publish.result == 'success' && needs.sbom.result == 'success'
uses: slackapi/slack-github-action@0d95c9a7becc1e6e297d76df9bc735c44f4cbcbc # v3.0.5
with:
webhook-type: incoming-webhook
webhook: ${{ secrets.SLACK_WEBHOOK_URL_YOLO }}
payload: |
text: "<!subteam^S082BPCRAJ3> *${{ github.workflow }}* ✅ `${{ github.repository }}` ${{ needs.check.outputs.current_tag }} <https://github.com/${{ github.repository }}/releases/tag/${{ needs.check.outputs.current_tag }}|*Release*> · <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|*Run*>"
- name: Notify Failure
if: needs.build.result != 'success' || needs.publish.result != 'success' || needs.sbom.result != 'success'
uses: slackapi/slack-github-action@0d95c9a7becc1e6e297d76df9bc735c44f4cbcbc # v3.0.5
with:
webhook-type: incoming-webhook
webhook: ${{ secrets.SLACK_WEBHOOK_URL_YOLO }}
payload: |
text: "<!subteam^S082BPCRAJ3> *${{ github.workflow }}* ❌ `${{ github.repository }}` ${{ needs.check.outputs.current_tag }} <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|*Run*>"