Build and Release #21
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-window-latest.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.'); | |
} | |
// Remove any surrounding quotes from the tag name | |
const tagName = releases.data[0].tag_name.replace(/^["'](.+(?=["']$))["']$/, '$1'); | |
console.log(`Latest release tag: ${tagName}`); | |
return tagName; | |
- name: Upload Assets to Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: | | |
dist/bundlerepo-ubuntu-latest.tar.gz | |
dist/bundlerepo-macos-latest.tar.gz | |
dist/bundlerepo.exe-window-latest.zip | |
tag_name: | |
${{ steps.get_release.outputs.result || | |
github.event.release.tag_name }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }} |