Skip to content
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
17 changes: 10 additions & 7 deletions .github/workflows/__test-action-dependencies-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,27 @@ jobs:
steps:
# jscpd:ignore-start

- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Arrange - Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- id: setup-node
- name: Arrange - Setup Node.js runtime
id: arrange-setup-node
uses: ./actions/setup-node
with:
working-directory: ${{ matrix.working-directory }}

- name: Check that package manager is the expected one
id: check-package-manager
- name: Arrange - Verify expected package manager
id: arrange-check-package-manager
run: |
if [[ "${{ steps.setup-node.outputs.run-script-command }}" != "${{ matrix.package-manager }}"* ]]; then
if [[ "${{ steps.arrange-setup-node.outputs.run-script-command }}" != "${{ matrix.package-manager }}"* ]]; then
echo "Package manager is not ${{ matrix.package-manager }}"
exit 1
fi

# jscpd:ignore-end

- id: get-dependencies-cache
- name: Act - Run "dependencies-cache" action
id: act-get-dependencies-cache
uses: ./actions/dependencies-cache
with:
working-directory: ${{ matrix.working-directory }}
Expand All @@ -57,7 +60,7 @@ jobs:
storybook
unknown

- name: Check "dependencies-cache" configured cache
- name: Assert - Check "dependencies-cache" configured cache
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/__test-action-get-package-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,33 @@ jobs:
install-command: yarn install --frozen-lockfile
run-script-command: yarn
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Arrange - Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- id: get-package-manager
- name: Act - Run "get-package-manager" action
id: act-get-package-manager
uses: ./actions/get-package-manager
with:
working-directory: ${{ matrix.working-directory }}

- name: Check "get-package-manager" outputs
- name: Assert - Check "get-package-manager" outputs
run: |
if [ "${{ steps.get-package-manager.outputs.package-manager }}" != '${{ matrix.package-manager }}' ]; then
if [ "${{ steps.act-get-package-manager.outputs.package-manager }}" != '${{ matrix.package-manager }}' ]; then
echo "get-package-manager outputs result is not valid"
exit 1
fi

if [ "${{ steps.get-package-manager.outputs.cache-dependency-path }}" != '${{ matrix.cache-dependency-path }}' ]; then
if [ "${{ steps.act-get-package-manager.outputs.cache-dependency-path }}" != '${{ matrix.cache-dependency-path }}' ]; then
echo "get-package-manager outputs cache-dependency-path is not valid"
exit 1
fi

if [ "${{ steps.get-package-manager.outputs.install-command }}" != '${{ matrix.install-command }}' ]; then
if [ "${{ steps.act-get-package-manager.outputs.install-command }}" != '${{ matrix.install-command }}' ]; then
echo "get-package-manager outputs install-command is not valid"
exit 1
fi

if [ "${{ steps.get-package-manager.outputs.run-script-command }}" != '${{ matrix.run-script-command }}' ]; then
if [ "${{ steps.act-get-package-manager.outputs.run-script-command }}" != '${{ matrix.run-script-command }}' ]; then
echo "get-package-manager outputs run-script-command is not valid"
exit 1
fi
21 changes: 13 additions & 8 deletions .github/workflows/__test-action-has-installed-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,25 @@ jobs:
package-manager: yarn
lock-file: yarn.lock
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Arrange - Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- id: setup-node
- name: Arrange - Setup Node.js runtime
id: arrange-setup-node
uses: ./actions/setup-node
with:
working-directory: ${{ matrix.working-directory }}

- name: Check that package manager is the expected one
id: check-package-manager
- name: Arrange - Verify expected package manager
id: arrange-check-package-manager
run: |
if [[ "${{ steps.setup-node.outputs.run-script-command }}" != "${{ matrix.package-manager }}"* ]]; then
if [[ "${{ steps.arrange-setup-node.outputs.run-script-command }}" != "${{ matrix.package-manager }}"* ]]; then
echo "Package manager is not ${{ matrix.package-manager }}"
exit 1
fi

- id: has-installed-dependencies
- name: Act - Run "has-installed-dependencies" action
id: act-has-installed-dependencies
uses: ./actions/has-installed-dependencies
with:
working-directory: ${{ matrix.working-directory }}
Expand All @@ -57,13 +60,15 @@ jobs:
storybook
unknown

- name: Check "has-installed-dependencies" outputs
- name: Assert - Check "has-installed-dependencies" outputs
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
INSTALLED_DEPENDENCIES: ${{ steps.act-has-installed-dependencies.outputs.installed-dependencies }}
with:
script: |
const assert = require("assert");

const installedDependenciesOutput = `${{ steps.has-installed-dependencies.outputs.installed-dependencies }}`;
const installedDependenciesOutput = process.env.INSTALLED_DEPENDENCIES;
assert(installedDependenciesOutput.length, `"installed-dependencies" output is empty`);

