Skip to content

Commit 766cd85

Browse files
committed
feat(actions): add package dir input for package action
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent f81c0d6 commit 766cd85

File tree

2 files changed

+42
-67
lines changed

2 files changed

+42
-67
lines changed

actions/package/README.md

Lines changed: 22 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,12 @@
33
# ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Package
44

55
<div align="center">
6-
<img src="https://opengraph.githubassets.com/0b6ae3eedb6db1767aa580568b2b8537a53dce2d0080866a902253850c40f7bd/hoverkraft-tech/ci-github-nodejs" width="60px" align="center" alt="Package" />
6+
<img src="https://opengraph.githubassets.com/4f96f3249d1151f63aed208674e7891f457414a36b8c7799ccaa893c5a4beca3/hoverkraft-tech/ci-github-nodejs" width="60px" align="center" alt="Package" />
77
</div>
88

99
---
1010

1111
<!-- header:end -->
12-
13-
## Overview
14-
15-
Action to create and upload an npm package tarball from a Node.js project.
16-
17-
## Usage
18-
19-
```yaml
20-
- uses: hoverkraft-tech/ci-github-nodejs/actions/package@c9d9d041ba4ef35695ee469c4782fa6a8bbebbcc # 0.21.2
21-
with:
22-
# Working directory where the package is packed.
23-
# Can be absolute or relative to the repository root.
24-
#
25-
# Default: `.`
26-
working-directory: .
27-
28-
# Optional build artifact ID to download before packaging.
29-
build-artifact-id: ""
30-
31-
# Optional version to apply with `npm version` before packaging.
32-
# The version is applied without creating a git tag.
33-
version: ""
34-
35-
# Name of the uploaded package tarball artifact
36-
# Default: `package-tarball`
37-
artifact-name: package-tarball
38-
```
39-
40-
## Inputs
41-
42-
| **Input** | **Description** | **Required** | **Default** |
43-
| ----------------------- | ---------------------------------------------------------------- | ------------ | ----------------- |
44-
| **`working-directory`** | Working directory where the package is packed. | **false** | `.` |
45-
| | Can be absolute or relative to the repository root. | | |
46-
| **`build-artifact-id`** | Optional build artifact ID to download before packaging. | **false** | - |
47-
| | When provided, the artifact will be downloaded to the workspace. | | |
48-
| **`version`** | Optional version to apply with `npm version` before packaging. | **false** | - |
49-
| | The version is applied without creating a Git tag. | | |
50-
| **`artifact-name`** | Name of the uploaded package tarball artifact | **false** | `package-tarball` |
51-
52-
## Outputs
53-
54-
| **Output** | **Description** |
55-
| --------------------------------- | ---------------------------------------------- |
56-
| **`package-tarball-path`** | Absolute path to the generated package tarball |
57-
| **`package-tarball-artifact-id`** | Artifact ID of the uploaded package tarball |
58-
59-
## Contributing
60-
61-
Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-nodejs/blob/main/CONTRIBUTING.md) for more details.
6212
<!-- badges:start -->
6313

