name: Build and Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build (${{ matrix.target }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: password_manager-linux-x86_64.tar.gz
binary: password_manager
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: password_manager-windows-x86_64.zip
binary: password_manager.exe
- target: x86_64-apple-darwin
os: macos-13
archive: password_manager-macos-x86_64.tar.gz
binary: password_manager
- target: aarch64-apple-darwin
os: macos-14
archive: password_manager-macos-aarch64.tar.gz
binary: password_manager
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install target
run: rustup target add ${{ matrix.target }}
- name: Build release
run: cargo build --release --target ${{ matrix.target }}
- name: Create release archive (Windows)
if: ${{ runner.os == 'Windows' }}
shell: pwsh
run: |
New-Item -ItemType Directory -Path dist -Force | Out-Null
Compress-Archive -Path "target/${{ matrix.target }}/release/${{ matrix.binary }}" -DestinationPath "dist/${{ matrix.archive }}" -Force
- name: Create release archive (Unix)
if: ${{ runner.os != 'Windows' }}
shell: bash
run: |
mkdir -p dist
tar -czf dist/${{ matrix.archive }} -C target/${{ matrix.target }}/release ${{ matrix.binary }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.archive }}
path: dist/${{ matrix.archive }}
release:
name: Create Release
runs-on: ubuntu-latest
needs: [build]
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: '*'
path: dist
merge-multiple: true
- name: List downloaded artifacts
run: |
echo "Listing dist contents:" && ls -la dist || true
echo "Recursive list:" && ls -laR dist || true
- name: Create release
uses: ncipollo/release-action@v1
with:
artifacts: "dist/*.tar.gz,dist/*.zip"
allowUpdates: true
draft: false
prerelease: false
generateReleaseNotes: true
tag: ${{ github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: [build]
if: startsWith(github.ref, 'refs/tags/')
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Cargo publish dry-run
run: cargo publish --dry-run --locked -v
- name: Publish to crates.io
if: ${{ env.CARGO_REGISTRY_TOKEN != '' }}
run: cargo publish --locked -v