Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/crates/oxc_linter/src/options/oxlintrc.schema.json",
"rules": {
"typescript/naming-convention": "off"
},
"ignorePatterns": ["rollup.config.ts", "vitest.config.ts", "__tests__/**"]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Takahiro Sato

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
46 changes: 39 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<div align="center">

# Setup mq

This GitHub Action will setup [mq](https://github.com/harehare/mq) in your GitHub Actions workflow, allowing you
**Set up [mq](https://github.com/harehare/mq) in your GitHub Actions workflow.**

[![ci](https://img.shields.io/github/actions/workflow/status/harehare/setup-mq/ci.yml?style=flat-square&logo=github-actions&label=ci)](https://github.com/harehare/setup-mq/actions/workflows/ci.yml)
[![marketplace](https://img.shields.io/badge/marketplace-Setup%20mq-2088FF?style=flat-square&logo=githubactions&logoColor=white)](https://github.com/marketplace/actions/setup-mq)
[![LICENCE](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)

</div>

This GitHub Action sets up [mq](https://github.com/harehare/mq) in your GitHub Actions workflow, allowing you
to easily integrate mq into your CI/CD pipeline.

## Usage
Expand All @@ -18,7 +28,9 @@ steps:

### With additional binaries

You can install additional binaries from `mq-XXX` repositories using the `bins` option.
mq ships companion tools (`lsp`, `dbg`, `test`, `crawl`) as part of its own releases, and other tools
are distributed from separate `mq-XXX` repositories (e.g. `mq-foo`). Use the `bins` option to install
either kind by name.

```yaml
steps:
Expand All @@ -27,17 +39,37 @@ steps:
uses: harehare/setup-mq@v1
with:
version: 'v0.1.0'
bins: 'foo,bar' # Installs binaries from mq-foo and mq-bar repositories
bins: 'crawl,foo' # Installs mq-crawl from the mq release, and mq-foo from the mq-foo repository
- name: Run mq
run: echo "# Test" | mq '.h'
```

## Inputs

| Name | Description | Required | Default |
| --------- | ---------------------------------------------------------------------------- | -------- | -------------- |
| `version` | mq version to install | No | Latest version |
| `bins` | Comma-separated list of additional binaries to install from `mq-XXX` repositories | No | `''` |
| Name | Description | Required | Default |
| -------------- | --------------------------------------------------------------------------------- | -------- | --------------------- |
| `version` | mq version to install | No | Latest version |
| `bins` | Comma-separated list of additional binaries to install from `mq-XXX` repositories | No | `''` |
| `github-token` | Token used to query the GitHub Releases API, mainly to avoid rate limiting | No | `${{ github.token }}` |

## Supported platforms

| OS | Architecture | Notes |
| ------- | ------------ | ---------------------------------------------- |
| Linux | x64, arm64 | glibc and musl (e.g. Alpine) are auto-detected |
| macOS | arm64 | |
| Windows | x64, arm64 | |

A job summary showing the installed tool versions is written to the workflow run automatically.

## Development

```bash
npm install
npm test
npm run lint
npm run bundle # builds dist/index.js
```

## License

Expand Down
121 changes: 112 additions & 9 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { promises as fs } from 'node:fs';
import * as core from '@actions/core';
import * as github from '@actions/github';
import * as tc from '@actions/tool-cache';
Expand All @@ -17,6 +18,8 @@ vi.mock('node:fs', () => ({
copyFile: vi.fn(),
chmod: vi.fn(),
mkdir: vi.fn(),
// Rejects by default, simulating a glibc-based (non-Alpine) runner.
access: vi.fn().mockRejectedValue(new Error('ENOENT')),
},
}));

Expand All @@ -33,13 +36,20 @@ vi.mock('@actions/core', () => {
return '';
});

const summary = {
addHeading: vi.fn().mockReturnThis(),
addTable: vi.fn().mockReturnThis(),
write: vi.fn().mockResolvedValue(undefined),
};

return {
getInput,
info: vi.fn(),
error: vi.fn(),
warning: vi.fn(),
setFailed: vi.fn(),
addPath: vi.fn(),
summary,
};
});

Expand Down Expand Up @@ -77,6 +87,10 @@ vi.mock('@actions/tool-cache', () => ({
return 'latest_tool/mq-crawl';
}

if (url === 'latest_url/mq-musl') {
return 'latest_tool/mq-musl';
}

return '';
}),
extractTar: vi.fn().mockResolvedValue('/path/to/extracted/directory'),
Expand Down Expand Up @@ -114,6 +128,10 @@ vi.mock('@actions/github', () => ({
browser_download_url: 'latest_url/mq-crawl',
name: 'mq-crawl-x86_64-unknown-linux-gnu',
},
{
browser_download_url: 'latest_url/mq-musl',
name: 'mq-x86_64-unknown-linux-musl',
},
],
},
};
Expand Down Expand Up @@ -186,6 +204,11 @@ vi.mock('@actions/github', () => ({
describe('GitHub Action', () => {
beforeEach(() => {
vi.clearAllMocks();
// afterEach's resetAllMocks() wipes the module-mock default, so restore it here.
vi.mocked(fs.access).mockRejectedValue(new Error('ENOENT'));
vi.mocked(core.summary.addHeading).mockReturnThis();
vi.mocked(core.summary.addTable).mockReturnThis();
vi.mocked(core.summary.write).mockResolvedValue(undefined as any);
});

afterEach(() => {
Expand Down Expand Up @@ -267,12 +290,8 @@ describe('GitHub Action', () => {
expect(tc.downloadTool).toHaveBeenCalledWith('bin_bar_url/mq-bar');

// Verify info messages for additional bins
expect(core.info).toHaveBeenCalledWith(
expect.stringContaining('foo'),
);
expect(core.info).toHaveBeenCalledWith(
expect.stringContaining('bar'),
);
expect(core.info).toHaveBeenCalledWith(expect.stringContaining('foo'));
expect(core.info).toHaveBeenCalledWith(expect.stringContaining('bar'));
});

it('should handle bins with whitespace correctly', async () => {
Expand Down Expand Up @@ -319,9 +338,7 @@ describe('GitHub Action', () => {
await run();

expect(tc.downloadTool).toHaveBeenCalledWith('bin_foo_url/mq-foo');
expect(core.info).toHaveBeenCalledWith(
expect.stringContaining('foo'),
);
expect(core.info).toHaveBeenCalledWith(expect.stringContaining('foo'));
});

it('should not setup bins when bins input is empty', async () => {
Expand Down Expand Up @@ -425,6 +442,92 @@ describe('GitHub Action', () => {
expect(tc.downloadTool).toHaveBeenCalledWith('bin_foo_url/mq-foo');
});

it('should install the musl asset on an Alpine-based runner', async () => {
vi.mocked(fs.access).mockImplementationOnce(async (target) => {
if (target === '/etc/alpine-release') {
return undefined;
}
throw new Error('ENOENT');
});

vi.mocked(core.getInput).mockImplementation((name) => {
if (name === 'version') {
return '';
}

if (name === 'github-token') {
return 'fake-token';
}

return '';
});

await run();

expect(tc.downloadTool).toHaveBeenCalledWith('latest_url/mq-musl');
expect(core.addPath).toHaveBeenCalledWith('latest_tool');
});

it('should write a job summary after a successful setup', async () => {
vi.mocked(core.getInput).mockImplementation((name) => {
if (name === 'version') {
return 'v0.1.0';
}

if (name === 'github-token') {
return 'fake-token';
}

return '';
});

await run();

expect(core.summary.addHeading).toHaveBeenCalledWith('Setup mq', 2);
expect(core.summary.addTable).toHaveBeenCalledWith(
expect.arrayContaining([
expect.arrayContaining(['mq', 'v0.1.0', 'linux_x64_gnu']),
]),
);
expect(core.summary.write).toHaveBeenCalled();
});

it('should fail when the mq release has no matching asset for the platform', async () => {
const octokit = vi.mocked(github.getOctokit);
octokit.mockReturnValue({
rest: {
repos: {
getLatestRelease: vi.fn(async () => ({
data: {
tag_name: 'v1.0.0',
assets: [],
},
})),
getReleaseByTag: vi.fn(),
},
},
} as any);

vi.mocked(core.getInput).mockImplementation((name) => {
if (name === 'version') {
return '';
}

if (name === 'github-token') {
return 'fake-token';
}

return '';
});

await run();

expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining('Not Found mq'),
);
expect(core.addPath).not.toHaveBeenCalled();
});

it('should warn when a bin release has no matching asset', async () => {
const octokit = vi.mocked(github.getOctokit);
octokit.mockReturnValue({
Expand Down
Loading