beamdpr 1.4.0

Combine and transform egsphsp (EGS phase space) files for use with BEAMnrc
Documentation
name: Release

on:
  push:
    tags:
      - "v*.*.*"
  workflow_dispatch:
    inputs:
      tag:
        description: "Release tag to build (e.g. v1.1.0). Created if it doesn't exist."
        required: true

permissions:
  contents: write

jobs:
  build:
    name: ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            archive: tar.gz
          - target: x86_64-apple-darwin
            os: macos-latest
            archive: tar.gz
          - target: aarch64-apple-darwin
            os: macos-latest
            archive: tar.gz
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            archive: zip

    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: 1.95.0
          targets: ${{ matrix.target }}

      - name: Cache cargo registry and target
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

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

      - name: Resolve version
        id: version
        shell: bash
        run: |
          if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
            tag="${{ github.event.inputs.tag }}"
          else
            tag="${GITHUB_REF#refs/tags/}"
          fi
          echo "tag=${tag}" >> "$GITHUB_OUTPUT"
          echo "version=${tag#v}" >> "$GITHUB_OUTPUT"

      - name: Package (unix)
        if: matrix.archive == 'tar.gz'
        shell: bash
        run: |
          name="beamdpr-${{ steps.version.outputs.version }}-${{ matrix.target }}"
          mkdir -p "dist/${name}"
          cp "target/${{ matrix.target }}/release/beamdpr" "dist/${name}/"
          cp README.md "dist/${name}/"
          tar -C dist -czf "dist/${name}.tar.gz" "${name}"
          echo "ASSET=dist/${name}.tar.gz" >> "$GITHUB_ENV"

      - name: Package (windows)
        if: matrix.archive == 'zip'
        shell: pwsh
        run: |
          $name = "beamdpr-${{ steps.version.outputs.version }}-${{ matrix.target }}"
          New-Item -ItemType Directory -Force -Path "dist/$name" | Out-Null
          Copy-Item "target/${{ matrix.target }}/release/beamdpr.exe" "dist/$name/"
          Copy-Item README.md "dist/$name/"
          Compress-Archive -Path "dist/$name" -DestinationPath "dist/$name.zip"
          "ASSET=dist/$name.zip" | Out-File -FilePath $env:GITHUB_ENV -Append

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: beamdpr-${{ matrix.target }}
          path: ${{ env.ASSET }}

  release:
    name: Publish release
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Resolve tag
        id: version
        run: |
          if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
            echo "tag=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
          else
            echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
          fi

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

      - name: Publish GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ steps.version.outputs.tag }}
          name: ${{ steps.version.outputs.tag }}
          generate_release_notes: true
          files: artifacts/**/*