Skip to content

Commit

Permalink
feat(workflow): add version check and conditional release
Browse files Browse the repository at this point in the history
- Added a version check job to determine if the version in Cargo.toml has changed.
- Modified the build and release jobs to run conditionally based on the version change.
- Updated paths for downloading artifacts in the release job.
  • Loading branch information
thelezend committed Sep 15, 2024
1 parent 95f4118 commit 72b86be
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 47 deletions.
47 changes: 41 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
name: Release

on: workflow_dispatch
on:
workflow_dispatch:
push:
paths:
- "Cargo.toml"

jobs:
check_version:
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.version_check.outputs.version_changed }}
version: ${{ steps.version_check.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Check if version changed
id: version_check
run: |
PREV_VERSION=$(git show HEAD~1:Cargo.toml | grep '^version =' | awk -F\" '{print $2}')
CURR_VERSION=$(grep '^version =' Cargo.toml | awk -F\" '{print $2}')
echo "Previous version: $PREV_VERSION"
echo "Current version: $CURR_VERSION"
echo "version=$CURR_VERSION" >> $GITHUB_OUTPUT
if [ "$PREV_VERSION" != "$CURR_VERSION" ]; then
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "version_changed=false" >> $GITHUB_OUTPUT
fi
build:
needs: check_version
if: needs.check_version.outputs.version_changed == 'true'
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -23,31 +54,35 @@ jobs:
target/release/solana-copy-trade-detect${{ matrix.os == 'windows-latest' && '.exe' || '' }}
release:
needs: build
needs: [check_version, build]
if: needs.check_version.outputs.version_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Download Ubuntu build
uses: actions/download-artifact@v4
with:
name: release-build-ubuntu-latest
path: solana-copy-trade-detect-linux

- name: Download Windows build
uses: actions/download-artifact@v4
with:
name: release-build-windows-latest
path: solana-copy-trade-detect-windows.exe

- name: Download macOS build
uses: actions/download-artifact@v4
with:
name: release-build-macos-latest
path: solana-copy-trade-detect-macos

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: latest
tag_name: v${{ needs.check_version.outputs.version }}
files: |
target/release/solana-copy-trade-detect
target/release/solana-copy-trade-detect.exe
target/release/solana-copy-trade-detect
solana-copy-trade-detect-linux
solana-copy-trade-detect-windows.exe
solana-copy-trade-detect-macos
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41 changes: 0 additions & 41 deletions .github/workflows/test.yml

This file was deleted.

0 comments on commit 72b86be

Please sign in to comment.