Skip to content

Commit

Permalink
add PR and publishing CI config
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Dec 13, 2024
1 parent cb8a685 commit 4826f67
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
on:
push:
branches: [ main ]
pull_request:
branches:
- main

name: CI

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v2
with:
# By default actions/checkout checks out a merge commit. Check out the PR head instead.
# https://github.com/actions/checkout#checkout-pull-request-head-commit-instead-of-merge-commit
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
- uses: Swatinem/rust-cache@c5ed9ba6b7e1bb8aff90d43acd2f0af4990fa57c
- name: Lint (clippy)
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features --all-targets
- name: Lint (rustfmt)
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check

build:
name: Build and test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
rust-version: [ stable ]
fail-fast: false
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust-version }}
override: true
- name: Build all targets with all features
uses: actions-rs/cargo@v1
with:
command: build
args: --all-targets --all-features
- name: Install latest nextest release
uses: taiki-e/install-action@nextest
- name: Test with latest nextest release
uses: actions-rs/cargo@v1
with:
command: nextest
args: run --all-features --profile ci
81 changes: 81 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: publish
on:
push:
tags:
- "v*"
env:
jobs:
build_and_test_linux:
name: Build and Test (Linux)
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable

- uses: taiki-e/install-action@nextest
- name: 'Build and test'
run: cargo nextest run --workspace --all-features

publish_gh_release:
name: Publish GH release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
release_version: ${{ env.RELEASE_VERSION }}
steps:
- name: Get the release version from the tag
shell: bash
if: env.RELEASE_VERSION == ''
run: |
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "version is: ${{ env.RELEASE_VERSION }}"
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Create GitHub release
id: release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_VERSION }}
release_name: ${{ env.RELEASE_VERSION }}

crates_io_publish:
name: Publish (crates.io)
needs:
- build_and_test_linux

runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable

- name: cargo-release Cache
id: cargo_release_cache
uses: actions/cache@v4
with:
path: ~/.cargo/bin/cargo-release
key: ${{ runner.os }}-cargo-release

- run: cargo install cargo-release
if: steps.cargo_release_cache.outputs.cache-hit != 'true'

- name: cargo login
run: cargo login ${{ secrets.CRATES_IO_API_TOKEN }}

# allow-branch HEAD is because GitHub actions switches
# to the tag while building, which is a detached head
- name: "cargo release publish"
run: |-
cargo release \
publish \
--workspace \
--all-features \
--allow-branch HEAD \
--no-confirm \
--execute

0 comments on commit 4826f67

Please sign in to comment.