// Check if is valid JSON
Expand Down
54 changes: 48 additions & 6 deletions .github/workflows/__test-action-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,76 @@ jobs:
include:
- working-directory: tests/npm
artifact-suffix: npm
install-command: npm install --force --legacy-peer-deps --no-audit --no-fund --loglevel=warn
- working-directory: tests/pnpm
artifact-suffix: pnpm
install-command: pnpm install
- working-directory: tests/pnpm-package-manager
artifact-suffix: pnpm-package-manager
install-command: pnpm install
- working-directory: tests/yarn
artifact-suffix: yarn
install-command: yarn add
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Arrange - Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- id: package
- name: Act - Run "package" action
id: act-package
uses: ./actions/package
with:
working-directory: ${{ matrix.working-directory }}
artifact-name: package-tarball-${{ matrix.artifact-suffix }}

- name: Check "package" outputs
- name: Assert - Check "package" outputs
env:
PACKAGE_TARBALL_PATH: ${{ steps.act-package.outputs.package-tarball-path }}
PACKAGE_TARBALL_ARTIFACT_ID: ${{ steps.act-package.outputs.package-tarball-artifact-id }}
run: |
if [ -z "${{ steps.package.outputs.package-tarball-path }}" ]; then
if [ -z "$PACKAGE_TARBALL_PATH" ]; then
echo "package-tarball-path output is empty"
exit 1
fi

if [ ! -f "${{ steps.package.outputs.package-tarball-path }}" ]; then
if [ ! -f "$PACKAGE_TARBALL_PATH" ]; then
echo "Generated package tarball does not exist"
exit 1
fi

if [ -z "${{ steps.package.outputs.package-tarball-artifact-id }}" ]; then
if [ -z "$PACKAGE_TARBALL_ARTIFACT_ID" ]; then
echo "package-tarball-artifact-id output is empty"
exit 1
fi

- name: Arrange - Configure Node.js version
run: echo "lts/*" > .nvmrc
working-directory: ${{ matrix.working-directory }}

- name: Arrange - Setup Node.js runtime
id: arrange-setup-node
uses: ./actions/setup-node
with:
working-directory: ${{ matrix.working-directory }}

- name: Assert - Download package tarball artifact by ID
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
artifact-ids: ${{ steps.act-package.outputs.package-tarball-artifact-id }}
path: ${{ runner.temp }}
skip-decompress: true

- name: Assert - Check downloaded package tarball artifact
env:
TARBALL_PATH: ${{ steps.act-package.outputs.package-tarball-path }}
INSTALL_COMMAND: ${{ matrix.install-command }}
working-directory: ${{ runner.temp }}
run: |
tarball_name="$(basename "$TARBALL_PATH")"

if [ ! -f "./$tarball_name" ]; then
echo "Downloaded package tarball artifact does not exist"
exit 1
fi

# Install the tarball to verify it's a valid npm package
$INSTALL_COMMAND "./$tarball_name"
26 changes: 12 additions & 14 deletions .github/workflows/__test-action-setup-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,36 @@ jobs:
matrix:
include:
- working-directory: tests/npm
package-manager: npm
lock-file: package-lock.json
run-script-command: npm run

- working-directory: tests/pnpm
package-manager: pnpm
lock-file: pnpm-lock.yaml
run-script-command: pnpm

- working-directory: tests/pnpm-package-manager
package-manager: pnpm
lock-file: pnpm-lock.yaml
run-script-command: pnpm

- working-directory: tests/yarn
package-manager: yarn
lock-file: yarn.lock
run-script-command: yarn
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Arrange - Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- run: echo "lts/*" > .nvmrc
- name: Arrange - Configure Node.js version
run: echo "lts/*" > .nvmrc
working-directory: ${{ matrix.working-directory }}

- id: setup-node
- name: Act - Run "setup-node" action
id: act-setup-node
uses: ./actions/setup-node
with:
working-directory: ${{ matrix.working-directory }}

- name: Check "setup-node" outputs
- name: Assert - Check "setup-node" outputs
env:
RUN_SCRIPT_COMMAND: ${{ steps.act-setup-node.outputs.run-script-command }}
EXPECTED_RUN_SCRIPT_COMMAND: ${{ matrix.run-script-command }}
run: |
if [ "${{ steps.setup-node.outputs.run-script-command }}" != "${{ matrix.run-script-command }}" ]; then
echo "get-package-manager outputs run-script-command is not valid"
if [ "$RUN_SCRIPT_COMMAND" != "$EXPECTED_RUN_SCRIPT_COMMAND" ]; then
echo "setup-node outputs run-script-command is not valid"
exit 1
fi
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
{"coverage": "github"}

arrange-with-container:
name: Arrange - Build container image for CI workflow
permissions:
id-token: write
contents: read
Expand Down
64 changes: 44 additions & 20 deletions actions/package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Package

