Skip to content

Commit

Permalink
chore: merge pull request #70 from threeal/js-action
Browse files Browse the repository at this point in the history
Convert to JavaScript Action
  • Loading branch information
threeal authored Nov 21, 2023
2 parents d27fb54 + dd1c440 commit 434fbed
Show file tree
Hide file tree
Showing 16 changed files with 32,182 additions and 107 deletions.
28 changes: 28 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"root": true,
"extends": ["eslint:recommended", "prettier"],
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},
"overrides": [
{
"files": ["**/*.mts", "**/*.ts"],
"extends": ["plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["tsconfig.eslint.json"]
},
"plugins": ["@typescript-eslint", "eslint-plugin-tsdoc"],
"rules": {
"tsdoc/syntax": "error"
}
},
{
"files": ["**/*.test.*"],
"env": {
"jest": true
}
}
]
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main/index.mjs -diff linguist-generated=true
9 changes: 9 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ updates:
commit-message:
prefix: chore
labels: [chore]

- package-ecosystem: npm
directory: /
schedule:
interval: daily
commit-message:
prefix: chore
labels: [chore]
versioning-strategy: increase
39 changes: 39 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build
on:
workflow_dispatch:
pull_request:
push:
branches: [main]
jobs:
build-package:
name: Build Package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.1

- name: Setup Node.js
uses: actions/setup-node@v4.0.0
with:
node-version: latest

- name: Update Yarn
run: corepack enable && yarn set version stable

- name: Cache deps
uses: actions/cache@v3.3.2
with:
path: .yarn
key: yarn-${{ runner.os }}-${{ hashFiles('yarn.lock') }}

- name: Install deps
run: yarn install

- name: Check lib
run: yarn check

- name: Bundle dist
run: yarn bundle

- name: Check diff
run: git diff --exit-code HEAD
43 changes: 30 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ on:
push:
branches: [latest, main]
jobs:
test-package:
name: Test Package
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: [windows, ubuntu, macos]
env:
NODE_OPTIONS: --experimental-vm-modules
steps:
- name: Checkout
uses: actions/checkout@v4.1.1

- name: Setup Node.js
uses: actions/setup-node@v4.0.0
with:
node-version: latest

- name: Cache deps
uses: actions/cache@v3.3.2
with:
path: .yarn
key: yarn-${{ runner.os }}-${{ hashFiles('yarn.lock') }}

- name: Install deps
run: corepack enable && yarn install

- name: Test lib
run: yarn test

default-usage:
runs-on: ${{ matrix.os }}-latest
strategy:
Expand Down Expand Up @@ -132,16 +162,3 @@ jobs:
build-args: --target test_c --target test_cpp
run-test: true
test-args: -R test

specified-shell:
runs-on: windows-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4.1.1

- name: Use the action with specified shell
uses: ./
with:
shell: bash
source-dir: test
run-build: true
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.*
!.eslint*
!.git*

