wash-cli 0.21.0

wasmcloud Shell (wash) CLI tool
name: Docker build check

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    name: build release assets
    runs-on: ${{ matrix.config.os }}
    outputs:
      version_output: ${{ steps.version_output.outputs.version }}
    strategy:
      matrix:
        config:
          # NOTE: We are building on an older version of ubuntu because of libc compatibility
          # issues. Namely, if we build on a new version of libc, it isn't backwards compatible with
          # old versions. But if we build on the old version, it is compatible with the newer
          # versions running in ubuntu 22 and its ilk
          - os: "ubuntu-20.04"
            arch: "amd64"
            extension: ""
            targetPath: "target/release/"
          - os: "ubuntu-20.04"
            arch: "aarch64"
            extension: ""
            targetPath: "target/aarch64-unknown-linux-gnu/release/"
    steps:
      - uses: actions/checkout@v4

      - name: set the release version (tag)
        if: startsWith(github.ref, 'refs/tags/v')
        shell: bash
        run: echo "RELEASE_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV

      - name: set the release version (main)
        if: github.ref == 'refs/heads/main'
        shell: bash
        run: echo "RELEASE_VERSION=canary" >> $GITHUB_ENV

      - name: Output Version
        id: version_output
        run: echo "version=$RELEASE_VERSION" >> $GITHUB_OUTPUT

      - name: lowercase the runner OS name
        shell: bash
        run: |
          OS=$(echo "${{ runner.os }}" | tr '[:upper:]' '[:lower:]')
          echo "RUNNER_OS=$OS" >> $GITHUB_ENV

      - name: Install latest Rust stable toolchain
        uses: dtolnay/rust-toolchain@stable
        if: matrix.config.arch != 'aarch64'
        with:
          toolchain: stable
          components: clippy, rustfmt

      - name: setup for cross-compile builds
        if: matrix.config.arch == 'aarch64' && matrix.config.os == 'ubuntu-20.04'
        run: |
          sudo apt-get update
          sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
          rustup toolchain install stable-aarch64-unknown-linux-gnu
          rustup target add --toolchain stable-aarch64-unknown-linux-gnu aarch64-unknown-linux-gnu
          echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
          echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
          echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV

      - name: Install latest Rust stable toolchain
        uses: dtolnay/rust-toolchain@stable
        if: matrix.config.arch == 'aarch64' && matrix.config.os == 'ubuntu-20.04'
        with:
          toolchain: stable
          components: clippy, rustfmt
          target: aarch64-unknown-linux-gnu

      - name: build release
        if: matrix.config.arch != 'aarch64'
        run: "cargo build --release"

      - name: build release
        if: matrix.config.arch == 'aarch64' && matrix.config.os == 'ubuntu-20.04'
        run: "cargo build --release --target aarch64-unknown-linux-gnu"

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Docker metadata
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: |
            wasmcloud/wash
            wasmcloud.azurecr.io/wash
          tags: |
            type=semver,pattern={{version}}
            type=sha
          flavor: |
            latest=auto
          labels: |
            org.opencontainers.image.title=wash
            org.opencontainers.image.description=WAsmcloud SHell
            org.opencontainers.image.vendor=wasmCloud
            org.opencontainers.image.source=https://github.com/${{ github.repository }}

      - name: Docker build
        uses: docker/build-push-action@v5
        with:
          file: "Dockerfile"
          context: .
          platforms: linux/${{ matrix.config.arch }}
          build-args: |
            BIN_AMD64=${{ matrix.config.targetPath }}/wash
            BIN_ARM64=${{ matrix.config.targetPath }}/wash
          labels: ${{ steps.meta.outputs.labels }}
          push: false