From 59cac3d19216b4416aa8d2808ff807fef642356a Mon Sep 17 00:00:00 2001 From: Luis Beu Date: Mon, 2 Oct 2023 00:54:40 +0200 Subject: [PATCH 1/3] Add bun support --- .github/workflows/environment-setup.yml | 58 ++++++++++++++++++++++++ .github/workflows/github-npm-publish.yml | 18 +++++--- .github/workflows/node-qa-testing.yml | 17 ++++--- .github/workflows/npm-publish.yml | 17 ++++--- 4 files changed, 90 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/environment-setup.yml diff --git a/.github/workflows/environment-setup.yml b/.github/workflows/environment-setup.yml new file mode 100644 index 0000000..95ae61d --- /dev/null +++ b/.github/workflows/environment-setup.yml @@ -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' || '' }} diff --git a/.github/workflows/github-npm-publish.yml b/.github/workflows/github-npm-publish.yml index 7cbdc8b..24e0bcc 100644 --- a/.github/workflows/github-npm-publish.yml +++ b/.github/workflows/github-npm-publish.yml @@ -11,6 +11,13 @@ default: "18" required: false type: string + package_manager: + default: npm + description: Package manager to use + options: + - npm + - bun + type: choice jobs: publish: @@ -18,14 +25,11 @@ jobs: 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 diff --git a/.github/workflows/node-qa-testing.yml b/.github/workflows/node-qa-testing.yml index c7a6733..121e850 100644 --- a/.github/workflows/node-qa-testing.yml +++ b/.github/workflows/node-qa-testing.yml @@ -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: @@ -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}} diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 89b71e4..28f27b1 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -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 @@ -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='' From ced6be87dff815e1a0e731acfcdcbba0b6a801ef Mon Sep 17 00:00:00 2001 From: Luis Beu Date: Thu, 5 Oct 2023 15:21:35 +0200 Subject: [PATCH 2/3] add ignore for unsupported feature --- .github/workflows/internal-linting.yml | 2 +- makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/internal-linting.yml b/.github/workflows/internal-linting.yml index d17ff96..4fb338d 100644 --- a/.github/workflows/internal-linting.yml +++ b/.github/workflows/internal-linting.yml @@ -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 .*" diff --git a/makefile b/makefile index 59754c9..0ef8962 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ lint: @echo "Lint all yaml files in repository" yamllint . -s - actionlint \ No newline at end of file + 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 .*" \ No newline at end of file From 860ebbb307895c229e4c0d866fbdeecea0849a87 Mon Sep 17 00:00:00 2001 From: Luis Beu Date: Thu, 5 Oct 2023 15:34:35 +0200 Subject: [PATCH 3/3] Update readme --- README.md | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c90f695..2a8bad7 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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` | @@ -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.