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

Feature/add bun support #4

Merged
merged 3 commits into from
Oct 5, 2023
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
58 changes: 58 additions & 0 deletions .github/workflows/environment-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
"on":
workflow_call:
inputs:
package_manager:
default: npm
description: Package manager to use
options:
- npm
- bun
type: choice
dependencies_type:
default: prod
description: Dependencies type to install
options:
- prod
- dev
type: choice
node_version:
description: Node version to setup
default: "18"
required: false
type: string
registry_url:
description: Registry url to use
default: https://registry.npmjs.org
required: false
type: string

jobs:
setup-npm:
if: inputs.package_manager == 'npm'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
registry-url: ${{ inputs.registry_url }}
node-version: ${{ inputs.node_version }}
cache: npm
- name: Install node dependencies
run: npm ci ${{ inputs.dependencies_type == 'prod' && '--omit=dev' || '' }}
setup-bun:
if: inputs.package_manager == 'bun'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
registry-url: ${{ inputs.registry_url }}
node-version: ${{ inputs.node_version }}
- uses: oven-sh/setup-bun@v1
- uses: actions/cache@v2
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
- name: Install node dependencies
run: bun install --frozen-lockfile ${{ inputs.dependencies_type == 'prod' && '--production' || '' }}
18 changes: 11 additions & 7 deletions .github/workflows/github-npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@
default: "18"
required: false
type: string
package_manager:
default: npm
description: Package manager to use
options:
- npm
- bun
type: choice

