Skip to content

Commit d008cd9

Browse files
committed
deploy: allow 'filename_pattern' input
This change adds a new input `filename_pattern:` to be able to customize the filename pattern to deploy a set of files in a directory to a hub.
1 parent 4601021 commit d008cd9

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,36 @@ jobs:
223223

224224
**Important:** make sure you adapt the name of the branch your deployment will target, _aka_ your destination branch if relevant (`main` in the example above), replace `<BUMP_HUB_ID>` with your Bump.sh hub slug or id and point `file:` to your local API definition file folder (`docs/`).
225225

226+
Please note, by default, only files named `{slug}-api.[format]` are deployed. Where `{slug}` is a name for your API and `[format]` is either `yaml` or `json`. Adjust to your file naming convention using the `filename_pattern:` input.
227+
228+
Note that it _can_ include `*` wildcard special character, but **must** include the `{slug}` filter to extract your documentation’s slug from the filename. The pattern can also have any other optional fixed characters.
229+
230+
Here’s a practical example. Let's assume that you have the following files in your `path/to/apis/` directory:
231+
232+
```
233+
path/to/apis
234+
└─ private-api-users-service.json
235+
└─ partner-api-payments-service.yml
236+
└─ public-api-contracts-service.yml
237+
└─ data.json
238+
└─ README.md
239+
```
240+
241+
In order to deploy the 3 services API definition files from this folder (`private-api-users-service.json`, `partner-api-payments-service.yml` and `public-api-contracts-service.yml`), you can set call the action like this:
242+
243+
```
244+
[...]
245+
steps:
246+
- name: Checkout
247+
uses: actions/checkout@v4
248+
- name: Deploy API documentation
249+
uses: bump-sh/github-action@v1
250+
with:
251+
hub: <BUMP_HUB_ID>
252+
token: ${{secrets.BUMP_TOKEN}}
253+
file: docs/
254+
filename_pattern: '*-api-{slug}-service'
255+
```
226256

227257
## Inputs
228258

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: bump.sh
55

66
inputs:
77
file:
8-
description: "Relative path to an API definition file (OpenAPI or AsyncAPI)"
8+
description: "Relative path to an API definition file (OpenAPI or AsyncAPI) or a directory of definition files (when deploying to a Hub)"
99
required: true
1010
default: api-contract.yml
1111
doc:
@@ -26,6 +26,9 @@ inputs:
2626
default: false
2727
overlay:
2828
description: "A list of OpenAPI Overlays to apply to the API definition before deploying it. Overlays are applied in the order they are provided."
29+
filename_pattern:
30+
default: "{slug}-api"
31+
description: "Filename pattern to extract the documentation slug from filenames when deploying a DIRECTORY. Pattern uses only '*' and '{slug}' as special characters to extract the slug from a filename without extension. Only used with the 'hub' input when deploying a whole directory ."
2932
runs:
3033
using: node20
3134
main: dist/index.js

src/main.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export async function run(): Promise<void> {
2121
const command: string = core.getInput('command') || 'deploy';
2222
const expires: string | undefined = core.getInput('expires');
2323
const failOnBreaking: boolean = core.getInput('fail_on_breaking') === 'true';
24+
const filenamePattern: string = core.getInput('filename_pattern');
2425
const cliParams = [file];
2526

2627
// HELP: this condition on the import meta dirname is here only
@@ -35,6 +36,12 @@ export async function run(): Promise<void> {
3536

3637
if (hub) {
3738
deployParams = deployParams.concat(['--auto-create', '--hub', hub]);
39+
if (filenamePattern) {
40+
deployParams = deployParams.concat([
41+
'--filename-pattern',
42+
`'${filenamePattern}'`,
43+
]);
44+
}
3845
}
3946

4047
if (branch) {

tests/main.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@ describe('main.ts', () => {
6666
);
6767
});
6868

69+
it('test action run deploy entire directory in hub with custom filename pattern correctly', async () => {
70+
mockInputs({
71+
file: 'my-file.yml',
72+
doc: undefined,
73+
hub: 'my-hub',
74+
token: 'SECRET',
75+
filename_pattern: 'source-{slug}-*',
76+
});
77+
78+
await run();
79+
80+
expect(bump.Deploy.run).toHaveBeenCalledWith(
81+
[
82+
'my-file.yml',
83+
'--token',
84+
'SECRET',
85+
'--auto-create',
86+
'--hub',
87+
'my-hub',
88+
'--filename-pattern',
89+
"'source-{slug}-*'",
90+
],
91+
'.',
92+
);
93+
});
94+
6995
it('test action run deploy correctly', async () => {
7096
// Set the action's inputs as return values from core.getInput().
7197
mockInputs({ file: 'my-file.yml', doc: 'my-doc', token: 'SECRET' });

0 commit comments

Comments
 (0)