Skip to content

Commit

Permalink
chore: add github actions (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
giangndm authored Dec 20, 2024
1 parent 0e93dcd commit 61c5396
Show file tree
Hide file tree
Showing 12 changed files with 523 additions and 22 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# rust-clippy is a tool that runs a bunch of lints to catch common
# mistakes in your Rust code and help improve your Rust code.
# More details at https://github.com/rust-lang/rust-clippy
# and https://rust-lang.github.io/rust-clippy/

name: rust-clippy analyze

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

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
rust-clippy-analyze:
name: Run rust-clippy analyzing
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/cache@v3
id: cache-cargo
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-

- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
version: "25.1"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Run rust-clippy
run: cargo clippy --all-targets --all-features -- -D warnings

- name: Install required cargo
run: cargo install clippy-sarif sarif-fmt

- name: Run rust-sarif
run: cargo clippy --all-features --message-format=json |
clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: rust-clippy-results.sarif
wait-for-processing: true
27 changes: 27 additions & 0 deletions .github/workflows/release-plz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release-plz

permissions:
pull-requests: write
contents: write

on:
push:
branches:
- master

jobs:
release-plz:
name: Release-plz
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
189 changes: 189 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
name: Release
on:
push:
branches: [master]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
APP_NAME: atm0s-mqtt
ARTIFACT_DIR: release-builds
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-release:
name: build-release
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: 1

strategy:
matrix:
build:
- linux gnu x64
# - linux musl x64
- linux gnu aarch64
# - linux musl aarch64
# - linux gnueabihf arm
# - linux gnueabihf armv7
# - linux gnu mips
# - linux gnuabi64 mips64
# - linux gnuabi64 mips64el
# - linux gnu mipsel
- macos x64
- macos aarch64
# - windows gnu x64
# - windows msvc x64
include:
- build: linux gnu x64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
extension: ""
# - build: linux musl x64
# os: ubuntu-latest
# target: x86_64-unknown-linux-musl
# extension: ""
- build: linux gnu aarch64
os: ubuntu-latest
target: aarch64-unknown-linux-gnu
extension: ""
# - build: linux musl aarch64
# os: ubuntu-latest
# target: aarch64-unknown-linux-musl
# extension: ""
# - build: linux gnueabihf arm
# os: ubuntu-latest
# target: arm-unknown-linux-gnueabihf
# extension: ""
# - build: linux gnueabihf armv7
# os: ubuntu-latest
# target: armv7-unknown-linux-gnueabihf
# extension: ""
# - build: linux gnu mips
# os: ubuntu-latest
# rust: 1.71.1
# target: mips-unknown-linux-gnu
# extension: ""
# - build: linux gnuabi64 mips64
# os: ubuntu-latest
# rust: 1.71.1
# target: mips64-unknown-linux-gnuabi64
# extension: ""
# - build: linux gnuabi64 mips64el
# os: ubuntu-latest
# rust: 1.71.1
# target: mips64el-unknown-linux-gnuabi64
# extension: ""
# - build: linux gnu mipsel
# os: ubuntu-latest
# rust: 1.71.1
# target: mipsel-unknown-linux-gnu
# extension: ""
# - build: linux musl aarch64
# os: ubuntu-latest
# target: aarch64-unknown-linux-musl
# extension: ""
- build: macos x64
os: macos-latest
target: x86_64-apple-darwin
extension: ""
- build: macos aarch64
os: macos-latest
target: aarch64-apple-darwin
extension: ""
# - build: windows gnu x64
# os: ubuntu-latest
# target: x86_64-pc-windows-gnu
# extension: ".exe"
# - build: windows msvc x64
# os: windows-latest
# target: x86_64-pc-windows-msvc
# extension: ".exe"
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build binary
uses: houseabsolute/actions-rust-cross@v0
with:
target: ${{ matrix.target }}
args: "--locked --release"
strip: true

- name: Upload Artifact to Summary
if: ${{ matrix.build != 'windows gnu x64' && matrix.build != 'windows msvc x64' }}
uses: actions/upload-artifact@v4
with:
name: ${{ env.APP_NAME }}-${{ matrix.target }}${{ matrix.extension }}
path: |
target/${{ matrix.target }}/release/${{ env.APP_NAME }}${{ matrix.extension }}
- name: Upload server binarie to release
if: startsWith(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/${{ matrix.target }}/release/${{ env.APP_NAME }}${{ matrix.extension }}
asset_name: ${{ env.APP_NAME }}-${{ matrix.target }}${{ matrix.extension }}
tag: ${{ github.ref }}
overwrite: true

create-release:
# only run if not a tags build
if: startsWith(github.ref, 'refs/tags/') == false
needs: build-release
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
- name: create_release
id: create_release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: ${{ github.event_name == 'workflow_dispatch' && 'latest' || (github.ref == 'refs/heads/master' && 'latest') || github.ref }}
title: Build ${{ github.event_name == 'workflow_dispatch' && 'development' || github.ref }}
files: |
*/*
prerelease: true

deploy-docker:
needs: build-release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: actions/download-artifact@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
36 changes: 36 additions & 0 deletions .github/workflows/rust-fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: rust-fmt analyze

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

concurrency:
# One build per PR, branch or tag
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
rust-fmt-analyze:
name: Run rust-fmt analyzing
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- 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: cargo fmt
run: cargo fmt --all -- --check
Loading

0 comments on commit 61c5396

Please sign in to comment.