Build and Release #10
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@v3 | |
- 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@v3 | |
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@v3 | |
with: | |
name: ubuntu-latest-binaries | |
path: ./dist | |
- name: Download macOS Binaries | |
uses: actions/download-artifact@v3 | |
with: | |
name: macos-latest-binaries | |
path: ./dist | |
- name: Download Windows Binaries | |
uses: actions/download-artifact@v3 | |
with: | |
name: windows-latest-binaries | |
path: ./dist | |
- name: Get release information | |
id: get_release | |
if: github.event_name == 'workflow_dispatch' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const latestRelease = await github.repos.getLatestRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
return latestRelease.data.tag_name; | |
result-encoding: string | |
- 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@v1 | |
with: | |
files: dist/* | |
tag_name: | |
${{ steps.get_release.outputs.result || | |
github.event.release.tag_name }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |