|
1 | | -name: CI |
| 1 | +name: SQL Formatter CI |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: [main] |
| 5 | + branches: [main, develop] |
6 | 6 | pull_request: |
7 | 7 | branches: [main] |
8 | 8 |
|
9 | 9 | jobs: |
10 | | - build: |
| 10 | + test: |
11 | 11 | runs-on: ubuntu-latest |
| 12 | + strategy: |
| 13 | + matrix: |
| 14 | + nvim-version: ["0.8.0", "0.9.0"] |
| 15 | + sql-dialect: ["postgresql", "mysql", "sqlite"] |
12 | 16 |
|
13 | 17 | steps: |
14 | | - - name: Checkout repository |
15 | | - uses: actions/checkout@v3 |
| 18 | + - uses: actions/checkout@v3 |
| 19 | + |
| 20 | + - name: Setup Neovim |
| 21 | + run: | |
| 22 | + curl -LO https://github.com/neovim/neovim/releases/download/v${{ matrix.nvim-version }}/nvim-linux64.tar.gz |
| 23 | + tar xzf nvim-linux64.tar.gz |
| 24 | + sudo mv nvim-linux64/bin/nvim /usr/local/bin/ |
| 25 | + sudo mv nvim-linux64/lib/nvim /usr/local/lib/ |
| 26 | + sudo mv nvim-linux64/share/nvim /usr/local/share/ |
| 27 | + nvim --version |
16 | 28 |
|
17 | | - - name: Set up Node.js |
18 | | - uses: actions/setup-node@v3 |
| 29 | + - name: Setup Python |
| 30 | + uses: actions/setup-python@v4 |
19 | 31 | with: |
20 | | - node-version: "18" |
| 32 | + python-version: "3.x" |
21 | 33 |
|
22 | 34 | - name: Install dependencies |
23 | | - run: npm ci |
| 35 | + run: | |
| 36 | + # Install sqlparse |
| 37 | + pip install sqlparse |
| 38 | + |
| 39 | + # Install LuaJIT and LuaRocks |
| 40 | + sudo apt-get update |
| 41 | + sudo apt-get install -y luajit luarocks |
| 42 | + sudo luarocks install luacheck |
| 43 | + |
| 44 | + # Install stylua for formatting |
| 45 | + cargo install stylua |
| 46 | +
|
| 47 | + - name: Lint Lua code |
| 48 | + run: | |
| 49 | + luacheck lua/ --globals vim --no-color |
| 50 | + stylua --check lua/ |
| 51 | +
|
| 52 | + - name: Test plugin loading |
| 53 | + run: | |
| 54 | + nvim --headless -c "lua require('sql-formatter').setup({dialect = '${{ matrix.sql-dialect }}'})" -c "qa!" |
| 55 | +
|
| 56 | + - name: Test SQL formatting |
| 57 | + run: | |
| 58 | + # Test basic SQL formatting |
| 59 | + echo "SELECT * FROM users WHERE active=1;" | sqlformat --reindent --keywords upper --identifiers lower - |
| 60 | + |
| 61 | + # Test complex SQL formatting |
| 62 | + echo "WITH RECURSIVE cte AS (SELECT id, name, parent_id FROM categories WHERE parent_id IS NULL UNION ALL SELECT c.id, c.name, c.parent_id FROM categories c INNER JOIN cte ON c.parent_id = cte.id) SELECT * FROM cte;" | sqlformat --reindent --keywords upper --identifiers lower - |
24 | 63 |
|
25 | | - - name: Run tests |
26 | | - run: npm test |
| 64 | + - name: Test file type detection |
| 65 | + run: | |
| 66 | + # Create test SQL files |
| 67 | + echo "SELECT * FROM test;" > test.sql |
| 68 | + echo "SELECT * FROM test;" > test.mysql |
| 69 | + echo "SELECT * FROM test;" > test.pgsql |
| 70 | + |
| 71 | + # Test formatting for each file type |
| 72 | + for file in test.*; do |
| 73 | + nvim --headless -c "e $file" -c "lua require('sql-formatter').setup({dialect = '${{ matrix.sql-dialect }}'})" -c "wq" |
| 74 | + done |
| 75 | +
|
| 76 | + release: |
| 77 | + needs: test |
| 78 | + runs-on: ubuntu-latest |
| 79 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 80 | + |
| 81 | + steps: |
| 82 | + - uses: actions/checkout@v3 |
| 83 | + with: |
| 84 | + fetch-depth: 0 |
27 | 85 |
|
28 | | - - name: Build project |
29 | | - run: npm run build |
| 86 | + - name: Generate changelog |
| 87 | + id: changelog |
| 88 | + run: | |
| 89 | + echo "## Changes" > CHANGELOG.tmp |
| 90 | + git log --oneline --since="$(git describe --tags --abbrev=0 2>/dev/null || echo '1970-01-01')" >> CHANGELOG.tmp |
30 | 91 |
|
31 | | - - name: Deploy to GitHub Pages |
32 | | - if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
33 | | - uses: peaceiris/actions-gh-pages@v3 |
| 92 | + - name: Create Release |
| 93 | + uses: actions/create-release@v1 |
| 94 | + if: contains(github.event.head_commit.message, '[release]') |
| 95 | + env: |
| 96 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
34 | 97 | with: |
35 | | - github_token: ${{ secrets.GITHUB_TOKEN }} |
36 | | - publish_dir: ./dist |
| 98 | + tag_name: v${{ github.run_number }} |
| 99 | + release_name: Release v${{ github.run_number }} |
| 100 | + body_path: CHANGELOG.tmp |
| 101 | + draft: false |
| 102 | + prerelease: false |
0 commit comments