Skip to content

Publishing CI builds #52

Publishing CI builds

Publishing CI builds #52

Workflow file for this run

on: [push, pull_request, workflow_dispatch]
name: Release
jobs:
bin_commit:
name: Get BIN COMMIT
runs-on: ubuntu-latest
outputs:
bin_commit: ${{ steps.set_env.outputs.bin_commit }} # Declare output variable
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set Environment Variable
id: set_env # ID used to reference output
run: echo "::set-output name=bin_commit::$(git rev-parse --short HEAD)"
create_release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
needs: bin_commit # Ensure this job runs after bin_commit
steps:
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.bin_commit.outputs.bin_commit }}
release_name: Release ${{ needs.bin_commit.outputs.bin_commit }}
draft: true
prerelease: true
- name: Set Upload URL Output
run: echo "::set-output name=upload_url::$(echo ${{ steps.create_release.outputs.upload_url }})"
build:
name: Build
env:
# The project name specified in your Cargo.toml
PROJECT_NAME: aderyn
# Set the job to run on the platform specified by the matrix below
runs-on: ${{ matrix.runner }}
needs: create_release # Ensure this job runs after create_release
# Define the build matrix for cross-compilation
strategy:
matrix:
include:
- name: linux-amd64
runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
- name: win-amd64
runner: windows-latest
target: x86_64-pc-windows-msvc
- name: macos-amd64
runner: macos-latest
target: x86_64-apple-darwin
- name: macos-arm64
runner: macos-latest
target: aarch64-apple-darwin
# The steps to run for each matrix item
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: "${{ matrix.target }}"
- name: Setup Cache
uses: Swatinem/rust-cache@v2
- name: Build Binary
run: cargo build --verbose --locked --release --target ${{ matrix.target }}
- name: Create Binary
shell: bash
run: |
BIN_SUFFIX=""
if [[ "${{ matrix.runner }}" == "windows-latest" ]]; then
BIN_SUFFIX=".exe"
fi
# The built binary output location
BIN_OUTPUT="target/${{ matrix.target }}/release/${PROJECT_NAME}${BIN_SUFFIX}"
# Define a better name for the final binary
echo "BIN_COMMIT: ${{ needs.bin_commit.outputs.bin_commit }}"
echo "PROJECT_NAME: $PROJECT_NAME"
echo "BIN_SUFFIX: $BIN_SUFFIX"
BIN_RELEASE_VERSIONED="${PROJECT_NAME}-${{ matrix.name }}-${{ needs.bin_commit.outputs.bin_commit }}${BIN_SUFFIX}"
echo "BIN_RELEASE_VERSIONED: $BIN_RELEASE_VERSIONED"
# Move the built binary where you want it
ls -la
mv "${BIN_OUTPUT}" "./${BIN_RELEASE_VERSIONED}"
# Export BIN_RELEASE to GITHUB_ENV
echo "BIN_RELEASE_VERSIONED=${BIN_RELEASE_VERSIONED}" >> $GITHUB_ENV
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.BIN_RELEASE_VERSIONED }}
path: ${{ env.BIN_RELEASE_VERSIONED }}
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ${{ env.BIN_RELEASE_VERSIONED }}
asset_name: ${{ env.BIN_RELEASE_VERSIONED }}
asset_content_type: application/octet-stream