badness 0.5.0

A language server, formatter, and linter for LaTeX
name: Build and Test

on:
  workflow_dispatch:
  workflow_call:
  pull_request:
  push:
    branches:
      - main
  schedule:
    - cron: "0 3 * * *"

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    if: github.event_name != 'schedule'
    name: Test
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        rust: [stable]

    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
          targets: wasm32-unknown-unknown

      - name: Cache cargo registry
        uses: actions/cache@v6
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-

      - name: Build
        run: cargo build --verbose

      - name: Run tests
        run: cargo test --verbose

  extension:
    name: VS Code Extension
    if: github.event_name != 'schedule'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      - uses: actions/setup-node@v6
        with:
          node-version: 20
          cache: npm
          cache-dependency-path: editors/code/package-lock.json

      - name: Install dependencies
        working-directory: editors/code
        run: npm ci

      # Type-checks against @types/vscode + vscode-languageclient and bundles
      # with esbuild. Mirrors the check-types + bundle steps that
      # vscode:prepublish runs at release time, so dependency bumps that break
      # the extension fail on the PR instead of at publish.
      - name: Compile extension
        working-directory: editors/code
        run: npm run compile

  cargo-audit:
    name: Cargo Audit
    runs-on: ubuntu-latest
    permissions:
      issues: write
      checks: write
    steps:
      - uses: actions/checkout@v7
      - uses: rustsec/audit-check@v2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

  cargo-deny:
    name: Cargo Deny
    runs-on: ubuntu-latest
    permissions:
      issues: write
      checks: write
    steps:
      - uses: actions/checkout@v7
      - uses: EmbarkStudios/cargo-deny-action@v2

  versionary:
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    needs: [test, extension, cargo-audit, cargo-deny]
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
      issues: write
    outputs:
      release_created: ${{ steps.versionary.outputs.release_created }}
      tag_name: ${{ steps.versionary.outputs.tag_name }}
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
          token: ${{ secrets.RELEASE_TOKEN }}

      - uses: dtolnay/rust-toolchain@stable

      - id: versionary
        uses: jolars/versionary@v0
        with:
          github-token: ${{ secrets.RELEASE_TOKEN }}

  build-release-assets:
    name: Build & Upload Release Assets
    needs: versionary
    if: ${{ needs.versionary.outputs.release_created == 'true' }}
    uses: ./.github/workflows/packages.yml
    with:
      upload: "true"
      tag: ${{ needs.versionary.outputs.tag_name }}
    permissions:
      contents: write

  publish-code-extensions:
    name: Publish Code Extensions
    needs: [versionary, build-release-assets]
    if: ${{ needs.versionary.outputs.release_created == 'true' }}
    uses: ./.github/workflows/publish-code-extensions.yml
    secrets: inherit
    permissions:
      contents: read