mural-client 1.2.1

Client software for the mural wallpaper service
Documentation
name: Create release

on:
  push:
    tags:
      - "*"

jobs:
  define-matrix:
    name: Define the target matrix
    runs-on: ubuntu-latest

    outputs:
      matrix: ${{ steps.define-matrix.outputs.matrix }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
    
      - name: Define the matrix
        id: define-matrix
        run: |
          echo "matrix=$(jq -c . .github/matrix.json)" >> "$GITHUB_OUTPUT"

  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    container: rust

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Publish
        run: |
          cargo publish --allow-dirty
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  
  generate-changelog:
    name: Generate changelog
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Generate changelog
        uses: orhun/git-cliff-action@v4
        id: git-cliff
        with:
          config: cliff.toml
          args: -vv --latest --strip header
        env:
          OUTPUT: CHANGES.md
          GITHUB_REPO: ${{ github.repository }}

      - name: Upload changelog artifact
        uses: actions/upload-artifact@v4
        with:
          name: changelog
          path: CHANGES.md

  build-binaries:
    needs:
      - define-matrix

    strategy:
      matrix:
        target: ${{ fromJson(needs.define-matrix.outputs.matrix) }}

    name: Build binary for ${{ matrix.target.target }}
    runs-on: ${{ matrix.target.runner }}
    container: ${{ matrix.target.container }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install dependencies
        run: |
          ${{ matrix.target.install_dependencies }}

      - name: Build
        run: |
          cargo build --release --target ${{ matrix.target.target }}

      - name: Upload binary artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ github.event.repository.name }}-${{ matrix.target.target }}
          path: target/${{ matrix.target.target }}/release/${{ github.event.repository.name }}

  create-release:
    needs:
      - generate-changelog
    
    name: Create the release
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Download changelog artifact
        uses: actions/download-artifact@v4
        with:
          name: changelog

      - name: Create the release
        run: |
          gh release create --draft --title "Release ${{ github.ref_name }}" --notes-file CHANGES.md ${{ github.ref_name }}
        env:
          GH_TOKEN: ${{ github.token }}

  upload-binaries-to-release:
    needs:
      - build-binaries
      - create-release
      - define-matrix

    strategy:
      matrix:
        target: ${{ fromJson(needs.define-matrix.outputs.matrix) }}

    name: Upload binary for ${{ matrix.target.target }}
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Download binary artifact
        uses: actions/download-artifact@v4
        with:
          name: ${{ github.event.repository.name }}-${{ matrix.target.target }}

      - name: Rename binary artifact
        run: |
          mv ${{ github.event.repository.name }} ${{ github.event.repository.name }}-${{ matrix.target.target }}

      - name: Upload binary to release
        run: |
          gh release upload ${{ github.ref_name }} ${{ github.event.repository.name }}-${{ matrix.target.target }}
        env:
          GH_TOKEN: ${{ github.token }}