python-launcher 1.0.0

The Python launcher for Unix
Documentation
name: Release

on: workflow_dispatch

permissions:
  contents: write

env:
  toolchain: stable

jobs:
  details:
    name: Release details
    runs-on: ubuntu-latest

    outputs:
      version: ${{ steps.version.outputs.version }}
      tag: ${{ steps.version.outputs.tag }}
      notes: ${{ env.RELEASE_NOTES }}

    steps:
      - uses: actions/checkout@v2

      # OS-specific
      - uses: actions/cache@v2
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ hashFiles('release/requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-

      - name: Install Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.x

      - name: Install dependencies
        run: python -m pip install -r release/requirements.txt
        shell: bash

      - name: Version details
        id: version
        run: |
          echo "::set-output name=version::`python -m release version`"
          echo "::set-output name=tag::`python -m release version --tag`"
        shell: bash

      - name: Release notes
        id: changelog
        run: |
          echo 'RELEASE_NOTES<<EOF' >> $GITHUB_ENV
          python -m release notes >> $GITHUB_ENV
          echo 'EOF' >> $GITHUB_ENV
        shell: bash

  release:
    name: GitHub release
    needs: details
    runs-on: ubuntu-latest

    steps:
      # Necessary to implicitly specify the repo to create the release for.
      - uses: actions/checkout@v2

      # OS-specific
      - uses: actions/cache@v2
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ hashFiles('release/requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-

      - name: Install Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.x

      - name: Install dependencies
        run: python -m pip install -r release/requirements.txt
        shell: bash

      - name: Update changelog
        run: |
          python -m scriv collect --add --version ${{ needs.details.outputs.version }}
          git config user.name github-actions
          git config user.email github-actions@github.com
          git commit -a -m "Update changelog for ${{ needs.details.outputs.tag }}"
          git push
        shell: bash

      - name: Create release
        run: |
          echo "${{ needs.details.outputs.notes }}" > /tmp/release_notes.md
          gh release create ${{ needs.details.outputs.tag }} --draft --notes-file /tmp/release_notes.md
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  build:
    name: Build ${{ matrix.target }}
    needs: [details, release]
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        # https://doc.rust-lang.org/stable/rustc/platform-support.html
        # https://github.com/rust-embedded/cross#supported-targets
        # aarch64-apple-darwin (basically) requires macos-11 to be generally available.
        include:
          - target: x86_64-apple-darwin
            os: macos-latest
            use-cross: false
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            use-cross: false
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            use-cross: true
          - target: riscv64gc-unknown-linux-gnu
            os: ubuntu-latest
            use-cross: true
          - target: x86_64-unknown-netbsd
            os: ubuntu-latest
            use-cross: true

    steps:
      - uses: actions/checkout@v2

      # OS-specific
      - uses: actions/cache@v2
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ hashFiles('release/requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-

      - name: Install Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.x

      - name: Install dependencies
        run: python -m pip install -r release/requirements.txt
        shell: bash

      - name: Install Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ env.toolchain }}
          target: ${{ matrix.target }}
          override: true
          profile: minimal

      - name: Cargo build
        uses: actions-rs/cargo@v1
        with:
          toolchain: ${{ env.toolchain }}
          use-cross: ${{ matrix.use-cross }}
          command: build
          args: --release --target ${{ matrix.target }}

      - name: Strip binary
        if: ${{ !matrix.use-cross }}
        run: |
          du -h target/${{ matrix.target }}/release/py
          strip target/${{ matrix.target }}/release/py
          du -h target/${{ matrix.target }}/release/py
        shell: bash

      - name: Create tarball
        run: |
          TARBALL_PATH=`python -m release tarball --target ${{ matrix.target }}`
          du -h $TARBALL_PATH
          tar -tvf $TARBALL_PATH
          echo "tarball_path=$TARBALL_PATH" >> $GITHUB_ENV
        shell: bash

      - name: Upload tarball
        run: gh release upload ${{ needs.details.outputs.tag }} ${{ env.tarball_path }} --clobber
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  publish:
    name: Publish to crates.io
    needs: release
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Install Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ env.toolchain }}
          override: true
          profile: minimal

      - name: Publish
        run: cargo publish --locked
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}