tempura 0.5.2

Pipeline-based Static site generator
Documentation
name: Release to GitHub and Crates.io

on:
  pull_request:
    types:
      - closed

env:
  # Disable incremental build
  CARGO_INCREMENTAL: 0
  PJ_NAME: tempura

jobs:
  version:
    name: Get version from git tag
    runs-on: ubuntu-latest
    if: ${{ startsWith(github.head_ref, 'release/') && github.event.pull_request.merged }}
    outputs:
      version: ${{ steps.s.outputs.version }}
    steps:
      - id: s
        run: |
          ref=${{ github.head_ref }}
          version=${ref#release/}
          echo $version
          echo "version=$version" >> $GITHUB_OUTPUT

  build:
    name: Build for ${{ matrix.target }} on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    if: ${{ startsWith(github.head_ref, 'release/') && github.event.pull_request.merged }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: i686-unknown-linux-gnu
            os: ubuntu-latest
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
          - target: i686-unknown-linux-musl
            os: ubuntu-latest
          - target: aarch64-unknown-linux-musl
            os: ubuntu-latest
          
          - target: x86_64-pc-windows-msvc
            os: windows-latest
          - target: i686-pc-windows-msvc
            os: windows-latest
          
          - target: x86_64-apple-darwin
            os: macos-latest
          - target: aarch64-apple-darwin
            os: macos-latest

    steps:
    - name: Setup | Checkout
      uses: actions/checkout@v3
    
    - name: Setup | Rust Toolchain
      uses: actions-rs/toolchain@v1.0.6
      with:
          toolchain: stable
          target: ${{ matrix.target }}
          override: true
    
    - name: Build | Build
      uses: actions-rs/cargo@v1.0.1
      with:
          command: build
          args: --release --locked --target=${{ matrix.target }}
          use-cross: ${{ matrix.os == 'ubuntu-latest' }}
          
    - name: Post Build | Compress artifacts [-nix]
      if: matrix.os != 'windows-latest'
      run: |
        cd target/${{ matrix.target }}/release
        tar czvf ../../../${{ env.PJ_NAME }}-${{ matrix.target }}.tar.gz ${{ env.PJ_NAME }}
        cd -
          
    - name: Post Build | Compress artifacts [Windows]
      if: matrix.os == 'windows-latest'
      run: |
        cd target/${{ matrix.target }}/release
        7z a     ../../../${{ env.PJ_NAME }}-${{ matrix.target }}.zip    ${{ env.PJ_NAME }}.exe
        cd -
    
    - name: Post Build | Upload artifacts [-nix]
      uses: actions/upload-artifact@v3
      if: matrix.os != 'windows-latest'
      with:
        name: ${{ env.PJ_NAME }}-${{ matrix.target }}.tar.gz
        path: ${{ env.PJ_NAME }}-${{ matrix.target }}.tar.gz
    
    - name: Post Build | Upload artifacts [Windows]
      uses: actions/upload-artifact@v3
      if: matrix.os == 'windows-latest'
      with:
        name: ${{ env.PJ_NAME }}-${{ matrix.target }}.zip
        path: ${{ env.PJ_NAME }}-${{ matrix.target }}.zip
  
  github_release:
    name: Make a new GitHub release for ${{ needs.version.outputs.version }}
    needs: [build, version]
    runs-on: ubuntu-latest
    if: ${{ startsWith(github.head_ref, 'release/') && github.event.pull_request.merged }}
    steps:
      - name: Download release note
        uses: dawidd6/action-download-artifact@v2
        with:
          workflow: pre-release.yml
          workflow_conclusion: success

      - name: Download artifacts
        uses: actions/download-artifact@v4.1.7
        with:
          merge-multiple: true
        
      - name: Add Artifacts to Release
        uses: softprops/action-gh-release@v1
        with:
          files: ${{ env.PJ_NAME }}-*/${{ env.PJ_NAME }}-*
          body_path: release-note/RELEASE_NOTE.md
          tag_name: ${{ needs.version.outputs.version }}

  crates_io_publish:
    name: Publish ${{ needs.version.outputs.version }} to Crates.io
    needs: [build]
    runs-on: ubuntu-latest
    if: ${{ startsWith(github.head_ref, 'release/') && github.event.pull_request.merged }}
    steps:
      - name: Setup | Checkout
        uses: actions/checkout@v3
      
      - name: Publish
        run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}