From b6dee8e7c87a31c4f11eb3068569303361b5205c Mon Sep 17 00:00:00 2001
From: Andrea Ricchi <17642033+AndreaRicchi@users.noreply.github.com>
Date: Wed, 15 Nov 2023 16:22:24 +0100
Subject: [PATCH] Update GitHub action pipelines

Renamed Rust pipeline to Build and added Publish Release pipeline to
automatically publish binaries to GitHub release pages.
---
 .github/workflows/build.yml           | 23 ++++++++++
 .github/workflows/publish_release.yml | 62 +++++++++++++++++++++++++++
 .github/workflows/rust.yml            | 24 -----------
 Cargo.toml                            |  2 +-
 README.md                             |  2 +-
 5 files changed, 87 insertions(+), 26 deletions(-)
 create mode 100644 .github/workflows/build.yml
 create mode 100644 .github/workflows/publish_release.yml
 delete mode 100644 .github/workflows/rust.yml

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..bdf63ad
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,23 @@
+name: Build
+
+on:
+  push:
+    branches: ["master"]
+  pull_request:
+    branches: ["master"]
+
+env:
+  CARGO_TERM_COLOR: always
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v4
+      - name: Build
+        run: cargo build --verbose
+      - name: Run tests
+        run: cargo test --verbose
+      - name: Run Clippy
+        run: cargo clippy -- -D warnings
diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml
new file mode 100644
index 0000000..43b01bd
--- /dev/null
+++ b/.github/workflows/publish_release.yml
@@ -0,0 +1,62 @@
+name: Publish Release
+
+on:
+  push:
+    tags:
+      - "*"
+
+jobs:
+  rustfmt:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+      - run: rustup component add rustfmt
+      - run: cargo fmt -- --check
+
+  build-linux:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+
+      - name: Build for Linux
+        run: cargo build --all --release && strip target/release/ftu
+
+      - name: Set env
+        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
+
+      - name: Upload binaries to release
+        uses: svenstaro/upload-release-action@2.7.0
+        with:
+          repo_token: ${{ secrets.GITHUB_TOKEN }}
+          file: target/release/ftu
+          asset_name: ftu-x86_64-apple-darwin
+          tag: ${{ github.ref }}
+          release_name: ${{ env.RELEASE_VERSION }}
+          body: "FTU release ${{ env.RELEASE_VERSION }}"
+          overwrite: true
+
+  build-mac:
+    runs-on: macos-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+
+      - name: Build for Mac
+        run: cargo build --all --release && strip target/release/ftu
+
+      - name: Set env
+        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
+
+      - name: Upload binaries to release
+        uses: svenstaro/upload-release-action@2.7.0
+        with:
+          repo_token: ${{ secrets.GITHUB_TOKEN }}
+          file: target/release/ftu
+          asset_name: ftu-x86_64-apple-darwin
+          tag: ${{ github.ref }}
+          release_name: ${{ env.RELEASE_VERSION }}
+          body: "FTU release ${{ env.RELEASE_VERSION }}"
+          overwrite: true
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
deleted file mode 100644
index 00b6dec..0000000
--- a/.github/workflows/rust.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-name: Rust
-
-on:
-  push:
-    branches: [ "master" ]
-  pull_request:
-    branches: [ "master" ]
-
-env:
-  CARGO_TERM_COLOR: always
-
-jobs:
-  build:
-
-    runs-on: ubuntu-latest
-
-    steps:
-    - uses: actions/checkout@v3
-    - name: Build
-      run: cargo build --verbose
-    - name: Run tests
-      run: cargo test --verbose
-    - name: Run Clippy
-      run: cargo clippy -- -D warnings
diff --git a/Cargo.toml b/Cargo.toml
index b7b51af..2dc3364 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "ftu"
-version = "0.1.0"
+version = "1.0.1"
 edition = "2021"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
diff --git a/README.md b/README.md
index 25d3191..e08615d 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-[![Rust](https://github.com/amarula/ftu/actions/workflows/rust.yml/badge.svg)](https://github.com/amarula/ftu/actions/workflows/rust.yml)
+[![Build](https://github.com/amarula/ftu/actions/workflows/build.yml/badge.svg)](https://github.com/amarula/ftu/actions/workflows/build.yml)
 [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
 
 # ftu - Flutter Translation Utility