Skip to content

Commit

Permalink
Merge pull request #1267 from axodotdev/cli
Browse files Browse the repository at this point in the history
feat: make cargo optional
  • Loading branch information
mistydemeo authored Oct 24, 2024
2 parents 5acb9fe + a4eb7bc commit 94dd0b6
Show file tree
Hide file tree
Showing 101 changed files with 1,417 additions and 1,377 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-crates.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Publishes our workspace's crates to crates.io
#
# This is triggered automatically by cargo-dist during the publish step
# This is triggered automatically by dist during the publish step
# (this is a custom publish job: https://opensource.axo.dev/cargo-dist/book/ci/customizing.html#custom-jobs)
#
# It is assumed that all crates are versioned and released in lockstep,
Expand Down
54 changes: 27 additions & 27 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# This file was autogenerated by cargo-dist: https://opensource.axo.dev/cargo-dist/
# This file was autogenerated by dist: https://opensource.axo.dev/cargo-dist/
#
# Copyright 2022-2024, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
# CI that:
#
# * checks for a Git Tag that looks like a release
# * builds artifacts with cargo-dist (archives, installers, hashes)
# * builds artifacts with dist (archives, installers, hashes)
# * uploads those artifacts to temporary workflow zip
# * on success, uploads the artifacts to Axo Releases and makes an Announcement
# * on success, uploads the artifacts to a GitHub Release
Expand All @@ -27,10 +27,10 @@ permissions:
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
#
# If PACKAGE_NAME is specified, then the announcement will be for that
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
# package (erroring out if it doesn't have the given version or isn't dist-able).
#
# If PACKAGE_NAME isn't specified, then the announcement will be for all
# (cargo-dist-able) packages in the workspace with that version (this mode is
# (dist-able) packages in the workspace with that version (this mode is
# intended for workspaces with only one dist-able package, or with all dist-able
# packages versioned/released in lockstep).
#
Expand All @@ -48,7 +48,7 @@ on:
- '**[0-9]+.[0-9]+.[0-9]+*'

jobs:
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
# Run 'dist plan' (or host) to determine what tasks we need to do
plan:
runs-on: "ubuntu-20.04"
outputs:
Expand All @@ -63,25 +63,25 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install cargo-dist
- name: Install dist
# we specify bash to get pipefail; it guards against the `curl` command
# failing. otherwise `sh` won't catch that `curl` returned non-0
shell: bash
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.23.0/cargo-dist-installer.sh | sh"
- name: Cache cargo-dist
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.24.0-prerelease.2/cargo-dist-installer.sh | sh"
- name: Cache dist
uses: actions/upload-artifact@v4
with:
name: cargo-dist-cache
path: ~/.cargo/bin/cargo-dist
path: ~/.cargo/bin/dist
# sure would be cool if github gave us proper conditionals...
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
# functionality based on whether this is a pull_request, and whether it's from a fork.
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
# but also really annoying to build CI around when it needs secrets to work right.)
- id: plan
run: |
cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || (env.AXO_RELEASES_TOKEN && 'host --steps=check') || 'plan' }} --output-format=json > plan-dist-manifest.json
echo "cargo dist ran successfully"
dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || (env.AXO_RELEASES_TOKEN && 'host --steps=check') || 'plan' }} --output-format=json > plan-dist-manifest.json
echo "dist ran successfully"
cat plan-dist-manifest.json
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
- name: "Upload dist-manifest.json"
Expand All @@ -99,12 +99,12 @@ jobs:
if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }}
strategy:
fail-fast: false
# Target platforms/runners are computed by cargo-dist in create-release.
# Target platforms/runners are computed by dist in create-release.
# Each member of the matrix has the following arguments:
#
# - runner: the github runner
# - dist-args: cli flags to pass to cargo dist
# - install-dist: expression to run to install cargo-dist on the runner
# - dist-args: cli flags to pass to dist
# - install-dist: expression to run to install dist on the runner
#
# Typically there will be:
# - 1 "global" task that builds universal installers
Expand All @@ -121,7 +121,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install cargo-dist
- name: Install dist
run: ${{ matrix.install_dist }}
# Get the dist-manifest
- name: Fetch local artifacts
Expand All @@ -136,8 +136,8 @@ jobs:
- name: Build artifacts
run: |
# Actually do builds and make zips and whatnot
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
echo "cargo dist ran successfully"
dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
echo "dist ran successfully"
- name: Attest
uses: actions/attest-build-provenance@v1
with:
Expand Down Expand Up @@ -176,12 +176,12 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install cached cargo-dist
- name: Install cached dist
uses: actions/download-artifact@v4
with:
name: cargo-dist-cache
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/cargo-dist
- run: chmod +x ~/.cargo/bin/dist
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
- name: Fetch local artifacts
uses: actions/download-artifact@v4
Expand All @@ -192,8 +192,8 @@ jobs:
- id: cargo-dist
shell: bash
run: |
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
echo "cargo dist ran successfully"
dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
echo "dist ran successfully"
# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -235,12 +235,12 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install cached cargo-dist
- name: Install cached dist
uses: actions/download-artifact@v4
with:
name: cargo-dist-cache
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/cargo-dist
- run: chmod +x ~/.cargo/bin/dist
# Fetch artifacts from scratch-storage
- name: Fetch artifacts
uses: actions/download-artifact@v4
Expand All @@ -253,7 +253,7 @@ jobs:
- id: host
shell: bash
run: |
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
echo "artifacts uploaded and released successfully"
cat dist-manifest.json
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -372,12 +372,12 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install cached cargo-dist
- name: Install cached dist
uses: actions/download-artifact@v4
with:
name: cargo-dist-cache
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/cargo-dist
- run: chmod +x ~/.cargo/bin/dist
- name: Fetch Axo Artifacts
uses: actions/download-artifact@v4
with:
Expand All @@ -386,7 +386,7 @@ jobs:
merge-multiple: true
- name: Announce Axo Releases
run: |
cargo dist host --steps=announce ${{ needs.plan.outputs.tag-flag }}
dist host --steps=announce ${{ needs.plan.outputs.tag-flag }}
# Create a GitHub Release while uploading all files to it
- name: "Download GitHub Artifacts"
uses: actions/download-artifact@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ on:
# Whenever something gets pushed to main, update the docs!
# This is great for getting docs changes live without cutting a full release.
#
# Note that if you're using cargo-dist, this will "race" the Release workflow
# Note that if you're using dist, this will "race" the Release workflow
# that actually builds the Github Release that oranda tries to read (and
# this will almost certainly complete first). As a result you will publish
# docs for the latest commit but the oranda landing page won't know about
# the latest release. The workflow_run trigger below will properly wait for
# cargo-dist, and so this half-published state will only last for ~10 minutes.
# dist, and so this half-published state will only last for ~10 minutes.
#
# If you only want docs to update with releases, disable this one.
push:
Expand All @@ -34,7 +34,7 @@ on:

