-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from seapagan/create-binaries-on-release
- Loading branch information
Showing
1 changed file
with
54 additions
and
90 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,77 @@ | ||
name: Build and Release | ||
|
||
on: | ||
release: | ||
types: [created] | ||
workflow_dispatch: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
jobs: | ||
build: | ||
# disable the job | ||
if: false | ||
name: Build Binaries | ||
runs-on: ${{ matrix.platform }} | ||
|
||
name: Build ${{ matrix.binary_target }} | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
BINARY_NAME: bundle_repo | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: [ubuntu-latest, macos-latest, windows-latest] | ||
include: | ||
- os: ubuntu-latest | ||
binary_target: x86_64-unknown-linux-musl | ||
- os: ubuntu-latest | ||
binary_target: x86_64-unknown-linux-gnu | ||
- os: windows-latest | ||
binary_target: x86_64-pc-windows-msvc | ||
- os: macos-latest | ||
binary_target: x86_64-apple-darwin | ||
- os: macos-latest | ||
binary_target: aarch64-apple-darwin | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
profile: minimal | ||
- name: Install musl tools | ||
if: matrix.binary_target == 'x86_64-unknown-linux-musl' | ||
run: sudo apt-get install -y musl-tools | ||
|
||
- name: Build the project | ||
run: cargo build --release | ||
- name: Install target | ||
run: rustup target add ${{ matrix.binary_target }} | ||
|
||
- 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 | ||
- name: Build binary | ||
run: | | ||
Rename-Item -Path target/release/bundlerepo -NewName bundlerepo.exe | ||
Get-ChildItem -Path target/release | ||
cargo build --release --target ${{ matrix.binary_target }} | ||
- name: Package the binary (Linux/macOS) | ||
if: matrix.platform != 'windows-latest' | ||
- name: Set archive name | ||
id: archive | ||
shell: bash | ||
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 | ||
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then | ||
echo "archive_name=${{ env.BINARY_NAME }}-v${{ github.ref_name }}-${{ matrix.binary_target }}.zip" >> $GITHUB_OUTPUT | ||
else | ||
echo "archive_name=${{ env.BINARY_NAME }}-v${{ github.ref_name }}-${{ matrix.binary_target }}.tar.gz" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Prepare binary (Unix) | ||
if: matrix.os != 'windows-latest' | ||
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: | ||
# disable the job | ||
if: false | ||
name: Release Artifacts | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Download Binaries | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ubuntu-latest-binaries | ||
path: ./dist | ||
cd target/${{ matrix.binary_target }}/release | ||
tar -czf ../../../${{ steps.archive.outputs.archive_name }} ${{ env.BINARY_NAME }} | ||
cd - | ||
- 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 | ||
- name: Prepare binary (Windows) | ||
if: matrix.os == 'windows-latest' | ||
shell: pwsh | ||
run: | | ||
latest_tag=$(gh release list -L 1 --json tagName -q '.[0].tagName') | ||
echo "Latest release tag: $latest_tag" | ||
echo "RELEASE_TAG=$latest_tag" >> $GITHUB_OUTPUT | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
cd target/${{ matrix.binary_target }}/release | ||
$BINARY_NAME = "${{ env.BINARY_NAME }}.exe" | ||
Compress-Archive -Path $BINARY_NAME -DestinationPath ../../../${{ steps.archive.outputs.archive_name }} | ||
cd - | ||
- name: Upload Assets to Release | ||
uses: softprops/action-gh-release@v2 | ||
- name: Upload Release Asset | ||
uses: svenstaro/upload-release-action@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.RELEASE_TAG || | ||
github.event.release.tag_name }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }} | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file: ${{ steps.archive.outputs.archive_name }} | ||
asset_name: ${{ steps.archive.outputs.archive_name }} | ||
tag: ${{ github.ref }} | ||
overwrite: true |