Files
2026-07-17 13:01:57 +08:00

175 lines
5.1 KiB
YAML

name: Release RustMailer
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
env:
BINARY_NAME: rustmailer
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
# - target: x86_64-pc-windows-msvc
# os: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
override: true
- name: Install protoc on Linux
if: runner.os == 'Linux'
run: |
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v31.1/protoc-31.1-linux-x86_64.zip
unzip protoc-31.1-linux-x86_64.zip -d protoc
echo "${PWD}/protoc/bin" >> $GITHUB_PATH
cp -r protoc/include/* protos/
- name: Install protoc on macOS
if: runner.os == 'macOS'
run: |
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v31.1/protoc-31.1-osx-x86_64.zip
unzip protoc-31.1-osx-x86_64.zip -d protoc
echo "${PWD}/protoc/bin" >> $GITHUB_PATH
cp -r protoc/include/* protos/
- name: Setup Node.js & pnpm
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install pnpm
run: npm install -g pnpm
- name: Build frontend (web)
working-directory: ./web
run: |
pnpm install
pnpm run build
- name: Install musl-tools (Linux musl only)
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Build Rust backend
run: cargo build --release --features vendored-openssl --target=${{ matrix.target }}
- name: Strip binary (Linux and macOS)
if: matrix.os != 'windows-latest'
run: |
strip target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}
- name: Pack artifact (Linux/macOS)
if: matrix.os != 'windows-latest'
shell: bash
run: |
mkdir -p release
BINARY="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}"
cp README.md LICENSE license.html release/
cp "$BINARY" release/
tar -czvf "${{ env.BINARY_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz" -C release .
mv "${{ env.BINARY_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz" release/
- name: Upload build artifact
if: matrix.os != 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: release/${{ env.BINARY_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: "*"
merge-multiple: true
- name: Flatten artifacts
run: |
mkdir -p artifacts
find artifacts -type f -name "*.zip" -exec mv {} artifacts/ \;
find artifacts -type f -name "*.tar.gz" -exec mv {} artifacts/ \;
- name: Debug list files
run: ls -R artifacts
- name: Generate SHA256 checksums
run: |
cd artifacts
sha256sum * > SHA256SUMS.txt
cat SHA256SUMS.txt
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
name: "Release ${{ github.ref_name }}"
generate_release_notes: true
files: |
artifacts/*
docker:
name: Build and Push Docker Image
needs: [build, release]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Linux musl artifact
uses: actions/download-artifact@v4
with:
name: x86_64-unknown-linux-musl
path: artifacts
- name: Prepare Docker context
run: |
tar -xzf artifacts/${{ env.BINARY_NAME }}-*.tar.gz -C docker
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./docker
push: true
tags: |
rustmailer/rustmailer:${{ github.ref_name }}
rustmailer/rustmailer:latest
build-args: |
CRATE_VERSION=${{ github.ref_name }}