# Whenever a workflow called "Release" completes, update the docs!
#
# If you're using cargo-dist, this is recommended, as it will ensure that
# If you're using dist, this is recommended, as it will ensure that
# oranda always sees the latest release right when it's available. Note
# however that Github's UI is wonky when you use workflow_run, and won't
# show this workflow as part of any commit. You have to go to the "actions"
Expand Down
13 changes: 10 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/axodotdev/cargo-dist"
homepage = "https://opensource.axo.dev/cargo-dist/"
version = "0.23.0"
version = "0.24.0-prerelease.2"

[workspace.dependencies]
# intra-workspace deps (you need to bump these versions when you cut releases too!
cargo-dist-schema = { version = "=0.23.0", path = "cargo-dist-schema" }
axoproject = { version = "=0.23.0", path = "axoproject", default-features = false, features = ["cargo-projects", "generic-projects", "npm-projects"] }
cargo-dist-schema = { version = "=0.24.0-prerelease.2", path = "cargo-dist-schema" }
axoproject = { version = "=0.24.0-prerelease.2", path = "axoproject", default-features = false, features = ["cargo-projects", "generic-projects", "npm-projects"] }

# first-party deps
axocli = { version = "0.2.0" }
Expand Down Expand Up @@ -66,6 +66,7 @@ serde_yml = "0.0.10"
spdx = "0.10.6"
base64 = "0.22.1"
lazy_static = "1.4.0"
current_platform = "0.2.0"

[workspace.metadata.release]
shared-version = true
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<div class="oranda-hide">

# `cargo-dist`
# `dist` (formerly known as `cargo-dist`)

</div>

