Skip to content

CI

CI #328

Workflow file for this run

name: CI
on:
push:
tags: ["v*"]
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: write
packages: write
jobs:
style:
name: Style
runs-on: ubuntu-latest
environment: Linux
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Style check
run: cargo fmt --all -- --check
- name: Clippy check
run: cargo clippy --all-targets
build:
name: Build
runs-on: ubuntu-latest
environment: Linux
if: startsWith(github.ref, 'refs/tags/')
container:
image: ghcr.io/rust-cross/cargo-zigbuild:latest
steps:
- uses: actions/checkout@v3
- name: Get tag
if: startsWith(github.ref, 'refs/tags/')
id: tag
uses: dawidd6/action-get-tag@v1
with:
strip_v: true
- name: Tag Check
run: |
echo "tag=${{ steps.tag.outputs.tag }}" >> $GITHUB_ENV
echo "tag=${{ steps.tag.outputs.tag }}" >> $GITHUB_OUTPUT
if [ -z "${{ steps.tag.outputs.tag }}" ]; then
echo "tag=latest" >> $GITHUB_OUTPUT
echo "tag=latest" >> $GITHUB_ENV
fi
- name: Install upx
run: |
wget https://github.com/upx/upx/releases/download/v4.2.1/upx-4.2.1-amd64_linux.tar.xz
tar -xvf upx-4.2.1-amd64_linux.tar.xz
mv upx-4.2.1-amd64_linux/upx /usr/bin/upx
rm -rf upx-4.2.1-amd64_linux.tar.xz upx-4.2.1-amd64_linux
- name: Install dependencies
run: |
apt-get update && apt-get install -y mingw-w64 sudo
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Build Windows Target
shell: bash
run: |
os=windows ./.github/build.sh
- name: Build macOS Target
run: |
os=macos ./.github/build.sh
- name: Build Linux Target
run: |
os=linux ./.github/build.sh
- name: Upload binaries to GitHub Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: |
bin/*
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
generate_release_notes: true
crates:
name: Publish crates
runs-on: ubuntu-latest
environment: Linux
needs: ["build", "style"]
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- name: Get tag
if: startsWith(github.ref, 'refs/tags/')
id: tag
uses: dawidd6/action-get-tag@v1
with:
strip_v: true
- name: Tag Check
run: |
echo "tag=${{ steps.tag.outputs.tag }}" >> $GITHUB_ENV
echo "tag=${{ steps.tag.outputs.tag }}" >> $GITHUB_OUTPUT
if [ -z "${{ steps.tag.outputs.tag }}" ]; then
echo "tag=latest" >> $GITHUB_OUTPUT
echo "tag=latest" >> $GITHUB_ENV
fi
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: katyo/publish-crates@v2
if: startsWith(github.ref, 'refs/tags/')
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
ignore-unpublished-changes: true
docker:
name: Build and push Docker image
runs-on: ubuntu-latest
needs: ["build", "crates"]
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
if: startsWith(github.ref, 'refs/tags/')
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
if: startsWith(github.ref, 'refs/tags/')
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}