diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e9490a9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,48 @@ +name: CI + +on: + pull_request: + push: + branches: + - main + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rust: + name: Rust (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - ubuntu-24.04-arm + - macos-15 + - windows-latest + - windows-11-arm + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + components: clippy, rustfmt + + - name: Cache Rust + uses: Swatinem/rust-cache@v2 + + - name: Check formatting + run: cargo fmt --all -- --check + + - name: Clippy + run: cargo clippy --all-targets --locked -- -D warnings + + - name: Test + run: cargo test --locked + + - name: Build + run: cargo build --locked diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..dcd43ac --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,131 @@ +name: Release + +on: + push: + tags: + - "v*" + workflow_dispatch: + inputs: + version: + description: "Existing release tag, for example v0.1.0" + required: true + type: string + +permissions: + contents: write + +jobs: + build: + name: Build ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - name: linux-x86_64 + os: ubuntu-latest + binary: mesh-pdf-plugin + target: x86_64-unknown-linux-gnu + archive_ext: tar.gz + package: tar + - name: linux-aarch64 + os: ubuntu-24.04-arm + binary: mesh-pdf-plugin + target: aarch64-unknown-linux-gnu + archive_ext: tar.gz + package: tar + - name: macos-aarch64 + os: macos-15 + binary: mesh-pdf-plugin + target: aarch64-apple-darwin + archive_ext: tar.gz + package: tar + - name: windows-x86_64 + os: windows-latest + binary: mesh-pdf-plugin.exe + target: x86_64-pc-windows-msvc + archive_ext: zip + package: zip + - name: windows-aarch64 + os: windows-11-arm + binary: mesh-pdf-plugin.exe + target: aarch64-pc-windows-msvc + archive_ext: zip + package: zip + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', inputs.version) || github.ref }} + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + + - name: Cache Rust + uses: Swatinem/rust-cache@v2 + + - name: Build release binary + run: cargo build --release --locked + + - name: Test release binary + run: cargo test --release --locked + + - name: Package Unix archive + if: matrix.package == 'tar' + shell: bash + run: | + set -euo pipefail + version="${{ github.event.inputs.version || github.ref_name }}" + version="${version#v}" + stable_archive="pdf-${{ matrix.target }}.${{ matrix.archive_ext }}" + versioned_archive="pdf-${version}-${{ matrix.target }}.${{ matrix.archive_ext }}" + mkdir -p dist/pdf + cp "target/release/${{ matrix.binary }}" dist/pdf/pdf + cp plugin.toml dist/pdf/plugin.toml + cp README.md dist/pdf/README.md + tar -czf "$stable_archive" -C dist pdf + cp "$stable_archive" "$versioned_archive" + + - name: Package Windows archive + if: matrix.package == 'zip' + shell: pwsh + run: | + $version = "${{ github.event.inputs.version || github.ref_name }}".TrimStart("v") + $stableArchive = "pdf-${{ matrix.target }}.${{ matrix.archive_ext }}" + $versionedArchive = "pdf-$version-${{ matrix.target }}.${{ matrix.archive_ext }}" + New-Item -ItemType Directory -Force -Path dist/pdf | Out-Null + Copy-Item "target/release/${{ matrix.binary }}" "dist/pdf/pdf.exe" + Copy-Item plugin.toml "dist/pdf/plugin.toml" + Copy-Item README.md "dist/pdf/README.md" + Compress-Archive -Path "dist/pdf" -DestinationPath $stableArchive + Copy-Item $stableArchive $versionedArchive + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: pdf-${{ matrix.target }} + path: | + pdf-*.tar.gz + pdf-*.zip + if-no-files-found: error + + publish: + name: Publish GitHub release + needs: build + runs-on: ubuntu-latest + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + merge-multiple: true + + - name: Publish release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ github.event.inputs.version || github.ref_name }} + name: ${{ github.event.inputs.version || github.ref_name }} + files: artifacts/* + fail_on_unmatched_files: true + overwrite_files: true