Skip to content

Commit

Permalink
feat: auto start iggy as option (#17)
Browse files Browse the repository at this point in the history
* feat: wip

* ci: use binary name

* ci: optimize triggers

* ci: trigger self host

* ci: use latest version

* ci: use specific version

* feat: detach process

* feat: use unref

* chore: add logs

* feat: ignore stdio

* feat: add option to choose auto start

* docs: add command to automatically generate options documentation

* test: validate autostart option

* ci: build sources
  • Loading branch information
Tchoupinax authored Nov 27, 2024
1 parent ae3964f commit 112ad8b
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 16 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/action-self-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ jobs:
- name: Setup iggy (using local GitHub Action)
uses: "./"
with:
version: "0.4.71"
version: "0.4.82"
autostart: false

- name: Print $PATH for iggy
run: which iggy-server
Expand All @@ -40,8 +41,8 @@ jobs:
- name: Check version is the one asked
run: |
VERSION=$(iggy-server --version | grep -oP 'server \K[0-9]+\.[0-9]+\.[0-9]+')
if [ "$VERSION" != "0.4.71" ]; then
echo "Error: Expected version 0.4.71, but got $VERSION"
if [ "$VERSION" != "0.4.82" ]; then
echo "Error: Expected version 0.4.82, but got $VERSION"
exit 1
fi
echo "Version is correct: $VERSION"
1 change: 1 addition & 0 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Check Transpiled JavaScript
on:
pull_request:
types: [ready_for_review]
branches:
- main
paths:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Checks
on:
pull_request:
types: [ready_for_review]
paths:
- "src/**/.ts"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/merge-checks.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Merge checks
on:
pull_request:
types: [opened, reopened, synchronize, labeled, unlabeled]
types: [ready_for_review, reopened, synchronize, labeled, unlabeled]

jobs:
check-labels:
Expand Down
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,45 @@ jobs:
name: Test setup-iggy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup iggy
uses: iggy-rs/setup-iggy@v1
with:
version: "0.4.72"
- name: Print iggy version
run: iggy-server --version
```
## Options
<!-- action-docs-header source="action.yml" -->
<!-- action-docs-header source="action.yml" -->
<!-- action-docs-description source="action.yml" -->
## Description
A GitHub Action to run iggy server
<!-- action-docs-description source="action.yml" --> # applicable for actions only
<!-- action-docs-inputs source="action.yml" -->
## Inputs
| name | description | required | default |
| --- | --- | --- | --- |
| `version` | <p>The Iggy version to launch.</p> | `false` | `default` |
| `autostart` | <p>Set to false if you do not want to start iggy server automatically</p> | `false` | `true` |
<!-- action-docs-inputs source="action.yml" -->

<!-- action-docs-outputs source="action.yml" -->
## Outputs

| name | description |
| --- | --- |
| `version` | <p>The Iggy version that was launched.</p> |
<!-- action-docs-outputs source="action.yml" -->

<!-- action-docs-runs source="action.yml" -->
## Runs

This action is a `node20` action.
<!-- action-docs-runs source="action.yml" --> # applicable for actions only

## Contributions

Any pull request is welcome!
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ inputs:
version:
description: "The Iggy version to launch."
required: false
default: "0.4.72"
default: "default"
autostart:
description: "Set to false if you do not want to start iggy server automatically"
required: false
default: "true"
outputs:
version:
description: "The Iggy version that was launched."
Expand Down
47 changes: 47 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(7484));
const binary_1 = __nccwpck_require__(2056);
const start_server_1 = __nccwpck_require__(9053);
const DEFAULT_VERSION = "latest";
function main() {
return __awaiter(this, void 0, void 0, function* () {
let version = core.getInput("version", { required: false });
if (version == null || version == "") {
version = DEFAULT_VERSION;
}
const autoStart = core.getBooleanInput("autostart", { required: false });
try {
core.info(`Installing iggy:${version} and adding it to GitHub Actions Path`);
yield (0, binary_1.setupBinary)(version);
if (autoStart) {
core.info("Starting server...");
(0, start_server_1.startIggyServer)();
}
}
catch (error) {
if (error instanceof Error) {
Expand All @@ -154,6 +160,47 @@ main();

/***/ }),

/***/ 9053:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.startIggyServer = startIggyServer;
const core = __importStar(__nccwpck_require__(7484));
const child_process_1 = __nccwpck_require__(5317);
function startIggyServer() {
const iggy = (0, child_process_1.spawn)("iggy-server", [], { detached: true, stdio: "ignore" });
iggy.unref();
core.info("Server started!");
}
//# sourceMappingURL=start-server.js.map

/***/ }),

/***/ 4914:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions dist/start-server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/start-server.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"main": "dist/index.js",
"scripts": {
"build": "tsc && ncc build --no-cache --no-source-map-register",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"docs": "action-docs --update-readme"
},
"dependencies": {
"@actions/core": "1.11.1",
Expand All @@ -25,6 +26,7 @@
"devDependencies": {
"@types/node": "22.10.0",
"@vercel/ncc": "0.38.3",
"action-docs": "2.5.1",
"eslint": "9.15.0",
"eslint-plugin-jsonc": "2.18.2",
"eslint-plugin-prettier": "5.2.1",
Expand Down
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from "@actions/core";

import { setupBinary } from "./binary";
import { startIggyServer } from "./start-server";

const DEFAULT_VERSION = "latest";

Expand All @@ -9,11 +10,16 @@ async function main() {
if (version == null || version == "") {
version = DEFAULT_VERSION;
}
const autoStart = core.getBooleanInput("autostart", { required: false });

try {
core.info(`Installing iggy:${version} and adding it to GitHub Actions Path`);

await setupBinary(version);

if (autoStart) {
core.info("Starting server...");
startIggyServer();
}
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
Expand Down
10 changes: 10 additions & 0 deletions src/start-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as core from "@actions/core";

import { spawn } from "child_process";

export function startIggyServer() {
const iggy = spawn("iggy-server", [], { detached: true, stdio: "ignore" });
iggy.unref();

core.info("Server started!");
}
Loading

0 comments on commit 112ad8b

Please sign in to comment.