Skip to content

Commit

Permalink
new github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Nov 7, 2023
1 parent 7c65433 commit 8658ca3
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 49 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Audit

on:
push:
paths:
- '**/Cargo.toml'
- '**/Cargo.lock'

jobs:
security_audit:
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v4
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
71 changes: 30 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,89 +1,78 @@
name: ci
name: CI

on: [push]
on:
push:
branches:
- main
pull_request:
workflow_dispatch:

permissions:
contents: read

env:
RUSTFLAGS: -Dwarnings

jobs:
cargo-tests:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- name: cargo test
run: cargo test --all
- name: cargo test all features
run: cargo test --all --all-features
- run: cargo test --all
- run: cargo test --all --all-features

cargo-lint:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
components: rustfmt, clippy
override: true
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- name: cargo fmt
run: cargo +nightly fmt --all -- --check
- name: cargo clippy
run: cargo +nightly clippy --all --all-features -- -D warnings
- run: cargo +nightly fmt --all -- --check
- run: cargo +nightly clippy --all --all-features -- -D warnings

cargo-build:
runs-on: ubuntu-latest
timeout-minutes: 20
continue-on-error: true
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- name: build
id: build
continue-on-error: true
- continue-on-error: true
run: cargo build --all
id: build

cargo-doc:
runs-on: ubuntu-latest
timeout-minutes: 20
continue-on-error: true
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- name: doclint
id: build
- name: doclints
continue-on-error: true
run: RUSTDOCFLAGS="-D warnings" cargo doc --all --no-deps --all-features --document-private-items
- name: doctest
run: cargo test --doc --all --all-features
id: build
- run: cargo test --doc --all --all-features
88 changes: 88 additions & 0 deletions .github/workflows/cross-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Cross Release

on:
workflow_dispatch:

jobs:
extract-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Export Crate Package Version
run: echo "VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version')" >> $GITHUB_OUTPUT
id: export
outputs:
VERSION: ${{ steps.export.outputs.VERSION }}

build:
name: build release
strategy:
matrix:
arch:
[
aarch64-unknown-linux-gnu,
x86_64-unknown-linux-gnu,
x86_64-apple-darwin,
aarch64-apple-darwin,
x86_64-pc-windows-gnu,
]
include:
- arch: aarch64-unknown-linux-gnu
platform: ubuntu-20.04
profile: maxperf
- arch: x86_64-unknown-linux-gnu
platform: ubuntu-20.04
profile: maxperf
- arch: x86_64-apple-darwin
platform: macos-latest
profile: maxperf
- arch: aarch64-apple-darwin
platform: macos-latest
profile: maxperf
- arch: x86_64-pc-windows-gnu
platform: ubuntu-20.04
profile: maxperf

runs-on: ${{ matrix.platform }}
needs: extract-version
env:
VERSION: ${{ needs.extract-version.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
- run: rustup update stable
- run: rustup target add ${{ matrix.arch }}
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Apple M1 setup
if: ${{ matrix.job.target == 'aarch64-apple-darwin' }}
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Build for ${{ matrix.arch }}
run: |
cargo install cross
env PROFILE=${{ matrix.profile }} make build-${{ matrix.arch }}
- name: Move cross-compiled binary
if: matrix.arch != 'x86_64-pc-windows-gnu'
run: |
mkdir artifacts
mv target/${{ matrix.arch }}/${{ matrix.profile }}/* ./artifacts
- name: Create artifacts
run: tar --directory=artifacts -czf release-${{ env.VERSION }}-${{ matrix.arch }}.tar.gz $(ls -U artifacts/ | head -1)
shell: bash

release:
name: Release on Github
runs-on: ubuntu-latest
permissions:
contents: write
needs: [build, extract-version]
env:
VERSION: ${{ needs.extract-version.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
- uses: ncipollo/release-action@v1
with:
artifacts: "artifacts/*"
tag: v${{ env.VERSION }}
38 changes: 38 additions & 0 deletions .github/workflows/github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Github Release

on:
workflow_dispatch:
workflow_run:
workflows: ["CI"]
branches: [main]
types:
- completed

jobs:
extract-crate-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Export Crate Package Version
run: echo "VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version')" >> $GITHUB_OUTPUT
id: export_crate_version
outputs:
VERSION: ${{ steps.export_crate_version.outputs.VERSION }}

release:
name: Release on Github
runs-on: ubuntu-latest
permissions:
contents: write
needs: [extract-crate-version]
env:
VERSION: ${{ needs.extract-crate-version.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
- run: cargo build --release
- name: Generate the Release Tarball
run: tar --directory=target/release -cf release.tar.gz $(ls -U target/release/ | head -1)
- uses: ncipollo/release-action@v1
with:
artifacts: "release.tar.gz"
tag: v${{ env.VERSION }}
21 changes: 21 additions & 0 deletions .github/workflows/manual-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Manual Tag

on:
workflow_dispatch:
inputs:
version:
description: "The version to release. Should match the version in `Cargo.toml`. For example, 0.1.20"
required: true

jobs:
tag:
runs-on: ubuntu-latest
permissions:
contents: write
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: anothrNick/github-tag-action@master
env:
CUSTOM_TAG: v${{ inputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release

on:
workflow_dispatch:
workflow_run:
workflows: ["CI"]
branches: [main]
types:
- completed

jobs:
publish:
name: Publish Crate to Crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: baptiste0928/cargo-install@v2
with:
crate: cargo-release
- run: CARGO_REGISTRY_TOKEN=${CRATES_TOKEN} cargo release --execute --no-confirm --no-push --no-tag
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
35 changes: 35 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Tag

on:
workflow_run:
workflows: ["CI"]
branches: [main]
types:
- completed

jobs:
extract-crate-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Export Crate Package Version
run: echo "VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version')" >> $GITHUB_OUTPUT
id: export_crate_version
outputs:
VERSION: ${{ steps.export_crate_version.outputs.VERSION }}

tag:
runs-on: ubuntu-latest
permissions:
contents: write
timeout-minutes: 20
needs: [extract-crate-version]
env:
VERSION: ${{ needs.extract-crate-version.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
- name: Bump version and push tag
uses: anothrNick/github-tag-action@master
env:
CUSTOM_TAG: v${{ env.VERSION }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43 changes: 43 additions & 0 deletions .github/workflows/validate-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Validate Release Version

on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
extract-github-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-ecosystem/action-get-latest-tag@v1
id: get-latest-tag
- name: Extract the git tag version
run: echo "VERSION=$(echo ${{ steps.get-latest-tag.outputs.tag }} | sed 's/^.*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\).*$/\1/')" >> $GITHUB_OUTPUT
id: export-git-tag
outputs:
VERSION: ${{ steps.export-git-tag.outputs.VERSION }}

extract-crate-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Export Crate Package Version
run: echo "VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version')" >> $GITHUB_OUTPUT
id: export_crate_version
outputs:
VERSION: ${{ steps.export_crate_version.outputs.VERSION }}

validate-crate-version:
runs-on: ubuntu-latest
needs: [extract-github-tag, extract-crate-version]
env:
GIT_TAG: ${{ needs.extract-github-tag.outputs.VERSION }}
CRATE_VERSION: ${{ needs.extract-crate-version.outputs.VERSION }}
steps:
- uses: baptiste0928/cargo-install@v2
with:
crate: semver-util
- name: Validate Semvers
run: semver cmp ${{ env.CRATE_VERSION }} gt ${{ env.GIT_TAG }} || exit 1
Loading

0 comments on commit 8658ca3

Please sign in to comment.