Skip to content

Commit

Permalink
Improve github action workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul1365972 authored and StackDoubleFlow committed Jan 15, 2025
1 parent e1705bf commit 2545b25
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 73 deletions.
4 changes: 4 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
exclude:
authors:
- dependabot
86 changes: 63 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ name: Build

on:
push:
branches: [master]
branches: [ "master" ]
tags: [ "v*" ]
pull_request:
branches: [ "master" ]

jobs:
build:
Expand All @@ -27,27 +30,26 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
profile: minimal
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- uses: actions/checkout@v4

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}

- name: Upload
uses: actions/upload-artifact@v4
with:
name: mchprs-${{ matrix.target }}
path: target/${{ matrix.target }}/release/mchprs${{ matrix.ext }}
- name: Build
env:
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER: rust-lld.exe
run: cargo build --release --target ${{ matrix.target }}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: mchprs-${{ matrix.target }}
path: target/${{ matrix.target }}/release/mchprs${{ matrix.ext }}

build-macos-universal:
needs: build
Expand All @@ -62,11 +64,49 @@ jobs:
name: mchprs-aarch64-apple-darwin
path: aarch64

- name: Build
- name: Create universal binary
run: lipo -create -output mchprs x86_64/mchprs aarch64/mchprs

- name: Upload
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: mchprs-universal-apple-darwin
path: mchprs
path: mchprs

publish:
needs: [build, build-macos-universal]
runs-on: ubuntu-latest
permissions:
contents: write
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Reorganize artifacts
run: |
mkdir -p dist/
find artifacts/ -type f -exec bash -c 'base=$(basename $1); mv $1 dist/$(basename $(dirname $1))${base#${base%.*}}' _ {} \;
- name: Create preview release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh release delete preview --yes || true
gh release create preview \
--prerelease \
--title "${GITHUB_REPOSITORY} Preview Build" \
--notes "🚧 **This is a preview build of the latest commit.**" \
dist/*
- name: Create release
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ github.token }}
tag: ${{ github.ref_name }}
run: |
gh release create "$tag" \
--title "${GITHUB_REPOSITORY} ${tag#v}" \
--generate-notes \
dist/*
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
CARGO_TERM_COLOR: always

jobs:
format:
name: Check formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: Check formatting
run: cargo fmt --check --all

clippy:
name: Clippy lints
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- name: Rust cache
uses: Swatinem/rust-cache@v2

- name: Run clippy
# If we ever get around to fix everything clippy complains about we can start failing on warning via: -- -D warnings
run: cargo clippy --all-features --all-targets

test:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Rust cache
uses: Swatinem/rust-cache@v2

- name: Run tests
run: cargo test --all-features --all-targets
55 changes: 38 additions & 17 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,51 @@ name: Docker

on:
push:
branches: [ master ]

branches: [ "master" ]
tags: [ "v*" ]

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

permissions:
contents: read
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Login to Docker Hub
uses: docker/login-action@v1
- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_HUB_USERNAME }}/mchprs
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=short
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build and push latest
uses: docker/build-push-action@v2

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/mchprs:latest
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha
33 changes: 0 additions & 33 deletions .github/workflows/test.yml

This file was deleted.

0 comments on commit 2545b25

Please sign in to comment.