Skip to content

CI

CI #50

Workflow file for this run

name: CI
on:
push:
branches: ["main"]
paths:
- "src/**"
- "Cargo.*"
pull_request:
branches: ["main"]
paths:
- "src/**"
- "Cargo.*"
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
tests:
name: Run tests
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cargo cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Setup tools
run: rustup default stable
- name: Run tests
run: cargo test --verbose
next-version:
name: Detect next version
runs-on: ubuntu-22.04
outputs:
previous-tag: ${{ fromJSON(steps.next-version.outputs.output).previous-tag }}
tag: ${{ fromJSON(steps.next-version.outputs.output).tag }}
version: ${{ fromJSON(steps.next-version.outputs.output).version }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: "0"
- name: Find next version
id: next-version
uses: ancosma/nexver@HEAD
with:
head-ref: ${{ github.event.pull_request.head.sha || 'HEAD' }}
patch-types: fix,chore(deps),chore
input-template: v{version}
output-template: '{"previous-tag": "{previous-tag}", "tag": "{tag}", "version": "{version}"}'
- name: Next version
run: |
printf '%s\n' ${{ steps.next-version.outputs.output }}
patch-version:
name: Patch version ${{ needs.next-version.outputs.tag }}
if: github.event.ref == 'refs/heads/main' && needs.next-version.outputs.tag != needs.next-version.outputs.previous-tag
needs: [next-version, tests]
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install cargo-edit
run: |
cargo install cargo-edit
- name: Patch version
env:
VERSION: ${{ needs.next-version.outputs.version }}
run: |
cargo set-version "${VERSION}"
cargo update
sed -i -- 's|NEXVER_VERSION:.*$|NEXVER_VERSION: "'${VERSION}'"|g' action.yaml
git config --global user.email "[email protected]"
git config --global user.name "CI"
git pull
git add Cargo.toml Cargo.lock action.yaml && git commit -m "ci: Patch version" || true
git push origin main
build-and-publish:
name: Build and publish
if: github.event.ref == 'refs/heads/main'
needs: [next-version, patch-version]
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
tag: ["${{ needs.next-version.outputs.tag }}"]
target:
[
x86_64-unknown-linux-gnu,
aarch64-unknown-linux-gnu,
x86_64-pc-windows-gnu,
]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- name: Update repo
run: git pull
- name: Cargo cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Setup tools
id: setup
run: |
./scripts/ghr-install
./scripts/cross-install
echo "cross_version=$(cross-util --version | cut -d' ' -f2 -)" >> $GITHUB_OUTPUT
- name: Cross cache
uses: actions/cache@v3
id: cross-cache
with:
path: ~/.local/share/cross/exports/${{ matrix.target }}-${{ steps.setup.outputs.cross_version }}
key: ${{ runner.os }}-cross-${{ matrix.target }}-${{ steps.setup.outputs.cross_version }}
- name: Restore ${{ matrix.target }} cross image
run: ./scripts/cross-import-image ${{ matrix.target }}
- name: Build ${{ matrix.tag }} (${{ matrix.target }}) & upload artifact
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
./scripts/build-release-artifact "${{ matrix.target }}"
artifact="$(ls target/${{ matrix.target }}/*{zip,tar.gz} 2>/dev/null | tr -d '\n')"
ghr "${{ matrix.tag }}" "${artifact}"
checksum="$(shasum -a 256 ${artifact} | cut -d' ' -f1 - | tr -d '\n')"
echo "checksum=${checksum}" >> $GITHUB_OUTPUT
echo "archive=$(basename ${artifact})" >> $GITHUB_OUTPUT
- name: Export ${{ matrix.target }} cross image
run: ./scripts/cross-export-image "${{ matrix.target }}"