Skip to content

Commit

Permalink
Remove caching from build workflow and add publish workflow
Browse files Browse the repository at this point in the history
The caching step in the build workflow for GitHub Actions has been removed. Additionally, a new publish workflow has been introduced. This workflow will automatically build the application and upload the compiled binaries every time a new version tag is pushed, targeting Linux, MacOS, and Windows platforms.
  • Loading branch information
rayyildiz committed Mar 22, 2024
1 parent 4bc8dee commit 8355578
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 11 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/build.yaml
Expand Up @@ -22,17 +22,6 @@ jobs:

- run: rustup default nightly

- uses: actions/cache@v4
with:
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin
~/.cargo/registry/index
~/.cargo/registry/cache
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- run: cargo test

- run: cargo build
79 changes: 79 additions & 0 deletions .github/workflows/publish.yaml
@@ -0,0 +1,79 @@
name: Publish

on:
push:
tags:
- "v*.*.*"

env:
CARGO_TERM_COLOR: always

jobs:

build-and-upload:
name: Build and upload
runs-on: ${{ matrix.os }}
timeout-minutes: 20

strategy:
matrix:
include:
- build: linux
os: ubuntu-latest
target: x86_64-unknown-linux-musl

- build: macos
os: macos-latest
target: x86_64-apple-darwin

- build: windows-gnu
os: windows-latest
target: x86_64-pc-windows-gnu

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Get the release version from the tag
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- name: Build
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --release --target ${{ matrix.target }}

- name: Build archive
shell: bash
run: |
# Replace with the name of your binary
binary_name="cc2p"
dirname="$binary_name-${{ env.VERSION }}-${{ matrix.target }}"
mkdir "$dirname"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
mv "target/${{ matrix.target }}/release/$binary_name.exe" "$dirname"
else
mv "target/${{ matrix.target }}/release/$binary_name" "$dirname"
fi
if [ "${{ matrix.os }}" = "windows-latest" ]; then
7z a "$dirname.zip" "$dirname"
echo "ASSET=$dirname.zip" >> $GITHUB_ENV
else
tar -czf "$dirname.tar.gz" "$dirname"
echo "ASSET=$dirname.tar.gz" >> $GITHUB_ENV
fi
- name: Upload the binaries
uses: softprops/action-gh-release@v2
with:
files: |
${{ env.ASSET }}

0 comments on commit 8355578

Please sign in to comment.