jobs:
publish:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: ./.github/workflows/environment-setup
with:
registry-url: https://npm.pkg.github.com
node-version: ${{ inputs.node_version }}
cache: npm
- name: Install node dependencies
run: npm ci
package_manager: ${{ inputs.package_manager }}
node_version: ${{ inputs.node_version }}
registry_url: https://npm.pkg.github.com
- name: Update version to include commit hash
run: npm version "$(npm pkg get version | sed 's/\"//g')"-"$(date +%s)".${{ github.sha }} --allow-same-version --git-tag-version=false --tag-version-prefix=''
- name: Publish to ${{ inputs.dist_tag }} tag with npm registry
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/internal-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
with:
go-version: stable
- run: go install github.com/rhysd/actionlint/cmd/actionlint@latest
- run: actionlint
- run: actionlint --ignore "^unexpected key \"options\" for \"inputs at workflow_call event\" section\. expected one of .*" --ignore "^invalid value \"choice\" for input type of workflow_call event. it must be one of .*"
17 changes: 11 additions & 6 deletions .github/workflows/node-qa-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
default: "['16.x', '17.x', '18.x']"
required: false
type: string
package_manager:
default: npm
description: Package manager to use
options:
- npm
- bun
type: choice
format_command:
description: Format command to run. Disabled by default
default:
Expand Down Expand Up @@ -45,13 +52,11 @@ jobs:
matrix:
node_version: ${{ fromJson(inputs.node_versions) }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: ./.github/workflows/environment-setup
with:
node-version: ${{ matrix.node_version }}
cache: npm
- name: Install node dependencies
run: npm ci
package_manager: ${{ inputs.package_manager }}
node_version: ${{ matrix.node_version }}
dependencies_type: dev
- name: Extract the last matrix job index
env:
LAST_JOB_INDEX_OFFSET: ${{ strategy.job-total}}
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
default: "18"
required: false
type: string
package_manager:
default: npm
description: Package manager to use
options:
- npm
- bun
type: choice
secrets:
NPM_TOKEN:
description: NPM token with right access for publishing
Expand All @@ -24,14 +31,10 @@ jobs:
name: ${{ inputs.dist_tag }}
url: ${{ steps.package-version-url.outputs.packageVersionUrl }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: ./.github/workflows/environment-setup
with:
registry-url: https://registry.npmjs.org
node-version: ${{ inputs.node_version }}
cache: npm
- name: Install node dependencies
run: npm ci
package_manager: ${{ inputs.package_manager }}
node_version: ${{ inputs.node_version }}
- name: Update version for non latest tagged versions
if: inputs.dist_tag != 'latest'
run: npm version "$(npm pkg get version | sed 's/\"//g')"-"$(date +%s)".${{ github.sha }} --allow-same-version --git-tag-version=false --tag-version-prefix=''
Expand Down
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ Publish a NPM package to the NPM registry.

#### Inputs

| Name | Description | Type | Default | Required |
| -------------- | --------------------------- | -------- | -------- | -------- |
| `dist_tag` | NPM dist tag to publish to. | `string` | `latest` | `false` |
| `node_version` | Node version to build on. | `string` | `18` | `false` |
| Name | Description | Type | Default | Required |
| ----------------- | --------------------------- | -------- | -------- | -------- |
| `dist_tag` | NPM dist tag to publish to. | `string` | `latest` | `false` |
| `node_version` | Node version to build on. | `string` | `18` | `false` |
| `package_manager` | Package manager to use. | `choice` | `npm` | `false` |

#### Secrets

Expand All @@ -60,10 +61,11 @@ Publish a NPM package to the GitHub registry.

#### Inputs

| Name | Description | Type | Default | Required |
| -------------- | --------------------------- | -------- | ------- | -------- |
| `dist_tag` | NPM dist tag to publish to. | `string` | `` | `true` |
| `node_version` | Node version to build on. | `string` | `18` | `false` |
| Name | Description | Type | Default | Required |
| ----------------- | --------------------------- | -------- | ------- | -------- |
| `dist_tag` | NPM dist tag to publish to. | `string` | `` | `true` |
| `node_version` | Node version to build on. | `string` | `18` | `false` |
| `package_manager` | Package manager to use. | `choice` | `npm` | `false` |

#### Secrets

Expand Down Expand Up @@ -119,6 +121,7 @@ Testing for node app, libraries and components.
| Name | Description | Type | Default | Required |
| ---------------------- | ------------------------------------------------------------------- | --------- | -------------------------- | -------- |
| `node_versions` | Node versions matrix to test on. | `string` | `['16.x', '17.x', '18.x']` | `false` |
| `package_manager` | Package manager to use. | `choice` | `npm` | `false` |
| `format_command` | Format command to run. To disable set to `''`. | `string` | `npm run format` | `false` |
| `lint_command` | Lint command to run. To disable set to `''`. | `string` | `npm run lint` | `false` |
| `build_command` | Build command to run. | `string` | `npm run build` | `false` |
Expand All @@ -133,6 +136,19 @@ Testing for node app, libraries and components.
| `pull-requests` | `write` | Only needed if job is used in a job with the `pull_request` trigger. |
| `contents` | `write` | Only needed if job is used in a job with the `push` trigger. |

### [Environment Setup](.github/workflows/environment-setup.yml)

Checks out the commit, set up the node env and setup the package manager with caching.

#### Inputs

| Name | Description | Type | Default | Required |
| ------------------- | -------------------------------- | -------- | ---------------------------- | -------- |
| `node_versions` | Node versions matrix to test on. | `string` | `['16.x', '17.x', '18.x']` | `false` |
| `package_manager` | Package manager to use. | `choice` | `npm` | `false` |
| `dependencies_type` | Dependencies type to install. | `choice` | `prod` | `false` |
| `registry_url` | Registry url to use. | `string` | `https://registry.npmjs.org` | `false` |

## Directory structure and file naming

> Reusable workflows are YAML-formatted files, very similar to any other workflow file. As with other workflow files, you locate reusable workflows in the `.github/workflows` directory of a repository. Subdirectories of the `workflows` directory are not supported.
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lint:
@echo "Lint all yaml files in repository"
yamllint . -s
actionlint
actionlint --ignore "^unexpected key \"options\" for \"inputs at workflow_call event\" section\. expected one of .*" --ignore "^invalid value \"choice\" for input type of workflow_call event. it must be one of .*"