Added CI #1
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: Release | ||
| on: | ||
| push: | ||
| tags: | ||
| - "v*" | ||
| permissions: | ||
| contents: write | ||
| concurrency: | ||
| group: release-${{ github.ref }} | ||
| cancel-in-progress: false | ||
| jobs: | ||
| prepare: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| version: ${{ steps.version.outputs.version }} | ||
| tag: ${{ steps.version.outputs.tag }} | ||
| prerelease: ${{ steps.version.outputs.prerelease }} | ||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v4 | ||
| - name: Read Cargo version and validate tag | ||
| id: version | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| version="$( | ||
| cargo metadata --no-deps --format-version 1 | python -c ' | ||
| import json | ||
| import sys | ||
| data = json.load(sys.stdin) | ||
| for package in data["packages"]: | ||
| if package["name"] == "src_tauri": | ||
| print(package["version"]) | ||
| break | ||
| else: | ||
| raise SystemExit("src_tauri package not found") | ||
| ' | ||
| )" | ||
| tag="${GITHUB_REF_NAME}" | ||
| expected_tag="v${version}" | ||
| if [[ "${tag}" != "${expected_tag}" ]]; then | ||
| echo "Tag ${tag} does not match src-tauri version ${version}" >&2 | ||
| exit 1 | ||
| fi | ||
| if [[ "${version}" == *-* ]]; then | ||
| prerelease=true | ||
| else | ||
| prerelease=false | ||
| fi | ||
| echo "version=${version}" >> "${GITHUB_OUTPUT}" | ||
| echo "tag=${tag}" >> "${GITHUB_OUTPUT}" | ||
| echo "prerelease=${prerelease}" >> "${GITHUB_OUTPUT}" | ||
| build: | ||
| needs: prepare | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - runner: ubuntu-24.04 | ||
| target: x86_64-unknown-linux-gnu | ||
| os_name: linux | ||
| arch: x86_64 | ||
| bundles: appimage,deb,rpm | ||
| artifact_name: linux-x86_64 | ||
| - runner: ubuntu-24.04-arm | ||
| target: aarch64-unknown-linux-gnu | ||
| os_name: linux | ||
| arch: arm64 | ||
| bundles: appimage,deb,rpm | ||
| artifact_name: linux-arm64 | ||
| - runner: macos-15-intel | ||
| target: x86_64-apple-darwin | ||
| os_name: macos | ||
| arch: x86_64 | ||
| bundles: dmg | ||
| artifact_name: macos-x86_64 | ||
| - runner: macos-15 | ||
| target: aarch64-apple-darwin | ||
| os_name: macos | ||
| arch: arm64 | ||
| bundles: dmg | ||
| artifact_name: macos-arm64 | ||
| - runner: windows-2025 | ||
| target: x86_64-pc-windows-msvc | ||
| os_name: windows | ||
| arch: x86_64 | ||
| bundles: msi | ||
| artifact_name: windows-x86_64 | ||
| - runner: windows-11-arm | ||
| target: aarch64-pc-windows-msvc | ||
| os_name: windows | ||
| arch: arm64 | ||
| bundles: msi | ||
| artifact_name: windows-arm64 | ||
| runs-on: ${{ matrix.runner }} | ||
| env: | ||
| CARGO_TERM_COLOR: always | ||
| NO_COLOR: "false" | ||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v4 | ||
| - name: Add cargo bin directory to PATH | ||
| shell: bash | ||
| run: echo "${HOME}/.cargo/bin" >> "${GITHUB_PATH}" | ||
| - name: Install Rust toolchain | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| rustup toolchain install stable --profile minimal | ||
| rustup default stable | ||
| rustup target add wasm32-unknown-unknown "${{ matrix.target }}" | ||
| - name: Install Linux build dependencies | ||
| if: startsWith(matrix.runner, 'ubuntu-') | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| sudo apt-get update | ||
| sudo apt-get install -y \ | ||
| libwebkit2gtk-4.1-dev \ | ||
| libgtk-3-dev \ | ||
| libayatana-appindicator3-dev \ | ||
| librsvg2-dev \ | ||
| patchelf \ | ||
| pkg-config \ | ||
| libssl-dev \ | ||
| libfuse2t64 \ | ||
| rpm | ||
| - name: Install release toolchain | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| cargo install tauri-cli --version 2.10.1 --locked | ||
| cargo install trunk --version 0.21.14 --locked | ||
| cargo install wasm-bindgen-cli --version 0.2.114 --locked | ||
| - name: Build release bundles | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| cargo tauri build --ci --no-sign --bundles "${{ matrix.bundles }}" --target "${{ matrix.target }}" | ||
| - name: Stage release artifacts | ||
| shell: bash | ||
| env: | ||
| VERSION: ${{ needs.prepare.outputs.version }} | ||
| OS_NAME: ${{ matrix.os_name }} | ||
| ARCH: ${{ matrix.arch }} | ||
| TARGET: ${{ matrix.target }} | ||
| run: | | ||
| set -euo pipefail | ||
| bundle_dir="target/${TARGET}/release/bundle" | ||
| stage_dir="ci-dist" | ||
| mkdir -p "${stage_dir}" | ||
| case "${OS_NAME}" in | ||
| linux) | ||
| cp "${bundle_dir}/appimage/"*.AppImage "${stage_dir}/WriterMD_${VERSION}_${OS_NAME}_${ARCH}.AppImage" | ||
| cp "${bundle_dir}/deb/"*.deb "${stage_dir}/WriterMD_${VERSION}_${OS_NAME}_${ARCH}.deb" | ||
| cp "${bundle_dir}/rpm/"*.rpm "${stage_dir}/WriterMD_${VERSION}_${OS_NAME}_${ARCH}.rpm" | ||
| ;; | ||
| macos) | ||
| cp "${bundle_dir}/dmg/"*.dmg "${stage_dir}/WriterMD_${VERSION}_${OS_NAME}_${ARCH}.dmg" | ||
| ;; | ||
| windows) | ||
| cp "${bundle_dir}/msi/"*.msi "${stage_dir}/WriterMD_${VERSION}_${OS_NAME}_${ARCH}.msi" | ||
| ;; | ||
| *) | ||
| echo "Unsupported OS ${OS_NAME}" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| - name: Upload staged artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: ${{ matrix.artifact_name }} | ||
| path: ci-dist/* | ||
| if-no-files-found: error | ||
| publish: | ||
| needs: | ||
| - prepare | ||
| - build | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| VERSION: ${{ needs.prepare.outputs.version }} | ||
| TAG: ${{ needs.prepare.outputs.tag }} | ||
| PRERELEASE: ${{ needs.prepare.outputs.prerelease }} | ||
| steps: | ||
| - name: Download staged artifacts | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| path: dist | ||
| merge-multiple: true | ||
| - name: Create or update GitHub Release | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| shopt -s nullglob | ||
| files=(dist/*) | ||
| if [[ ${#files[@]} -eq 0 ]]; then | ||
| echo "No release files found" >&2 | ||
| exit 1 | ||
| fi | ||
| if gh release view "${TAG}" >/dev/null 2>&1; then | ||
| gh release upload "${TAG}" "${files[@]}" --clobber | ||
| else | ||
| prerelease_flag=() | ||
| if [[ "${PRERELEASE}" == "true" ]]; then | ||
| prerelease_flag+=(--prerelease) | ||
| fi | ||
| gh release create "${TAG}" "${files[@]}" \ | ||
| --title "WriterMD v${VERSION}" \ | ||
| --generate-notes \ | ||
| "${prerelease_flag[@]}" | ||
| fi | ||