Skip to content

Commit

Permalink
ci: add workflows to test, build containers and binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Dec 12, 2023
1 parent f4076c0 commit 47f87cb
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 1 deletion.
63 changes: 63 additions & 0 deletions .github/workflows/containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build and upload Docker image

on:
push:
tags:
- "*.*.*"
branches:
- main
pull_request:
branches:
- main
- dev

env:
REGISTRY: ghcr.io/${{ github.repository_owner }}

jobs:
builds-linux:
runs-on: ubuntu-latest

strategy:
matrix:
target: [subfile-exchange]

permissions:
packages: write

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
${{ env.REGISTRY }}/${{matrix.target}}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
type=semver,pattern={{major}}
type=sha
- name: Log in to the Container registry
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./
push: true
tags: ${{ steps.meta.outputs.tags }}
file: Dockerfile.${{ matrix.target }}
48 changes: 48 additions & 0 deletions .github/workflows/gen-binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and upload release binaries

on:
release:
types: [published]

jobs:
build-linux:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Build release binary
run: |
cargo build --release
- name: Upload Ubuntu binary
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./target/release/subfile-exchange
asset_name: subfile-exchange-${{ github.event.release.tag_name }}-ubuntu
asset_content_type: binary/octet-stream
build-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Build release binary
run: |
cargo build --release
- name: Upload MacOS binary
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./target/release/subfile-exchange
asset_name: subfile-exchange-${{ github.event.release.tag_name }}-macos
asset_content_type: binary/octet-stream
2 changes: 1 addition & 1 deletion .github/release.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ changelog:
- title: Refactor 🌱
labels:
- refactor
- title: Other Changes
- title: Other Changes 🗳️
labels:
- "*"
71 changes: 71 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: tests

on:
push:
branches: [ main, dev ]
pull_request:
workflow_dispatch:

jobs:
fmt:
name: cargo fmt
runs-on: ubuntu-latest
container:
image: rust:1.74-bookworm
steps:
- uses: actions/checkout@v3
- run: |
rustup component add rustfmt
cargo fmt --all -- --check
clippy:
name: cargo clippy
runs-on: ubuntu-latest
container:
image: rust:1.74-bookworm
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
- run: |
rustup component add clippy
# Temporarily allowing dead-code, while denying all other warnings
cargo clippy --all-features --all-targets -- -A dead-code -D warnings
test-and-coverage:
name: cargo test and coverage
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
actions: read
container:
image: rust:1.74-bookworm
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Run tests and generate coverage report
run: cargo llvm-cov test --all-features --workspace --lcov --output-path lcov.info
- name: Test documentation code snippets
run: cargo test --doc --all-features --workspace
- name: Upload coverage to Coveralls
uses: coverallsapp/[email protected]
with:
file: ./lcov.info

0 comments on commit 47f87cb

Please sign in to comment.