Update GitHub Actions workflow for release process #7
This file contains hidden or 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: Flash CLI CI + Conditional Release | |
| permissions: | |
| contents: write # REQUIRED to create GitHub releases | |
| on: | |
| push: | |
| branches: ["main"] | |
| pull_request: | |
| jobs: | |
| # ------------------------------ | |
| # 1. CI JOB (Runs on PR + Push) | |
| # ------------------------------ | |
| ci: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| build-essential \ | |
| clang \ | |
| curl \ | |
| libcurl4-openssl-dev | |
| - name: Build C Project | |
| run: gcc Flash-cli.c -o flash-linux-x64 -lcurl | |
| - name: Run Tests | |
| run: | | |
| if [ -d "tests" ]; then | |
| for f in tests/*.sh; do | |
| bash "$f" | |
| done | |
| else | |
| echo "No tests directory" | |
| fi | |
| # ------------------------------------------------------- | |
| # 2. RELEASE JOB (Only on push to main) | |
| # ------------------------------------------------------- | |
| release: | |
| needs: ci | |
| if: github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| build-essential \ | |
| clang \ | |
| curl \ | |
| libcurl4-openssl-dev | |
| # Detect if version.h changed | |
| - name: Check if version file changed | |
| id: check_version | |
| run: | | |
| git fetch origin main --depth=2 | |
| if git diff --name-only HEAD^ HEAD | grep -q "lib/version.h"; then | |
| echo "changed=true" >> $GITHUB_ENV | |
| else | |
| echo "changed=false" >> $GITHUB_ENV | |
| fi | |
| - name: Stop if version did not change | |
| if: env.changed == 'false' | |
| run: | | |
| echo "version.h not changed → skipping release" | |
| exit 0 | |
| # Extract version text | |
| - name: Extract version from version.h | |
| run: | | |
| VERSION=$(grep "RELEASE_VERSION" lib/version.h | cut -d '"' -f2) | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| # Build final binary | |
| - name: Build Linux binary | |
| run: gcc Flash-cli.c -o flash-linux-x64 -lcurl | |
| # Determine release title | |
| - name: Decide Release Title | |
| run: | | |
| echo "TITLE=${{ github.event.head_commit.message }}" >> $GITHUB_ENV | |
| # Create GitHub Release | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: "${{ env.TITLE }} (v${{ env.VERSION }})" | |
| tag_name: "v${{ env.VERSION }}" | |
| files: flash-linux-x64 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |