generated from ultralytics/template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Add GitHub Actions workflow for crate publishing #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
glenn-jocher
wants to merge
9
commits into
main
Choose a base branch
from
feature/publsh
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+150
β0
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8dc2505
Add GitHub Actions workflow for crate publishing
glenn-jocher a9ea6c9
Merge branch 'main' into feature/publsh
pderrenger 1526688
Merge branch 'main' into feature/publsh
pderrenger 19fb28a
Merge branch 'main' into feature/publsh
glenn-jocher d7a77ad
Merge branch 'main' into feature/publsh
glenn-jocher 8108d18
Merge branch 'main' into feature/publsh
onuralpszr 796234e
Merge branch 'main' into feature/publsh
glenn-jocher bc7b455
Merge branch 'main' into feature/publsh
onuralpszr 4257b3f
Merge branch 'main' into feature/publsh
onuralpszr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| # Ultralytics π AGPL-3.0 License - https://ultralytics.com/license | ||
|
|
||
| # Publish crate to crates.io https://crates.io/crates/ultralytics-template-rust | ||
|
|
||
| name: Publish to crates.io | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
| inputs: | ||
| publish: | ||
| type: boolean | ||
| description: Publish to crates.io | ||
|
|
||
| jobs: | ||
| check: | ||
| if: github.repository == 'ultralytics/inference' | ||
| 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-template-rust | ||
onuralpszr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
| - uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.x" | ||
| - uses: astral-sh/setup-uv@v7 | ||
| - 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 | ||
onuralpszr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| run: | | ||
| import os | ||
| import re | ||
| import subprocess | ||
|
|
||
| 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( | ||
onuralpszr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ["git", "ls-remote", "--tags", "origin", current_tag], | ||
| text=True, | ||
| capture_output=True, | ||
| ) | ||
| tag_exists = current_tag in tags or bool(remote.stdout.strip()) | ||
| 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}") | ||
|
|
||
| os.system(f'echo "increment={increment}" >> $GITHUB_OUTPUT') | ||
onuralpszr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| os.system(f'echo "current_tag={current_tag}" >> $GITHUB_OUTPUT') | ||
| os.system(f'echo "previous_tag={previous_tag}" >> $GITHUB_OUTPUT') | ||
| if increment == "True": | ||
| print("Ready to publish new version to crates.io β .") | ||
| - name: Tag and Release | ||
| if: steps.check_version.outputs.increment == '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 "[email protected]" | ||
| 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' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: dtolnay/rust-toolchain@nightly | ||
| with: | ||
| components: rustfmt, clippy | ||
| - uses: Swatinem/rust-cache@v2 | ||
| - run: cargo fmt --all -- --check | ||
| - run: cargo clippy --all-targets --all-features -- -D warnings | ||
| - run: cargo test --all --all-features | ||
|
|
||
| publish: | ||
| needs: [check, build] | ||
| if: needs.check.outputs.increment == 'True' | ||
| runs-on: ubuntu-latest | ||
| environment: | ||
| name: Release - crates.io | ||
| url: ${{ needs.check.outputs.crate_url }} | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| - uses: Swatinem/rust-cache@v2 | ||
| - run: cargo publish | ||
| env: | ||
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | ||
|
|
||
| sbom: | ||
| needs: [check, build, publish] | ||
| if: needs.check.outputs.increment == 'True' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| - uses: Swatinem/rust-cache@v2 | ||
| - name: Generate Cargo.lock for SBOM | ||
| run: cargo generate-lockfile | ||
| - uses: anchore/sbom-action@v0 | ||
| with: | ||
| format: spdx-json | ||
| output-file: sbom.spdx.json | ||
| path: . | ||
| - run: gh release upload ${{ needs.check.outputs.current_tag }} sbom.spdx.json | ||
onuralpszr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.