book icon indicating copy to clipboard operation
book copied to clipboard

Suggestion: add GitHub Actions example

Open trevordmiller opened this issue 5 years ago • 5 comments

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.

trevordmiller avatar Dec 04 '19 17:12 trevordmiller

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.

trevordmiller avatar Dec 04 '19 17:12 trevordmiller

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

trevordmiller avatar Dec 04 '19 18:12 trevordmiller

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!

deg4uss3r avatar Dec 05 '19 14:12 deg4uss3r

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.

epage avatar Dec 05 '19 14:12 epage

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

trevordmiller avatar Feb 06 '20 18:02 trevordmiller

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

jpmckinney avatar Nov 26 '22 01:11 jpmckinney