build
build/
coverage/
dist/
node_modules/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Latest Version](https://img.shields.io/github/v/release/threeal/cmake-action)](https://github.com/threeal/cmake-action/releases/)
[![License](https://img.shields.io/github/license/threeal/cmake-action)](./LICENSE)
[![Build Status](https://img.shields.io/github/actions/workflow/status/threeal/cmake-action/build.yaml?branch=main)](https://github.com/threeal/cmake-action/actions/workflows/build.yaml)
[![Test Status](https://img.shields.io/github/actions/workflow/status/threeal/cmake-action/test.yml?label=test&branch=main)](https://github.com/threeal/cmake-action/actions/workflows/test.yml)

Configure, build, and test your [CMake](https://cmake.org/) project using [GitHub Actions](https://github.com/features/actions). This action simplifies the workflow for configuring the build environment of a CMake project. It can also be optionally specified to build a CMake project using the `cmake --build` command and test it using the `ctest` command.
Expand All @@ -22,7 +23,6 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action

| Name | Value Type | Description |
| --- | --- | --- |
| `shell` | String | The shell to be used to run the commands. It defaults to `pwsh` on Windows and `bash` on Linux and macOS. Refer to [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell) for more information on available shell options. |
| `source-dir` | Path | The source directory of the CMake project. It defaults to the current directory. |
| `build-dir` | Path | The build directory of the CMake project. It defaults to the `build` directory inside the source directory. |
| `generator` | String | The build system generator for the CMake project. It appends the CMake configuration arguments with `-G [val]`. |
Expand Down
94 changes: 2 additions & 92 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ branding:
color: gray-dark
icon: terminal
inputs:
shell:
description: The shell to be used to run the commands
required: false
source-dir:
description: The source directory of the CMake project
required: false
Expand Down Expand Up @@ -54,92 +51,5 @@ outputs:
description: The build directory of the CMake project
value: ${{ steps.process-inputs.outputs.build-dir }}
runs:
using: composite
steps:
- name: Process the inputs
id: process-inputs
shell: bash
run: |
if [ -n '${{ inputs.shell }}' ]; then
SHELL='${{ inputs.shell }}'
else
SHELL='${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}'
fi
echo "shell=$SHELL" >> $GITHUB_OUTPUT
SOURCE_DIR="."
if [ -n '${{ inputs.source-dir }}' ]; then
SOURCE_DIR="${{ inputs.source-dir }}"
fi
BUILD_DIR="build"
if [ -n '${{ inputs.build-dir }}' ]; then
BUILD_DIR="${{ inputs.build-dir }}"
elif [ -n "${{ inputs.source-dir }}" ]; then
BUILD_DIR="${{ inputs.source-dir }}/build"
fi
echo "build-dir=$BUILD_DIR" >> $GITHUB_OUTPUT
ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'"
if [ -n '${{ inputs.generator }}' ]; then
ARGS="$ARGS -G '${{ inputs.generator }}'"
fi
if [ -n '${{ inputs.c-compiler }}' ]; then
ARGS="$ARGS -D CMAKE_C_COMPILER='${{ inputs.c-compiler }}'"
fi
if [ -n '${{ inputs.cxx-compiler }}' ]; then
ARGS="$ARGS -D CMAKE_CXX_COMPILER='${{ inputs.cxx-compiler }}'"
fi
if [ -n '${{ inputs.c-flags }}' ]; then
ARGS="$ARGS -D CMAKE_C_FLAGS='${{ inputs.c-flags }}'"
fi
if [ -n '${{ inputs.cxx-flags }}' ]; then
ARGS="$ARGS -D CMAKE_CXX_FLAGS='${{ inputs.cxx-flags }}'"
fi
for OPT in ${{ inputs.options }}; do
ARGS="$ARGS -D $OPT"
done
if [ -n '${{ inputs.args }}' ]; then
ARGS="$ARGS ${{ inputs.args }}"
fi
echo "cmake-args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
if [ '${{ inputs.run-build }}' == 'true' ] || [ '${{ inputs.run-test }}' == 'true' ]; then
BUILD_ARGS="--build '$BUILD_DIR'"
if [ -n '${{ inputs.build-args }}' ]; then
BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}"
fi
echo "cmake-build-args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
fi
if [ '${{ inputs.run-test }}' == 'true' ]; then
TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error"
if [ -n '${{ inputs.test-args }}' ]; then
TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}"
fi
echo "cmake-test-args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
fi
- name: Install Ninja
if: ${{ inputs.generator == 'Ninja' }}
shell: bash
run: |
case "$OSTYPE" in
darwin*) brew install ninja ;;
linux*) sudo apt install -y ninja-build ;;
*) choco install ninja ;;
esac
- name: Configure the CMake project
shell: ${{ steps.process-inputs.outputs.shell }}
run: cmake ${{ steps.process-inputs.outputs.cmake-args }}

- name: Build targets
if: inputs.run-build != 'false' || inputs.run-test != 'false'
shell: ${{ steps.process-inputs.outputs.shell }}
run: cmake ${{ steps.process-inputs.outputs.cmake-build-args }}

- name: Run tests
if: inputs.run-test != 'false'
shell: ${{ steps.process-inputs.outputs.shell }}
run: ctest ${{ steps.process-inputs.outputs.cmake-test-args }}
using: node20
main: main/index.mjs
19 changes: 19 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"collectCoverage": true,
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
},
"extensionsToTreatAsEsm": [".ts", ".mts"],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.mjs$": "$1.mts"
},
"testMatch": ["**/*.test.ts"],
"transform": {
"^.+\\.m?ts$": ["ts-jest", { "useESM": true }]
}
}
Loading

0 comments on commit 434fbed

Please sign in to comment.