<div align="center">
<img src="https://opengraph.githubassets.com/07d39741f0be451a378f8b498a7b573d5949e0ae7da27c750abebd8d586a5331/hoverkraft-tech/ci-github-nodejs" width="60px" align="center" alt="Package" />
<img src="https://opengraph.githubassets.com/d1a1e1a571ea2f219133f714e773a06b07d3efc23fa42a8746c3f02c80af02cf/hoverkraft-tech/ci-github-nodejs" width="60px" align="center" alt="Package" />
</div>

---
Expand All @@ -30,7 +30,7 @@ Action to create and upload an npm package tarball from a Node.js project
## Usage

```yaml
- uses: hoverkraft-tech/ci-github-nodejs/actions/package@775ce0902c528062cc94141dd7d13261083b752a # 0.22.0
- uses: hoverkraft-tech/ci-github-nodejs/actions/package@edadd27d0f6a1b2dd558aec095acb6496aa1916b # main
with:
# Working directory where dependencies are installed for packaging.
# Can be absolute or relative to the repository root.
Expand Down Expand Up @@ -67,20 +67,20 @@ Action to create and upload an npm package tarball from a Node.js project

## Inputs

| **Input** | **Description** | **Required** | **Default** |
| ------------------------- | ------------------------------------------------------------------------------------------- | ------------ | ------------------------- |
| **`working-directory`** | Working directory where dependencies are installed for packaging. | **false** | `.` |
| | Can be absolute or relative to the repository root. | | |
| **`package-directory`** | Optional package directory to version and pack. | **false** | - |
| | Can be absolute or relative to `working-directory`. | | |
| | Useful for monorepos where dependencies are installed at the root. | | |
| **`build-artifact-id`** | Optional build artifact ID to download before packaging. | **false** | - |
| | When provided, the artifact will be downloaded to the workspace. | | |
| **`build-artifact-path`** | Optional path to the build artifact contents relative to the workspace root. | **false** | `${{ github.workspace }}` |
| | Used to locate the files to be included in the package when a build artifact is downloaded. | | |
| **`version`** | Optional version to apply with `npm version` before packaging. | **false** | - |
| | The version is applied without creating a Git tag. | | |
| **`artifact-name`** | Name of the uploaded package tarball artifact | **false** | `package-tarball` |
| **Input** | **Description** | **Required** | **Default** |
| ------------------------- | ------------------------------------------------------------------------------------------- | ------------ | --------------------------- |
| **`working-directory`** | Working directory where dependencies are installed for packaging. | **false** | `.` |
| | Can be absolute or relative to the repository root. | | |
| **`package-directory`** | Optional package directory to version and pack. | **false** | - |
| | Can be absolute or relative to `working-directory`. | | |
| | Useful for monorepos where dependencies are installed at the root. | | |
| **`build-artifact-id`** | Optional build artifact ID to download before packaging. | **false** | - |
| | When provided, the artifact will be downloaded to the workspace. | | |
| **`build-artifact-path`** | Optional path to the build artifact contents relative to the workspace root. | **false** | `$\{\{ github.workspace }}` |
| | Used to locate the files to be included in the package when a build artifact is downloaded. | | |
| **`version`** | Optional version to apply with `npm version` before packaging. | **false** | - |
| | The version is applied without creating a Git tag. | | |
| **`artifact-name`** | Name of the uploaded package tarball artifact | **false** | `package-tarball` |

<!-- inputs:end -->
<!-- secrets:start -->
Expand All @@ -89,13 +89,37 @@ Action to create and upload an npm package tarball from a Node.js project

## Outputs

| **Output** | **Description** |
| --------------------------------- | ---------------------------------------------- |
| **`package-tarball-path`** | Absolute path to the generated package tarball |
| **`package-tarball-artifact-id`** | Artifact ID of the uploaded package tarball |
| **Output** | **Description** |
| --------------------------------- | --------------------------------------------------------------------------------- |
| **`package-tarball-path`** | Absolute path to the generated package tarball |
| **`package-tarball-artifact-id`** | Artifact ID of the uploaded package tarball (download with skip-decompress: true) |

<!-- outputs:end -->
<!-- examples:start -->

## Examples

```yaml
jobs:
package:
runs-on: ubuntu-latest
outputs:
package-tarball-artifact-id: ${{ steps.package.outputs.package-tarball-artifact-id }}
steps:
- id: package
uses: hoverkraft-tech/ci-github-nodejs/actions/package@edadd27d0f6a1b2dd558aec095acb6496aa1916b # main

consume:
needs: package
runs-on: ubuntu-latest
steps:
- name: Download package tarball by artifact ID
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
artifact-ids: ${{ needs.package.outputs.package-tarball-artifact-id }}
skip-decompress: true
```

<!-- examples:end -->
<!-- contributing:start -->

Expand Down
Loading
Loading