Skip to content

Working on release script #7

Working on release script

Working on release script #7

Workflow file for this run

name: Release
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
inputs:
tag:
description: 'Tag to build release for'
required: true
type: string
permissions:
contents: write
jobs:
create-release:
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Get version from tag
id: get_version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ inputs.tag }}" >> $GITHUB_OUTPUT
echo "tag_name=${{ inputs.tag }}" >> $GITHUB_OUTPUT
else
VERSION=${GITHUB_REF#refs/tags/}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag_name=$VERSION" >> $GITHUB_OUTPUT
fi
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ steps.get_version.outputs.tag_name }}
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.tag_name }}
release_name: ${{ steps.get_version.outputs.tag_name }}
draft: false
prerelease: false
build-release:
needs: create-release
strategy:
matrix:
include:
# Linux x86_64
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: cfcli-x86_64-unknown-linux-gnu.tar.gz
# Linux ARM64
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
name: cfcli-aarch64-unknown-linux-gnu.tar.gz
# macOS x86_64
- target: x86_64-apple-darwin
os: macos-latest
name: cfcli-x86_64-apple-darwin.tar.gz
# macOS ARM64
- target: aarch64-apple-darwin
os: macos-latest
name: cfcli-aarch64-apple-darwin.tar.gz
# Windows x86_64
- target: x86_64-pc-windows-msvc
os: windows-latest
name: cfcli-x86_64-pc-windows-msvc.zip
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.create-release.outputs.version }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install OpenSSL (Linux x86_64)
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev pkg-config libudev-dev
- name: Install cross-compilation tools (Linux ARM)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
# Add ARM64 architecture
sudo dpkg --add-architecture arm64
# Configure apt to ignore ARM64 packages from repositories that don't support it
echo 'Acquire::Languages "none";' | sudo tee /etc/apt/apt.conf.d/99disable-translations
sudo apt-get update || true # Continue even if some repos fail
# Install ARM64 development libraries
sudo apt-get install -y libssl-dev:arm64 libudev-dev:arm64 || {
echo "Failed to install ARM64 libraries, trying alternative approach"
sudo apt-get install -y libssl-dev libudev-dev
}
# Configure pkg-config for cross-compilation
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig" >> $GITHUB_ENV
echo "PKG_CONFIG_SYSROOT_DIR=/" >> $GITHUB_ENV
echo "OPENSSL_NO_VENDOR=1" >> $GITHUB_ENV
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Package (Unix)
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../${{ matrix.name }} cfcli
cd -
- name: Package (Windows)
if: matrix.os == 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
7z a ../../../${{ matrix.name }} cfcli.exe
cd -
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./${{ matrix.name }}
asset_name: ${{ matrix.name }}
asset_content_type: application/octet-stream
- name: Generate SHA256 checksum
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
certutil -hashfile ${{ matrix.name }} SHA256 > ${{ matrix.name }}.sha256
else
shasum -a 256 ${{ matrix.name }} > ${{ matrix.name }}.sha256
fi
shell: bash
- name: Upload Checksum
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./${{ matrix.name }}.sha256
asset_name: ${{ matrix.name }}.sha256
asset_content_type: text/plain
build-deb:
needs: create-release
strategy:
matrix:
include:
# Debian/Ubuntu x86_64
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
arch: amd64
# Debian/Ubuntu ARM64
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
arch: arm64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.create-release.outputs.version }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cargo-deb
run: cargo install cargo-deb
- name: Install dependencies (x86_64)
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev pkg-config libudev-dev
- name: Install cross-compilation tools (ARM64)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
# Add ARM64 architecture
sudo dpkg --add-architecture arm64
# Configure apt to ignore ARM64 packages from repositories that don't support it
echo 'Acquire::Languages "none";' | sudo tee /etc/apt/apt.conf.d/99disable-translations
sudo apt-get update || true # Continue even if some repos fail
# Install ARM64 development libraries
sudo apt-get install -y libssl-dev:arm64 libudev-dev:arm64 || {
echo "Failed to install ARM64 libraries, trying alternative approach"
sudo apt-get install -y libssl-dev libudev-dev
}
# Configure pkg-config for cross-compilation
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig" >> $GITHUB_ENV
echo "PKG_CONFIG_SYSROOT_DIR=/" >> $GITHUB_ENV
echo "OPENSSL_NO_VENDOR=1" >> $GITHUB_ENV
- name: Build deb package
run: cargo deb --target ${{ matrix.target }} --no-strip
- name: Find deb package
id: find_deb
run: |
DEB_PATH=$(find target/${{ matrix.target }}/debian -name "*.deb" -type f)
DEB_NAME=$(basename "$DEB_PATH")
echo "deb_path=$DEB_PATH" >> $GITHUB_OUTPUT
echo "deb_name=$DEB_NAME" >> $GITHUB_OUTPUT
- name: Upload deb package
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ${{ steps.find_deb.outputs.deb_path }}
asset_name: ${{ steps.find_deb.outputs.deb_name }}
asset_content_type: application/vnd.debian.binary-package