6414
[![Marketplace](https://img.shields.io/badge/Marketplace-package-blue?logo=github-actions)](https://github.com/marketplace/actions/package)
@@ -80,14 +30,19 @@ Action to create and upload an npm package tarball from a Node.js project
8030
## Usage
8131

8232
```yaml
83-
- uses: hoverkraft-tech/ci-github-nodejs/actions/package@775ce0902c528062cc94141dd7d13261083b752a # 0.22.0
33+
- uses: hoverkraft-tech/ci-github-nodejs/actions/package@f81c0d625c99d16be16427d82737651df1af5ee9 # main
8434
with:
85-
# Working directory where the package is packed.
35+
# Working directory where dependencies are installed for packaging.
8636
# Can be absolute or relative to the repository root.
8737
#
8838
# Default: `.`
8939
working-directory: .
9040

41+
# Optional package directory to version and pack.
42+
# Can be absolute or relative to `working-directory`.
43+
# Useful for monorepos where dependencies are installed at the root.
44+
package-directory: ""
45+
9146
# Optional build artifact ID to download before packaging.
9247
# When provided, the artifact will be downloaded to the workspace.
9348
build-artifact-id: ""
@@ -112,17 +67,20 @@ Action to create and upload an npm package tarball from a Node.js project
11267
11368
## Inputs
11469
115-
| **Input** | **Description** | **Required** | **Default** |
116-
| ------------------------- | ------------------------------------------------------------------------------------------- | ------------ | ------------------------- |
117-
| **`working-directory`** | Working directory where the package is packed. | **false** | `.` |
118-
| | Can be absolute or relative to the repository root. | | |
119-
| **`build-artifact-id`** | Optional build artifact ID to download before packaging. | **false** | - |
120-
| | When provided, the artifact will be downloaded to the workspace. | | |
121-
| **`build-artifact-path`** | Optional path to the build artifact contents relative to the workspace root. | **false** | `${{ github.workspace }}` |
122-
| | Used to locate the files to be included in the package when a build artifact is downloaded. | | |
123-
| **`version`** | Optional version to apply with `npm version` before packaging. | **false** | - |
124-
| | The version is applied without creating a Git tag. | | |
125-
| **`artifact-name`** | Name of the uploaded package tarball artifact | **false** | `package-tarball` |
70+
| **Input** | **Description** | **Required** | **Default** |
71+
| ------------------------- | ------------------------------------------------------------------------------------------- | ------------ | --------------------------- |
72+
| **`working-directory`** | Working directory where dependencies are installed for packaging. | **false** | `.` |
73+
| | Can be absolute or relative to the repository root. | | |
74+
| **`package-directory`** | Optional package directory to version and pack. | **false** | - |
75+
| | Can be absolute or relative to `working-directory`. | | |
76+
| | Useful for monorepos where dependencies are installed at the root. | | |
77+
| **`build-artifact-id`** | Optional build artifact ID to download before packaging. | **false** | - |
78+
| | When provided, the artifact will be downloaded to the workspace. | | |
79+
| **`build-artifact-path`** | Optional path to the build artifact contents relative to the workspace root. | **false** | `$\{\{ github.workspace }}` |
80+
| | Used to locate the files to be included in the package when a build artifact is downloaded. | | |
81+
| **`version`** | Optional version to apply with `npm version` before packaging. | **false** | - |
82+
| | The version is applied without creating a Git tag. | | |
83+
| **`artifact-name`** | Name of the uploaded package tarball artifact | **false** | `package-tarball` |
12684

12785
<!-- inputs:end -->
12886
<!-- secrets:start -->

actions/package/action.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ branding:
88
inputs:
99
working-directory:
1010
description: |
11-
Working directory where the package is packed.
11+
Working directory where dependencies are installed for packaging.
1212
Can be absolute or relative to the repository root.
1313
required: false
1414
default: "."
15+
package-directory:
16+
description: |
17+
Optional package directory to version and pack.
18+
Can be absolute or relative to `working-directory`.
19+
Useful for monorepos where dependencies are installed at the root.
20+
required: false
21+
default: ""
1522
build-artifact-id:
1623
description: |
1724
Optional build artifact ID to download before packaging.
@@ -77,6 +84,7 @@ runs:
7784
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
7885
env:
7986
WORKING_DIRECTORY: ${{ steps.working-directory.outputs.absolute-path }}
87+
PACKAGE_DIRECTORY: ${{ inputs.package-directory }}
8088
RELEASE_VERSION: ${{ inputs.version }}
8189
RUNNER_TEMP: ${{ runner.temp }}
8290
with:
@@ -85,19 +93,28 @@ runs:
8593
const path = require('node:path');
8694
8795
const workingDirectory = process.env.WORKING_DIRECTORY;
96+
const packageDirectoryInput = (process.env.PACKAGE_DIRECTORY || '').trim();
97+
const packageDirectory = packageDirectoryInput ? path.resolve(workingDirectory, packageDirectoryInput) : workingDirectory;
8898
core.debug(`Running in working directory: ${workingDirectory}`);
99+
core.debug(`Package directory: ${packageDirectory}`);
89100
process.chdir(workingDirectory);
90101
91102
const releaseVersion = (process.env.RELEASE_VERSION || '').trim();
92103
const runnerTemp = process.env.RUNNER_TEMP;
93104
105+
const packageJsonPath = path.join(packageDirectory, 'package.json');
106+
if (!fs.existsSync(packageJsonPath)) {
107+
core.setFailed(`package.json not found in package directory: ${packageDirectory}`);
108+
return;
109+
}
110+
94111
if (releaseVersion) {
95112
core.info(`Updating package version to provided release version: ${releaseVersion}`);
96113
const npmVersionResult = await exec.getExecOutput(
97114
'npm',
98115
['version', releaseVersion, '--no-git-tag-version', '--no-workspaces-update'],
99116
{
100-
cwd: workingDirectory,
117+
cwd: packageDirectory,
101118
ignoreReturnCode: true,
102119
},
103120
);
@@ -109,7 +126,7 @@ runs:
109126
}
110127
111128
const npmPackResult = await exec.getExecOutput('npm', ['pack', '--json', '--pack-destination', runnerTemp], {
112-
cwd: workingDirectory,
129+
cwd: packageDirectory,
113130
ignoreReturnCode: true,
114131
});
115132

0 commit comments

Comments
 (0)