book
book copied to clipboard
Suggestion: add GitHub Actions example
It would be helpful to have a GitHub Actions example to go along with the Travis CI / Trust items in https://rust-lang-nursery.github.io/cli-wg/tutorial/packaging.html.
I'd be willing to submit a pull request for this, but as a new Rust developer, I've been trying to find this information myself and am not sure how to do it.
It seems to me that CI could do something like:
cargo check
cargo test
cargo clippy
cargo fmt
cargo audit
And CD something like:
cargo doc
cargo build --release
# how to share executables to GitHub releases / packages?
But perhaps this would be better to put in the cargo book, not specific to Command Line apps? https://github.com/rust-lang/cargo/issues/7664
I think this is more for a "Rust CI book" rather than the CLI WG. Since if we did an example for GitHub Actions we would probably need to have one for Jenkins, Travis, Appveyor, and so on.
I do like the idea of a Rust CI book though, that would be really helpful!
My recommendation has been that solving these types of problems are best handled in a dedicated resource, like crate-ci. I've not had much time for updating it lately. Though the crate-ci book doesn't reference Azure Pipelines, we have a separate page for azure pipelines and azure pipeline templates. I do need to link out to uploading tarballs to Github Releases.
i see it natural to also consolidate Github Action templates and documentation over there as well.
Here is what I ended up with, in case it is helpful:
Run CI when pushing to branches for pull requeests
name: Pull request
on:
push:
branches-ignore:
- master
jobs:
verify:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Check
run: cargo check
- name: Test
run: cargo test
- name: Lint
run: cargo clippy --all-targets -- -D warnings
- name: Format
run: cargo fmt -- --check
- name: Publish
run: cargo publish --dry-run
Run CI and CD when merging pull requests to master
name: Merge
on:
push:
branches:
- master
jobs:
verify:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Check
run: cargo check
- name: Test
run: cargo test
- name: Lint
run: cargo clippy --all-targets -- -D warnings
- name: Format
run: cargo fmt -- --check
executable:
runs-on: ubuntu-latest
needs: [verify]
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Login
run: cargo login ${{ secrets.CRATE_REGISTRY_PAT }}
- name: Publish
if: success()
run: cargo publish
The documentation already has links to projects that contain GitHub Actions examples, but they are all deprecated or abandoned.
- trust is abandoned and doesn't work on GitHub Actions.
- wasm-pack (there are links to its Travis and Appveyor files, but it also uses GitHub Actions now) uses set-output, which is deprecated, uses actions-rs/toolchain, which is unmaintained (use dtolnay/rust-toolchain instead), and uses actions/create-release and actions/upload-release-asset, which are archived and use set-output.
- ripgrep (uses GitHub Actions now) uses an old, strange GITHUB_REF workaround (use github.ref_name or GITHUB_REF_NAME), and uses actions/create-release and actions/upload-release-asset (see above).
The best way to do things now on GitHub Actions is very simple:
- Use
${{ github.ref_name }}(or$GITHUB_REF_NAME) - Use cross
- Use the GitHub CLI in GitHub Actions workflows
Example: https://github.com/open-contracting/cardinal-rs/blob/main/.github/workflows/release.yml