From 818657d960b6b046542f3742324bd64ed01f56f4 Mon Sep 17 00:00:00 2001 From: Marc <74199970+Marc55s@users.noreply.github.com> Date: Fri, 24 Oct 2025 22:46:51 +0200 Subject: [PATCH 1/5] Update Rust workflow for multi-platform release This workflow builds and releases a Rust project on git tag pushes, with support for multiple platforms. --- .github/workflows/rust.yml | 123 +++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..60bdb4b --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,123 @@ +# This workflow builds and releases your Rust project when you push a git tag +# that starts with 'v' (e.g., v1.0.0, v0.2.1). +# +# 1. Place this file in your repository at .github/workflows/release.yml +# 2. !! IMPORTANT !! +# Change the `BINARY_NAME` env variable below to match your binary's name +# (which is usually the 'name' field in your Cargo.toml). +# +name: Rust Release + +on: + push: + tags: + - 'v*' # Trigger workflow on tags starting with 'v' + +# Set a default environment variable for your binary name. +# !! CHANGE THIS TO YOUR BINARY'S NAME !! +env: + BINARY_NAME: your-binary-name-here + +jobs: + # Job to build the binaries for different platforms + build-and-release: + name: Build & Release + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + # Linux (GNU) + - platform: linux-x86_64 + os: ubuntu-latest + target: x86_64-unknown-linux-gnu + # macOS (x86_64) + - platform: macos-x86_64 + os: macos-latest + target: x86_64-apple-darwin + # macOS (Apple Silicon) + - platform: macos-aarch64 + os: macos-latest + target: aarch64-apple-darwin + # Windows (MSVC) + - platform: windows-x86_64 + os: windows-latest + target: x86_64-pc-windows-msvc + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + targets: ${{ matrix.target }} + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + + - name: Build binary + run: cargo build --release --target ${{ matrix.target }} + + - name: Prepare asset names and paths + # This step creates environment variables for the asset name and binary path + # based on the runner's operating system. + shell: bash + run: | + if [ "${{ runner.os }}" == "Windows" ]; then + # Windows uses .exe and .zip + echo "ASSET_NAME=${{ env.BINARY_NAME }}-${{ matrix.platform }}.zip" >> $GITHUB_ENV + echo "BINARY_PATH=target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe" >> $GITHUB_ENV + else + # Linux and macOS use .tar.gz + echo "ASSET_NAME=${{ env.BINARY_NAME }}-${{ matrix.platform }}.tar.gz" >> $GITHUB_ENV + echo "BINARY_PATH=target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}" >> $GITHUB_ENV + fi + + - name: Package asset (Windows) + if: runner.os == 'Windows' + # Use PowerShell to create a .zip archive + shell: powershell + run: Compress-Archive -Path ${{ env.BINARY_PATH }} -DestinationPath ${{ env.ASSET_NAME }} + + - name: Package asset (Linux/macOS) + if: runner.os != 'Windows' + # Use tar to create a .tar.gz archive + # -C changes directory to the binary's parent folder to avoid including the full path + run: tar -czvf ${{ env.ASSET_NAME }} -C $(dirname ${{ env.BINARY_PATH }}) $(basename ${{ env.BINARY_PATH }}) + + - name: Upload asset for release + # This uploads the packaged asset (zip/tar.gz) so the next job can use it + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.platform }}-asset # Unique name for each artifact + path: ${{ env.ASSET_NAME }} + retention-days: 1 # We only need it for the next job + + # Job to create the GitHub Release and upload all assets + create-release: + name: Create GitHub Release + runs-on: ubuntu-latest + needs: build-and-release # Wait for all builds to finish + permissions: + contents: write # Required to create a release + + steps: + - name: Download all build artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts/ # Download all artifacts into an 'artifacts' directory + + - name: Create GitHub Release + # This action uses the GITHUB_TOKEN to create a release. + # It automatically finds the tag that triggered the workflow. + uses: softprops/action-gh-release@v2 + with: + # Use a glob pattern to find all asset files downloaded in the previous step + files: artifacts/*/* + + # Automatically generate release notes from commits since the last tag + generate_release_notes: true + + # Set the release name to be the same as the tag + name: ${{ github.ref_name }} From e7f30a24bb4bdfbe435ec0be9258510928e9255c Mon Sep 17 00:00:00 2001 From: Marc <74199970+Marc55s@users.noreply.github.com> Date: Fri, 24 Oct 2025 22:56:30 +0200 Subject: [PATCH 2/5] Update Rust workflow for Linux x86_64 only --- .github/workflows/rust.yml | 67 ++++++++++---------------------------- 1 file changed, 17 insertions(+), 50 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 60bdb4b..547857a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,12 +1,12 @@ -# This workflow builds and releases your Rust project when you push a git tag -# that starts with 'v' (e.g., v1.0.0, v0.2.1). +# This workflow builds and releases your Rust project for Linux x86_64 +# when you push a git tag that starts with 'v' (e.g., v1.0.0, v0.2.1). # # 1. Place this file in your repository at .github/workflows/release.yml # 2. !! IMPORTANT !! # Change the `BINARY_NAME` env variable below to match your binary's name # (which is usually the 'name' field in your Cargo.toml). # -name: Rust Release +name: Rust Release (Linux x86_64) on: push: @@ -16,33 +16,14 @@ on: # Set a default environment variable for your binary name. # !! CHANGE THIS TO YOUR BINARY'S NAME !! env: - BINARY_NAME: your-binary-name-here + BINARY_NAME: termstat jobs: - # Job to build the binaries for different platforms + # Job to build the binary for Linux x86_64 build-and-release: - name: Build & Release - runs-on: ${{ matrix.os }} - strategy: - matrix: - include: - # Linux (GNU) - - platform: linux-x86_64 - os: ubuntu-latest - target: x86_64-unknown-linux-gnu - # macOS (x86_64) - - platform: macos-x86_64 - os: macos-latest - target: x86_64-apple-darwin - # macOS (Apple Silicon) - - platform: macos-aarch64 - os: macos-latest - target: aarch64-apple-darwin - # Windows (MSVC) - - platform: windows-x86_64 - os: windows-latest - target: x86_64-pc-windows-msvc - + name: Build & Release (Linux x86_64) + runs-on: ubuntu-latest # Hardcode for Linux + steps: - name: Checkout repository uses: actions/checkout@v4 @@ -51,46 +32,31 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: stable - targets: ${{ matrix.target }} + targets: x86_64-unknown-linux-gnu # Hardcode target - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 - name: Build binary - run: cargo build --release --target ${{ matrix.target }} + run: cargo build --release --target x86_64-unknown-linux-gnu # Hardcode target - name: Prepare asset names and paths # This step creates environment variables for the asset name and binary path - # based on the runner's operating system. shell: bash run: | - if [ "${{ runner.os }}" == "Windows" ]; then - # Windows uses .exe and .zip - echo "ASSET_NAME=${{ env.BINARY_NAME }}-${{ matrix.platform }}.zip" >> $GITHUB_ENV - echo "BINARY_PATH=target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe" >> $GITHUB_ENV - else - # Linux and macOS use .tar.gz - echo "ASSET_NAME=${{ env.BINARY_NAME }}-${{ matrix.platform }}.tar.gz" >> $GITHUB_ENV - echo "BINARY_PATH=target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}" >> $GITHUB_ENV - fi + echo "ASSET_NAME=${{ env.BINARY_NAME }}-linux-x86_64.tar.gz" >> $GITHUB_ENV + echo "BINARY_PATH=target/x86_64-unknown-linux-gnu/release/${{ env.BINARY_NAME }}" >> $GITHUB_ENV - - name: Package asset (Windows) - if: runner.os == 'Windows' - # Use PowerShell to create a .zip archive - shell: powershell - run: Compress-Archive -Path ${{ env.BINARY_PATH }} -DestinationPath ${{ env.ASSET_NAME }} - - - name: Package asset (Linux/macOS) - if: runner.os != 'Windows' + - name: Package asset (Linux) # Use tar to create a .tar.gz archive # -C changes directory to the binary's parent folder to avoid including the full path run: tar -czvf ${{ env.ASSET_NAME }} -C $(dirname ${{ env.BINARY_PATH }}) $(basename ${{ env.BINARY_PATH }}) - name: Upload asset for release - # This uploads the packaged asset (zip/tar.gz) so the next job can use it + # This uploads the packaged asset (tar.gz) so the next job can use it uses: actions/upload-artifact@v4 with: - name: ${{ matrix.platform }}-asset # Unique name for each artifact + name: linux-x86_64-asset # Hardcoded artifact name path: ${{ env.ASSET_NAME }} retention-days: 1 # We only need it for the next job @@ -98,7 +64,7 @@ jobs: create-release: name: Create GitHub Release runs-on: ubuntu-latest - needs: build-and-release # Wait for all builds to finish + needs: build-and-release # Wait for the build to finish permissions: contents: write # Required to create a release @@ -121,3 +87,4 @@ jobs: # Set the release name to be the same as the tag name: ${{ github.ref_name }} + From 3ec2a3eabae0832b6a4256c5d1ec0950903f3e33 Mon Sep 17 00:00:00 2001 From: Marc <74199970+Marc55s@users.noreply.github.com> Date: Fri, 24 Oct 2025 23:01:17 +0200 Subject: [PATCH 3/5] Modify binary name and set build job limits Updated the binary name placeholder and limited parallel build jobs. --- .github/workflows/rust.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 547857a..7a8b598 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,13 +16,18 @@ on: # Set a default environment variable for your binary name. # !! CHANGE THIS TO YOUR BINARY'S NAME !! env: - BINARY_NAME: termstat + BINARY_NAME: your-binary-name-here jobs: # Job to build the binary for Linux x86_64 build-and-release: name: Build & Release (Linux x86_64) runs-on: ubuntu-latest # Hardcode for Linux + env: + # Limit the number of parallel build jobs to 2. + # This can prevent "Operation was canceled" errors, which are + # often caused by the runner running out of memory (OOMKilled). + CARGO_BUILD_JOBS: 2 steps: - name: Checkout repository @@ -87,4 +92,3 @@ jobs: # Set the release name to be the same as the tag name: ${{ github.ref_name }} - From a124a802c90b91b12b67b2454cf2ae22dbaf8a7f Mon Sep 17 00:00:00 2001 From: Marc <74199970+Marc55s@users.noreply.github.com> Date: Fri, 24 Oct 2025 23:04:06 +0200 Subject: [PATCH 4/5] Update BINARY_NAME in rust.yml workflow --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7a8b598..19bee29 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,7 +16,7 @@ on: # Set a default environment variable for your binary name. # !! CHANGE THIS TO YOUR BINARY'S NAME !! env: - BINARY_NAME: your-binary-name-here + BINARY_NAME: termstat jobs: # Job to build the binary for Linux x86_64 From 1b5b2cb45f16da9b3e82ce01e21937a95d5c4bc6 Mon Sep 17 00:00:00 2001 From: Marc <74199970+Marc55s@users.noreply.github.com> Date: Fri, 24 Oct 2025 23:20:03 +0200 Subject: [PATCH 5/5] Refactor Rust release workflow for clarity Updated workflow to specify project name and improve comments. --- .github/workflows/rust.yml | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 19bee29..e6fa81b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,20 +1,25 @@ -# This workflow builds and releases your Rust project for Linux x86_64 -# when you push a git tag that starts with 'v' (e.g., v1.0.0, v0.2.1). +# This workflow builds and releases your Rust project 'termstat' # -# 1. Place this file in your repository at .github/workflows/release.yml -# 2. !! IMPORTANT !! -# Change the `BINARY_NAME` env variable below to match your binary's name -# (which is usually the 'name' field in your Cargo.toml). +# HOW IT WORKS: +# 1. TEST BUILDS: +# On pushes to the 'github-release-action' branch, this workflow will ONLY +# run the 'build-and-release' job. This lets you check for compilation +# errors without creating a fake release. # -name: Rust Release (Linux x86_64) +# 2. REAL RELEASES: +# On pushes of tags starting with 'v*' (e.g., v1.0.0), this workflow +# will run BOTH jobs, creating a new GitHub Release with your binary. +# +name: Rust Release (termstat) on: push: tags: - - 'v*' # Trigger workflow on tags starting with 'v' + - 'v*' # Trigger on tags for actual releases + branches: + - 'github-release-action' # Trigger on pushes to this branch for testing -# Set a default environment variable for your binary name. -# !! CHANGE THIS TO YOUR BINARY'S NAME !! +# Set the binary name env: BINARY_NAME: termstat @@ -24,9 +29,7 @@ jobs: name: Build & Release (Linux x86_64) runs-on: ubuntu-latest # Hardcode for Linux env: - # Limit the number of parallel build jobs to 2. - # This can prevent "Operation was canceled" errors, which are - # often caused by the runner running out of memory (OOMKilled). + # Limit parallel build jobs to prevent out-of-memory errors CARGO_BUILD_JOBS: 2 steps: @@ -70,6 +73,12 @@ jobs: name: Create GitHub Release runs-on: ubuntu-latest needs: build-and-release # Wait for the build to finish + + # !! CRITICAL !! + # This 'if' condition ensures this job ONLY runs for tags, + # not on pushes to your testing branch. + if: startsWith(github.ref, 'refs/tags/') + permissions: contents: write # Required to create a release @@ -92,3 +101,4 @@ jobs: # Set the release name to be the same as the tag name: ${{ github.ref_name }} +