Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: push v1 of the Github action #1

Merged
merged 7 commits into from
Nov 24, 2024
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
45 changes: 45 additions & 0 deletions .github/workflows/action-self-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "GitHub Action: Self-Test"
on:
push:

jobs:
setup-iggy:
name: Test setup-iggy
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22

- name: Install dependencies
run: yarn

- name: Build dist
run: yarn run build

- name: Setup iggy (using local GitHub Action)
uses: "./"
with:
version: "0.4.71"

- name: Print $PATH for iggy
run: which iggy-server

- name: Print iggy version
run: iggy-server --version

- 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"
exit 1
fi
echo "Version is correct: $VERSION"
32 changes: 32 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Checks
on:
push:

jobs:
checks:
name: Install and build
runs-on: ubuntu-latest

strategy:
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategyfail-fast
fail-fast: false
matrix:
node-version:
- 22.x

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: yarn

- name: Build dist
run: yarn run build
65 changes: 65 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release
on:
push:
branches:
- main

jobs:
install:
name: Install and build
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22

- name: Install dependencies
run: yarn

- name: Build dist
run: yarn run build

semantic-release:
needs: install
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.DEPLOY_APP_ID }}
private-key: ${{ secrets.DEPLOY_APP_KEY }}

- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
# Make sure the value of GITHUB_TOKEN will not be persisted in repo's config
persist-credentials: false

- uses: actions/setup-node@v4
with:
node-version: 22

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v4
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}

- uses: actions/cache@v4
with:
path: |
VERSION.txt
package.json
package-lock.json
CHANGELOG.md
key: ${{ runner.os }}-sr-version-${{ github.sha }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"arrowParens": "avoid",
"printWidth": 100,
"trailingComma": "all"
}
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "always"
},
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.formatOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
}
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @spetz @T1B0 @Tchoupinax
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
# setup-iggy
# GitHub Action: `setup-iggy`

<p>
<a href="https://github.com/iggy-rs/setup-iggy/releases"><img alt="Latest release" src="https://img.shields.io/github/v/release/Tchoupinax/setup-iggy"></a>
</p>

## Usage

```yaml
name: Test with Iggy server
on:
push:
jobs:
tests-iggy:
name: Test setup-iggy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup iggy
uses: "./"
with:
version: "0.4.71"
- name: Print iggy version
run: iggy-server --version
```
19 changes: 19 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://docs.github.com/en/actions/sharing-automations/creating-actions/publishing-actions-in-github-marketplace
name: "Setup Iggy server"
author: "Tchoupinax"
description: "A GitHub Action to run iggy server"
inputs:
version:
description: "The Iggy version to launch."
required: false
default: "0.4.72"
outputs:
version:
description: "The Iggy version that was launched."
runs:
using: "node20"
main: "dist/index.js"
# https://actions-cool.github.io/github-action-branding
branding:
icon: "box"
color: "orange"
46 changes: 46 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import eslint from "@eslint/js";

import eslintPluginJsonc from 'eslint-plugin-jsonc';
import eslintPluginPrettierRecommended from "eslint-plugin-prettier";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import tseslint from "typescript-eslint";

export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommended,
...eslintPluginJsonc.configs['flat/recommended-with-jsonc'],
{
plugins: {
"eslint-plugin-prettier": eslintPluginPrettierRecommended,
},
},
{
plugins: {
"simple-import-sort": simpleImportSort,
},
ignores: ["package.json"],
rules: {
// https://github.com/lydell/eslint-plugin-simple-import-sort
"simple-import-sort/imports": [
"error",
{
// https://dev.to/receter/automatic-import-sorting-in-vscode-275m
groups: [["^@?\\w", "^node"], ["^[^@]?\\w"]],
},
],
"simple-import-sort/exports": "error",
},
},
{
rules: {
"@typescript-eslint/no-explicit-any": "off",
},
},
{
files: ["**/*.json"],
ignores: ["package.json"],
rules: {
"jsonc/sort-keys": ["error"]
}
}
);
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "setup-iggy",
"version": "0.1.0",
"description": "A GitHub Action to install a specific version of Iggy server",
"private": true,
"keywords": [
"github-actions",
"hashicorp",
"nomad"
],
"repository": {
"type": "git",
"url": "[email protected]:iggy-rs/setup-iggy.git"
},
"license": "MIT",
"author": "Tchoupinax",
"main": "dist/index.js",
"scripts": {
"build": "tsc && ncc build --no-cache",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
},
"dependencies": {
"@actions/core": "1.11.1",
"@actions/tool-cache": "^2.0.1"
},
"devDependencies": {
"@types/node": "22.9.3",
"@vercel/ncc": "0.38.3",
"eslint": "9.15.0",
"eslint-plugin-jsonc": "2.18.2",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-simple-import-sort": "12.1.1",
"typescript": "5.6",
"typescript-eslint": "8.15.0",
"vite-node": "2.1.5"
}
}
15 changes: 15 additions & 0 deletions src/binary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as core from "@actions/core";

import { downloadFile } from "./download-binary";

export async function setupBinary(version: string) {
core.info(`Installing iggy binary (${version})...`);

const binaryPath = await downloadFile(version);
core.info(`Binary path is: ${binaryPath}`);

core.addPath(binaryPath);
core.info(`iggy-server:${version} added to path`);

core.setOutput("version", version);
}
13 changes: 13 additions & 0 deletions src/download-binary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { info } from "@actions/core";
import { downloadTool, extractZip } from "@actions/tool-cache";

export async function downloadFile(version: string): Promise<string> {
const arch = "Linux-x86_64";

const binaryUrl = `https://github.com/iggy-rs/iggy/releases/download/server-${version}/${arch}.zip`;
info(`Binary downloaded from ${binaryUrl}`);

const pathToTarball = await downloadTool(binaryUrl);
const pathToCLI = await extractZip(pathToTarball);
return pathToCLI + `/all_artifacts/${arch}`;
}
24 changes: 24 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as core from "@actions/core";

import { setupBinary } from "./binary";

const DEFAULT_VERSION = "0.4.72";

async function main() {
let version = core.getInput("version", { required: false });
if (version == null || version == "") {
version = DEFAULT_VERSION;
}

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

await setupBinary(version);
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
}
}
}

main();
17 changes: 17 additions & 0 deletions src/utils/arch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os from "os";

export function getArch(): string {
const arch = os.arch();
switch (arch) {
case "arm":
return "arm";
case "arm64":
return "arm64";
case "x32":
return "386";
case "x64":
return "amd64";
default:
throw new Error(`Unsupported operating system architecture: ${arch}`);
}
}
Loading