[![crates.io](https://img.shields.io/crates/v/cargo-dist.svg)](https://crates.io/crates/cargo-dist)
[![docs](https://docs.rs/cargo-dist/badge.svg)](https://docs.rs/cargo-dist)
[![Rust CI](https://github.com/axodotdev/cargo-dist/workflows/Rust%20CI/badge.svg?branch=main)](https://github.com/axodotdev/cargo-dist/actions/workflows/ci.yml)

*cargo-dist distributes your binaries*
*dist distributes your binaries*

The TL;DR is that with cargo-dist set up, just doing this:
The TL;DR is that with dist set up, just doing this:

```sh
git commit -am "release: 0.2.0"
Expand All @@ -28,7 +28,7 @@ Or if you're using [oranda](https://opensource.axo.dev/oranda/), you'll get [thi

Cutting releases of your apps and distributing binaries for them has a lot of steps, and cargo-dist is quickly growing to try to cover them all!

To accomplish this, cargo-dist functionality can be broken up into two parts:
To accomplish this, dist functionality can be broken up into two parts:

* building (**planning** the release; **building** binaries and installers)
* distributing (**hosting** artifacts; **publishing** packages; **announcing** releases)
Expand All @@ -38,7 +38,7 @@ The build functionality can be used on its own if you just want some tarballs an

## Building

As a build tool, cargo-dist can do the following:
As a build tool, dist can do the following:

* Pick good build flags for "shippable binaries"
* Make [tarballs][] and [installers][] for the resulting binaries
Expand All @@ -49,7 +49,7 @@ That's a short list because "we make [installers][]" is doing a lot of heavy lif

## Distributing

As a distribution tool, cargo-dist gets to flex its biggest superpower: **it generates [its own CI scripts][ci-providers]**. For instance, enabling [GitHub CI][ci-providers] with `cargo dist init` will generate release.yml, which implements the full pipeline of plan, build, host, publish, announce:
As a distribution tool, dist gets to flex its biggest superpower: **it generates [its own CI scripts][ci-providers]**. For instance, enabling [GitHub CI][ci-providers] with `dist init` will generate release.yml, which implements the full pipeline of plan, build, host, publish, announce:

* Plan
* Waits for you to push a git tag for a new version (v1.0.0, my-app-v1.0.0, my-app/1.0.0, ...)
Expand All @@ -73,7 +73,7 @@ As a distribution tool, cargo-dist gets to flex its biggest superpower: **it gen

# Read The Book!

We've got all the docs you need over at the [cargo-dist book](https://axodotdev.github.io/cargo-dist/book/)!
We've got all the docs you need over at the [dist book](https://axodotdev.github.io/cargo-dist/book/)!

* [Introduction](https://opensource.axo.dev/cargo-dist/book/introduction.html)
* [Install](https://opensource.axo.dev/cargo-dist/book/install.html)
Expand All @@ -87,7 +87,7 @@ We've got all the docs you need over at the [cargo-dist book](https://axodotdev.

## Updating Snapshots

cargo-dist's tests rely on [cargo-insta](https://crates.io/crates/cargo-insta) for snapshot testing various
dist's tests rely on [cargo-insta](https://crates.io/crates/cargo-insta) for snapshot testing various
outputs. This allows us to both catch regressions and also more easily review UI/output changes. If a snapshot
test fails, you will need to use the `cargo insta` CLI tool to update them:

Expand All @@ -109,23 +109,23 @@ If you know you like the changes, just use `cargo insta accept` to auto-apply al
## Cutting Releases

cargo-dist is self-hosting, so you just need to push a git-tag with the right format to "do" a release. Of course there's lots of other tedious tasks that come with updating a release, and we use cargo-release to handle all those mechanical details of updating versions/headings/tags. See [these sections of the docs for the release workflow we use](https://opensource.axo.dev/cargo-dist/book/workspaces/cargo-release-guide.html#using-cargo-release-with-pull-requests).
dist is self-hosting, so you just need to push a git-tag with the right format to "do" a release. Of course there's lots of other tedious tasks that come with updating a release, and we use cargo-release to handle all those mechanical details of updating versions/headings/tags. See [these sections of the docs for the release workflow we use](https://opensource.axo.dev/cargo-dist/book/workspaces/cargo-release-guide.html#using-cargo-release-with-pull-requests).

TL;DR:

* Update CHANGELOG.md's "Unreleased" section to include all the release notes you want
* run cargo-release as described in the docs
* ..you're done!

Note that we've wired up cargo-dist and cargo-release to understand the "Unreleased" heading so you
Note that we've wired up dist and cargo-release to understand the "Unreleased" heading so you
should never edit that name, the tools will update it as needed.

If that releases succeeds, we recommend updating the bootstrap version of cargo-dist as a follow up:
If that releases succeeds, we recommend updating the bootstrap version of dist as a follow up:

* install the version of cargo-dist you just released on your system
* run `cargo dist init --yes`
* install the version of dist you just released on your system
* run `dist init --yes`
* commit "chore: update bootstrap dist to ..."

Note that as a consequence of the way we self-host, cargo-dist's published artifacts will always be built/generated by a previous version of itself. This can be problematic if you make breaking changes to cargo-dist-schema's format... so don't! Many things in the schema are intentionally optional to enable forward and backward compatibility, so this should hopefully work well!
Note that as a consequence of the way we self-host, dist's published artifacts will always be built/generated by a previous version of itself. This can be problematic if you make breaking changes to cargo-dist-schema's format... so don't! Many things in the schema are intentionally optional to enable forward and backward compatibility, so this should hopefully work well!

</div>
2 changes: 1 addition & 1 deletion axoproject/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Rust CI](https://github.com/axodotdev/axoproject/workflows/Rust%20CI/badge.svg?branch=main)](https://github.com/axodotdev/axoproject/actions/workflows/ci.yml)

A tool that handles the details of detecting a cargo/npm workspace/project at a given directory,
and making sense of the structure. This should be used by cargo-dist and oranda to share that logic.
and making sense of the structure. This should be used by dist and oranda to share that logic.

## License

Expand Down
5 changes: 5 additions & 0 deletions axoproject/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ pub enum AxoprojectError {
/// Version we were looking for
version: Version,
},

/// We couldn't parse a workspace because there's no Cargo
#[error("Your app has a Cargo.toml, but you don't appear to have cargo installed.")]
#[diagnostic(help("Is cargo in your PATH? You can install cargo via: https://rustup.rs"))]
CargoMissing {},
}

/// Errors related to finding the project
Expand Down
Loading

0 comments on commit 94dd0b6

Please sign in to comment.