Skip to content

Workflow file for this run

name: Build, Test, and Publish Docker Action
on:
push:
branches:
- main
tags:
- "v*"
pull_request:
permissions:
contents: read
packages: write
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v3
# Set up Rust
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
# Cache Cargo dependencies
- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-index-
- name: Cache target directory
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-target-
# Install Rust dependencies
- name: Install dependencies
run: cargo fetch
- name: Rustfmt Check
run: |
rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt
cargo fmt --all -- --check
# Build the project
- name: Build
run: cargo build --release
# Run tests
- name: Run tests
run: cargo test --verbose
build-and-publish:
name: Build and Publish Docker Image
needs: build-and-test
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v3
# Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build Docker image
- name: Build Docker image
run: docker build -t ghcr.io/${{ github.repository }}/action:latest .
# Push Docker image to GitHub Container Registry
- name: Push Docker image
run: |
docker push ghcr.io/${{ github.repository }}/action:latest
# docker push ghcr.io/${{ github.repository }}/action:$TAG