diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a121c97 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,78 @@ +name: Release + +env: + PROJECT_NAME: swiss-qr-bill-decoder + CARGO_TERM_COLOR: always + +on: + push: + tags: + # Regex for a version number such as 0.2.1 + - "[0-9]+.[0-9]+.[0-9]+" + +jobs: + build_and_release: + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - name: linux-amd64 + runner: ubuntu-latest + target: x86_64-unknown-linux-gnu + - name: macos-amd64 + runner: macos-latest + target: x86_64-apple-darwin + - name: macos-arm64 + runner: macos-latest + target: aarch64-apple-darwin + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: "${{ matrix.platform.target }}" + + - name: Rust (Cargo) Caching + uses: Swatinem/rust-cache@v2 + + - name: Install ghostscript (for linux) + uses: awalsh128/cache-apt-pkgs-action@latest + if: matrix.platform.runner == 'ubuntu-latest' + with: + packages: ghostscript + version: 1.0 + + - name: Install ghostscript (for macos) + run: brew install ghostscript + if: matrix.platform.runner == 'macos-latest' + + - name: Run tests + run: cargo test --locked --target ${{ matrix.platform.target }} + + - name: Build release + run: cargo build --release--locked --target ${{ matrix.platform.target }} + + - name: Get the release version from the tag + shell: bash + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + - name: Build archive + shell: bash + run: | + # Replace with the name of your binary + binary_name="${{PROJECT_NAME}}" + + dirname="$binary_name-${{ env.VERSION }}-${{ matrix.platform.target }}" + mkdir "$dirname" + mv "target/${{ matrix.platform.target }}/release/$binary_name" "$dirname" + tar -czf "$dirname.tar.gz" "$dirname" + echo "ASSET=$dirname.tar.gz" >> $GITHUB_ENV + + - name: Upload the binaries + uses: softprops/action-gh-release@v1 + with: + files: | + ${{ env.ASSET }} \ No newline at end of file