Skip to content

Build and Release

Build and Release #14

Workflow file for this run

name: Build and Release
on:
release:
types: [created]
workflow_dispatch:
jobs:
build:
name: Build Binaries
runs-on: ubuntu-latest
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
- name: Build the project
run: cargo build --release
# - name: Check release directory contents
# if: matrix.platform == 'windows-latest'
# shell: pwsh
# run: Get-ChildItem -Path target/release
- name: Rename the binary to .exe (Windows)
if: matrix.platform == 'windows-latest'
shell: pwsh
run: |
Rename-Item -Path target/release/bundlerepo -NewName bundlerepo.exe
Get-ChildItem -Path target/release
- name: Package the binary (Linux/macOS)
if: matrix.platform != 'windows-latest'
run: |
BINARY_NAME="bundlerepo"
mkdir -p binaries
tar -czvf binaries/${BINARY_NAME}-${{ matrix.platform }}.tar.gz -C target/release ${BINARY_NAME}
- name: Package the binary (Windows)
if: matrix.platform == 'windows-latest'
shell: pwsh
run: |
$BINARY_NAME = "bundlerepo.exe"
New-Item -ItemType Directory -Path binaries -Force
Compress-Archive -Path target/release/$BINARY_NAME -DestinationPath binaries\$BINARY_NAME.zip
- name: Upload Binaries
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-binaries
path: binaries/
release:
name: Release Artifacts
needs: build
runs-on: ubuntu-latest
steps:
- name: Download Binaries
uses: actions/download-artifact@v4
with:
name: ubuntu-latest-binaries
path: ./dist
- name: Download macOS Binaries
uses: actions/download-artifact@v4
with:
name: macos-latest-binaries
path: ./dist
- name: Download Windows Binaries
uses: actions/download-artifact@v4
with:
name: windows-latest-binaries
path: ./dist
- name: Get latest release tag
id: get_release
uses: actions/github-script@v7
with:
script: |
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});
if (releases.data.length === 0) {
throw new Error('No releases found in the repository.');
}
return releases.data[0].tag_name;
# - name: Delete existing release assets
# id: delete_assets
# uses: actions/github-script@v6
# with:
# script: |
# const release = await github.repos.getReleaseByTag({
# owner: context.repo.owner,
# repo: context.repo.repo,
# tag: "${{ steps.get_release.outputs.result || github.event.release.tag_name }}"
# });
# for (const asset of release.data.assets) {
# await github.repos.deleteReleaseAsset({
# owner: context.repo.owner,
# repo: context.repo.repo,
# asset_id: asset.id
# });
# }
- name: Upload Assets to Release
uses: softprops/action-gh-release@v2
with:
files: dist/*
tag_name:
${{ steps.get_release.outputs.result ||
github.event.release.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}