Skip to content

chore: Update Cargo.lock for version 0.0.1 #3

chore: Update Cargo.lock for version 0.0.1

chore: Update Cargo.lock for version 0.0.1 #3

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch: # Allows manual testing
env:
CARGO_TERM_COLOR: always
jobs:
create-release:
name: Create Release
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.create_release.outputs.result }}
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: actions/github-script@v7
with:
script: |
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: context.ref.replace('refs/tags/', ''),
name: `Release ${context.ref.replace('refs/tags/', '')}`,
draft: true,
prerelease: false
});
return release.data.id;
build:
name: Build ${{ matrix.target }}
needs: create-release
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
matrix:
include:
# Linux x86_64
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: pgsqlite
asset_name: pgsqlite-linux-amd64
use_cross: false
# Linux ARM64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
artifact_name: pgsqlite
asset_name: pgsqlite-linux-arm64
use_cross: true
# Windows x86_64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: pgsqlite.exe
asset_name: pgsqlite-windows-amd64
use_cross: false
# macOS x86_64
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: pgsqlite
asset_name: pgsqlite-macos-intel
use_cross: false
# macOS ARM64
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: pgsqlite
asset_name: pgsqlite-macos-apple-silicon
use_cross: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ matrix.target }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ matrix.target }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Install cross
if: matrix.use_cross == true
run: cargo install cross --version 0.2.5
- name: Build (cargo)
if: matrix.use_cross == false
run: cargo build --release --target ${{ matrix.target }}
- name: Build (cross)
if: matrix.use_cross == true
run: cross build --release --target ${{ matrix.target }}
- name: Strip binary (Unix)
if: matrix.os != 'windows-latest'
run: |
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
else
if [[ "${{ matrix.use_cross }}" == "true" ]]; then
docker run --rm -v "$PWD:/work" -w /work rustembedded/cross:${{ matrix.target }} \
aarch64-linux-gnu-strip /work/target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
else
strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
fi
fi
- name: Create archive (Unix)
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }}
cd -
- name: Create archive (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
cd target\${{ matrix.target }}\release
Compress-Archive -Path ${{ matrix.artifact_name }} -DestinationPath ..\..\..\${{ matrix.asset_name }}.zip
cd -
- name: Generate SHA256 (Unix)
if: matrix.os != 'windows-latest'
run: |
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
shasum -a 256 ${{ matrix.asset_name }}.tar.gz > ${{ matrix.asset_name }}.tar.gz.sha256
else
sha256sum ${{ matrix.asset_name }}.tar.gz > ${{ matrix.asset_name }}.tar.gz.sha256
fi
- name: Generate SHA256 (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$hash = Get-FileHash -Path "${{ matrix.asset_name }}.zip" -Algorithm SHA256
"$($hash.Hash.ToLower()) ${{ matrix.asset_name }}.zip" | Out-File -FilePath "${{ matrix.asset_name }}.zip.sha256" -NoNewline
- name: Upload Release Assets
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const releaseId = ${{ needs.create-release.outputs.release_id }};
// Determine file extension based on OS
const isWindows = '${{ matrix.os }}' === 'windows-latest';
const archiveExt = isWindows ? 'zip' : 'tar.gz';
const archiveName = `${{ matrix.asset_name }}.${archiveExt}`;
const checksumName = `${archiveName}.sha256`;
// Upload main archive
console.log(`Uploading ${archiveName}...`);
const archiveData = fs.readFileSync(archiveName);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
name: archiveName,
data: archiveData,
headers: {
'content-type': isWindows ? 'application/zip' : 'application/gzip',
'content-length': archiveData.length
}
});
// Upload checksum
console.log(`Uploading ${checksumName}...`);
const checksumData = fs.readFileSync(checksumName);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
name: checksumName,
data: checksumData,
headers: {
'content-type': 'text/plain',
'content-length': checksumData.length
}
});