Skip to content

chore: Cargo update #27

chore: Cargo update

chore: Cargo update #27

Workflow file for this run

# References:
# - https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/
# - https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/release.yml
name: Release
on:
push:
tags:
- 'v[0-9]+.*'
# Allow one concurrent check
concurrency:
group: "punktf-release"
cancel-in-progress: false
defaults:
run:
shell: bash
permissions:
contents: write
jobs:
create-release:
name: Create release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
steps:
- name: Get release version
shell: bash
if: env.PUNKTF_VERSION == ''
run: |
# Get the version from github tag
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
echo "PUNKTF_VERSION=${GITHUB_REF#refs/tags/v}" >> "${GITHUB_ENV}"
echo "Version: ${{ env.PUNKTF_VERSION }}"
- name: Create release
id: release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
name: ${{ env.PUNKTF_VERSION }}
generate_release_notes: true
build-release:
name: Build release
needs: ['create-release']
runs-on: ${{ matrix.os }}
env:
# Build tool. For some builds this can be cross.
CARGO: cargo
# When `CARGO` is set to `cross` this will be set to `--target {{matrix.target}}`.
TARGET_FLAGS: ""
# When `CARGO` is set to `cross` this will be set to `./target/{{matrix.target}}`.
TARGET_DIR: ./target
# Get backtraces on panics.
RUST_BACKTRACE: 1
strategy:
matrix:
build: [linux, win-msvc, win32-msvc]
include:
- build: linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-musl
- build: win-msvc
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
- build: win-msvc-static
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
features: windows-static
name: x86_64-pc-windows-msvc-static
- build: win32-msvc
os: windows-latest
rust: stable
target: i686-pc-windows-msvc
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Update packages (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update -y
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: Setup Cross
shell: bash
run: |
cargo install cross
{
echo "CARGO=cross"
echo "TARGET_FLAGS=--target ${{ matrix.target }}"
echo "TARGET_DIR=./target/${{ matrix.target }}"
} >> "${GITHUB_ENV}"
- name: Log env
run: |
echo "cargo: ${{ env.CARGO }}"
echo "target flags: ${{ env.TARGET_FLAGS }}"
echo "target dir: ${{ env.TARGET_DIR }}"
- name: Build release binary without features
if: ${{ matrix.features == '' }}
run: |
${{ env.CARGO }} build --release ${{ env.TARGET_FLAGS }}
- name: Build release binary with features
if: ${{ matrix.features != '' }}
run: |
${{ env.CARGO }} build --release ${{ env.TARGET_FLAGS }} --features ${{ matrix.features }}
- name: Strip release binary (linux)
if: matrix.build == 'linux'
run: strip "${{ env.TARGET_DIR }}/release/punktf"
- name: Build archive
shell: bash
run: |
suffix="${{ matrix.name }}"
staging="punktf-${suffix:-${{ matrix.target }}}"
mkdir -p "${staging}"
if [[ "${{ matrix.os }}" = "windows-latest" ]]; then
echo "Archiving windows build"
cp "${{ env.TARGET_DIR }}/release/punktf.exe" "${staging}/"
7z a "${staging}.zip" "${staging}"
echo "ASSET=${staging}.zip" >> "${GITHUB_ENV}"
else
echo "Archiving unix build"
cp "${{ env.TARGET_DIR }}/release/punktf" "${staging}/"
tar czf "${staging}.tar.gz" "${staging}"
echo "ASSET=${staging}.tar.gz" >> "${GITHUB_ENV}"
fi
- name: Calculate hashes (linux)
if: matrix.build == 'linux'
shell: bash
run: |
mkdir -p hashes
# Cut to only get the hash
shasum -a256 "${{ env.ASSET }}" | cut -d ' ' -f 1 > "hashes/${{ env.ASSET }}.sha256"
shasum -a512 "${{ env.ASSET }}" | cut -d ' ' -f 1 > "hashes/${{ env.ASSET }}.sha512"
- name: Calculate hashes (windows)
if: matrix.build != 'linux'
shell: powershell
run: |
mkdir -p hashes
(Get-FileHash -Path "${{ env.ASSET }}" -Algorithm SHA256).Hash > "hashes/${{ env.ASSET }}.sha256"
(Get-FileHash -Path "${{ env.ASSET }}" -Algorithm SHA512).Hash > "hashes/${{ env.ASSET }}.sha512"
- name: Upload archive
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ${{ env.ASSET }}
asset_name: ${{ env.ASSET }}
asset_content_type: application/octet-stream
- name: Upload hashes
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: "hashes/*"
asset_content_type: application/octet-stream