diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.yml new file mode 100644 index 000000000..1716b5a5f --- /dev/null +++ b/.github/workflows/release-cli.yml @@ -0,0 +1,168 @@ +name: Release CLI + +on: + release: + types: [published] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + name: Build ${{ matrix.platform.target }} + runs-on: ${{ matrix.platform.os }} + strategy: + fail-fast: false + matrix: + platform: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + arch: x86_64 + - target: aarch64-unknown-linux-gnu + os: ubuntu-latest + arch: aarch64 + - target: riscv64gc-unknown-linux-gnu + os: ubuntu-latest + arch: riscv64gc + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.platform.target }} + + - name: Install cross + run: cargo install cross --git https://github.com/cross-rs/cross --tag v0.2.5 + + - name: Build + run: cross build --release --bin km --target ${{ matrix.platform.target }} + + - name: Rename binary + run: | + mv target/${{ matrix.platform.target }}/release/km km-${{ matrix.platform.arch }} + + - name: Upload binary artifact + uses: actions/upload-artifact@v4 + with: + name: km-${{ matrix.platform.arch }} + path: km-${{ matrix.platform.arch }} + + package-deb: + name: DEB ${{ matrix.platform.arch }} + needs: build + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - arch: x86_64 + deb_arch: amd64 + - arch: aarch64 + deb_arch: arm64 + - arch: riscv64gc + deb_arch: riscv64 + + steps: + - name: Download binary + uses: actions/download-artifact@v4 + with: + name: km-${{ matrix.platform.arch }} + + - name: Build DEB package + run: | + VERSION="${GITHUB_REF_NAME#v}" + mkdir -p pkg/DEBIAN pkg/usr/bin + chmod +x km-${{ matrix.platform.arch }} + cp km-${{ matrix.platform.arch }} pkg/usr/bin/km + printf 'Package: komodo-cli\nVersion: %s\nSection: utils\nPriority: optional\nArchitecture: %s\nDepends: libc6\nMaintainer: Max Becker \nDescription: Komodo CLI\n Command line tool for Komodo deployment management platform.\n Provides the '\''km'\'' binary for interacting with Komodo.\nHomepage: https://komo.do\n' "$VERSION" "${{ matrix.platform.deb_arch }}" > pkg/DEBIAN/control + dpkg-deb --build pkg komodo-cli_${VERSION}_${{ matrix.platform.deb_arch }}.deb + + - name: Upload DEB artifact + uses: actions/upload-artifact@v4 + with: + name: komodo-cli_${{ matrix.platform.deb_arch }}.deb + path: komodo-cli_*_${{ matrix.platform.deb_arch }}.deb + + package-rpm: + name: RPM ${{ matrix.platform.arch }} + needs: build + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - arch: x86_64 + rpm_arch: x86_64 + - arch: aarch64 + rpm_arch: aarch64 + - arch: riscv64gc + rpm_arch: riscv64 + + steps: + - name: Download binary + uses: actions/download-artifact@v4 + with: + name: km-${{ matrix.platform.arch }} + + - name: Install rpm tools + run: sudo apt-get update && sudo apt-get install -y rpm + + - name: Build RPM package + run: | + VERSION="${GITHUB_REF_NAME#v}" + RELEASE="1" + chmod +x km-${{ matrix.platform.arch }} + RPM_ARCH=${{ matrix.platform.rpm_arch }} + BUILDROOT=komodo-cli-${VERSION}-${RELEASE}.${RPM_ARCH} + + mkdir -p ~/rpmbuild/{SOURCES,SPECS,BUILD,RPMS} + mkdir -p ~/rpmbuild/BUILDROOT/${BUILDROOT}/usr/bin + cp km-${{ matrix.platform.arch }} ~/rpmbuild/BUILDROOT/${BUILDROOT}/usr/bin/km + chmod +x ~/rpmbuild/BUILDROOT/${BUILDROOT}/usr/bin/km + + CHANGELOG_DATE=$(date '+%a %b %d %Y') + printf 'Name: komodo-cli\nVersion: %s\nRelease: %s%%{?dist}\nSummary: Komodo CLI - command line tool for Komodo\n\nLicense: GPL-3.0-or-later\nURL: https://komo.do\nSource0: https://github.com/moghtech/komodo\n\nExclusiveArch: %s\n\n%%description\nCommand line tool for Komodo deployment management platform.\nProvides the '\''km'\'' binary for interacting with Komodo.\n\n%%files\n/usr/bin/km\n\n%%changelog\n* %s Komodo - %s-%s\n- Release %s\n' "$VERSION" "$RELEASE" "$RPM_ARCH" "$CHANGELOG_DATE" "$VERSION" "$RELEASE" "$VERSION" > ~/rpmbuild/SPECS/komodo-cli.spec + + rpmbuild -bb \ + --target ${RPM_ARCH} \ + --buildroot ~/rpmbuild/BUILDROOT/${BUILDROOT} \ + ~/rpmbuild/SPECS/komodo-cli.spec + + cp ~/rpmbuild/RPMS/${RPM_ARCH}/komodo-cli-*.rpm . + + - name: Upload RPM artifact + uses: actions/upload-artifact@v4 + with: + name: komodo-cli-${{ matrix.platform.rpm_arch }}.rpm + path: komodo-cli-*.rpm + + release: + name: Publish Release Assets + needs: [build, package-deb, package-rpm] + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + merge-multiple: false + + - name: Flatten artifacts + run: | + mkdir -p release-assets + find artifacts -type f \( \ + -name 'km-*' -o \ + -name '*.deb' -o \ + -name '*.rpm' \ + \) -exec cp {} release-assets/ \; + ls -la release-assets/ + + - name: Upload release assets + uses: softprops/action-gh-release@v2 + with: + files: release-assets/* diff --git a/docsite/docs/ecosystem/cli.mdx b/docsite/docs/ecosystem/cli.mdx index 3102676f6..3ecfa78a4 100644 --- a/docsite/docs/ecosystem/cli.mdx +++ b/docsite/docs/ecosystem/cli.mdx @@ -52,7 +52,7 @@ Secret variable values are masked by default. Set `KM_SHOW_SECRETS=true` or `KM_ ## Install -There are binaries available for Linux (`x86_64` / `aarch64`), macOS (Apple silicon), and a distroless image at `ghcr.io/moghtech/komodo-cli`. +There are binaries available for Linux (`x86_64` / `aarch64` / `riscv64`), macOS (Apple silicon), and a distroless image at `ghcr.io/moghtech/komodo-cli`. ### Linux diff --git a/scripts/install-cli.py b/scripts/install-cli.py index c8a642fea..1399ca3ad 100644 --- a/scripts/install-cli.py +++ b/scripts/install-cli.py @@ -49,13 +49,16 @@ def download_binary(args, bin_dir): if os.path.isfile(bin_path): os.remove(bin_path) - km_bin = "km-x86_64" arch = platform.machine().lower() if arch == "aarch64" or arch == "arm64": print("aarch64 detected") km_bin = "km-aarch64" + elif arch in ("riscv64", "riscv64gc"): + print("riscv64 detected") + km_bin = "km-riscv64gc" else: print("using x86_64 binary") + km_bin = "km-x86_64" # download the binary to bin path if os.system(f'curl -f -sSL {args.binary_url}/{args.version}/{km_bin} -o {bin_path}') != 0: