-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(output): ensure that current buffer is respected (#9)
* fix(output): ensure buffer location is respected * chore(make): add test command * chore(ci): disabled stlua * chore(ci): add test
- Loading branch information
Showing
6 changed files
with
124 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,71 @@ | ||
name: main | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
|
||
|
||
jobs: | ||
run: | ||
lint: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- uses: JohnnyMorganz/[email protected] | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
args: --check . | ||
|
||
- name: Release | ||
uses: go-semantic-release/action@v1 | ||
if: github.ref == 'refs/heads/main' | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- uses: JohnnyMorganz/stylua-action@v1 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
args: --check . | ||
test: | ||
runs-on: ${{ matrix.os }} | ||
timeout-minutes: 10 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- id: Neovim Nightly | ||
os: ubuntu-20.04 | ||
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz | ||
manager: sudo apt-get | ||
packages: -y ripgrep | ||
- id: Neovim 0.8 | ||
os: ubuntu-20.04 | ||
url: https://github.com/neovim/neovim/releases/download/v0.8.0/nvim-linux64.tar.gz | ||
manager: sudo apt-get | ||
packages: -y ripgrep | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: date +%F > todays-date | ||
- name: Restore from todays cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: _neovim | ||
key: ${{ runner.os }}-${{ matrix.url }}-${{ hashFiles('todays-date') }} | ||
- name: Prepare | ||
run: | | ||
${{ matrix.manager }} update | ||
${{ matrix.manager }} install ${{ matrix.packages }} | ||
test -d _neovim || { | ||
mkdir -p _neovim | ||
curl -sL ${{ matrix.url }} | tar xzf - --strip-components=1 -C "${PWD}/_neovim" | ||
} | ||
mkdir -p ~/.local/share/nvim/site/pack/vendor/start | ||
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim | ||
git clone --depth 1 https://github.com/kyazdani42/nvim-web-devicons ~/.local/share/nvim/site/pack/vendor/start/nvim-web-devicons | ||
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start | ||
- name: Run tests | ||
run: | | ||
export PATH="${PWD}/_neovim/bin:${PATH}" | ||
export VIM="${PWD}/_neovim/share/nvim/runtime" | ||
nvim --version | ||
make test | ||
release: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
needs: [lint, test] | ||
steps: | ||
- name: Release | ||
uses: go-semantic-release/action@v1 | ||
if: github.ref == 'refs/heads/main' | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
local M = {} | ||
|
||
-- Produces a fully qualified path for the provided output path | ||
-- Ensures that the current directory is respected | ||
-- e.g if the user is within a repo: | ||
-- README.md | ||
-- src/ | ||
-- my_folder/ | ||
-- document.md | ||
-- res/ | ||
-- my_other_folder/ | ||
-- document2.md | ||
-- res/ | ||
-- If they run the plugin whilst inside 'my_folder' with output res/my_image.png | ||
-- then the output image should go into src/my_folder/res/my_image.png | ||
-- Some environments will interpret "res/my_image.png" as starting from the root repo which is usually | ||
-- not what we want | ||
M.get_current_buffer_directory = function(output_path, current_buffer, buffer_directory) | ||
if output_path:sub(1, 1) == "/" then | ||
return buffer_directory .. output_path | ||
else | ||
return buffer_directory .. "/" .. output_path | ||
end | ||
end | ||
|
||
return M |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
set rtp+=. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local mock = require("luassert.mock") | ||
|
||
describe("get_current_buffer_directory", function() | ||
it("respects output path /", function() | ||
local utils = require("maim.utils") | ||
|
||
local output_path = "/res/image.png" | ||
local current_buffer = "/home/hello/document/projects/my_project/subfolder/document.md" | ||
local current_directory = "/home/hello/document/projects/my_project/subfolder" | ||
local expected = "/home/hello/document/projects/my_project/subfolder/res/image.png" | ||
|
||
local output = utils.get_current_buffer_directory(output_path, current_buffer, current_directory) | ||
|
||
assert.are.same(expected, output) | ||
end) | ||
|
||
it("respects output path", function() | ||
local utils = require("maim.utils") | ||
|
||
local output_path = "res/image.png" | ||
local current_buffer = "/home/hello/document/projects/my_project/subfolder/document.md" | ||
local current_directory = "/home/hello/document/projects/my_project/subfolder" | ||
local expected = "/home/hello/document/projects/my_project/subfolder/res/image.png" | ||
|
||
local output = utils.get_current_buffer_directory(output_path, current_buffer, current_directory) | ||
|
||
assert.are.same(expected, output) | ||
end) | ||
end) |
This file contains 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