Skip to content

Commit e38fb4b

Browse files
authored
refactor!: add test runner (#28)
this may break some users because the S3CMD_CONFIG environment variable is now used to place and use the s3cmd config file from ${process.env.RUNNER_TEMP}/s3cmd.conf. Users that read this file directly in their workflow need to adjust the path they are using. Signed-off-by: Nico Braun <[email protected]>
1 parent 91996c6 commit e38fb4b

12 files changed

+1048
-376
lines changed

.github/workflows/validate.yml

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: validate
23

34
on:
@@ -6,23 +7,31 @@ on:
67
branches: ["main"]
78
pull_request:
89
types:
9-
- opened
10-
- synchronize
11-
- reopened
12-
- ready_for_review
13-
10+
- opened
11+
- synchronize
12+
- reopened
13+
- ready_for_review
14+
1415
jobs:
1516
use_s3cmd:
1617
runs-on: ubuntu-latest
1718
name: Validate Project
1819
steps:
19-
- uses: actions/checkout@v2
20-
- run: |
21-
npm i
22-
mv dist/index.js old
23-
npm run build
24-
if cmp --silent -- old dist/index.js; then
25-
exit 0
26-
else
27-
exit 1
28-
fi
20+
- uses: actions/checkout@v2
21+
22+
- name: install dependencies
23+
run: npm ci
24+
25+
- name: verify dist is up to date
26+
run: |
27+
mv dist/index.js old
28+
npm run build
29+
if cmp --silent -- old dist/index.js; then
30+
exit 0
31+
else
32+
exit 1
33+
fi
34+
35+
- name: Run Tests
36+
run: npm run test
37+

README.md

+14-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ This action is a simple wrapper for [S3cmd](https://github.com/s3tools/s3cmd).
44

55
## Supported Providers
66

7-
Currently the below providers are supported, but it could be used with other providers too when using additional flags.
7+
Currently the below providers are supported, but it could be used with
8+
other providers too when using additional flags.
89

910
- AWS
1011
- DigitalOcean
@@ -22,9 +23,11 @@ Currently the below providers are supported, but it could be used with other pro
2223

2324
### `provider`
2425

25-
**Not Required** The s3 provider to use. Defaults to `linode`.
26+
**Not Required** The s3 provider to use. Defaults to `linode`.
2627

27-
Supported values: `aws`, `digitalocean`, `linode`, `scaleway`, `cloudflare`, `vultr`, `clevercloud`, `hcloud`, `synologyc2`, `wasabi`, `yandex`.
28+
Supported values: `aws`, `digitalocean`, `linode`, `scaleway`,
29+
`cloudflare`, `vultr`, `clevercloud`, `hcloud`, `synologyc2`, `wasabi`,
30+
`yandex`.
2831

2932
### `secret_key`
3033

@@ -40,7 +43,8 @@ Supported values: `aws`, `digitalocean`, `linode`, `scaleway`, `cloudflare`, `vu
4043

4144
### `account_id`
4245

43-
**Not Required** Cloudflare account ID. Only required when using Cloudflare R2.
46+
**Not Required** Cloudflare account ID. Only required when using
47+
Cloudflare R2.
4448

4549
## Example usage
4650

@@ -62,13 +66,17 @@ Supported values: `aws`, `digitalocean`, `linode`, `scaleway`, `cloudflare`, `vu
6266
6367
### Note
6468
65-
The region only matters when creating a new bucket with `mb`. In that case a different region apart from the default region can be provided ad hoc.
69+
The region only matters when creating a new bucket with `mb`. In that
70+
case a different region apart from the default region can be provided ad
71+
hoc.
6672

6773
```console
6874
s3cmd mb --region ap-south-1 s3://my-bucket
6975
```
7076

71-
For linode object storage this wont work though. The region must always be set to US. If you want to change the region on the fly you can still do ith with the below command.
77+
For linode object storage this wont work though. The region must always
78+
be set to US. If you want to change the region on the fly you can still
79+
do ith with the below command.
7280

7381
```console
7482
s3cmd mb --host ap-south-1.linodeobjects.com s3://my-bucket

action.test.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const assert = require("node:assert");
2+
const { readFileSync } = require("node:fs");
3+
const { join } = require("node:path");
4+
const { tests } = require("./src/providers");
5+
6+
const { RunOptions, RunTarget } = require("github-action-ts-run-api");
7+
8+
(async () => {
9+
for (const [provider, { giveInputs, wantLines }] of Object.entries(tests)) {
10+
console.log(`\n---\nTesting provider: ${provider}`);
11+
12+
const target = RunTarget.mainJs("action.yml");
13+
const options = RunOptions.create()
14+
.setFakeFsOptions({ rmFakedTempDirAfterRun: false })
15+
.setInputs({ ...giveInputs, provider });
16+
17+
const res = await target.run(options);
18+
try {
19+
assert.strictEqual(res.exitCode, 0);
20+
21+
const b = readFileSync(join(res.tempDirPath, "s3cmd.conf"));
22+
const data = b.toString();
23+
for (const line of wantLines) {
24+
assert.ok(data.includes(line), `${provider}: missing line: ${line}`);
25+
}
26+
} finally {
27+
res.cleanUpFakedDirs();
28+
}
29+
}
30+
})();

action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
---
12
name: "Use S3cmd"
23
description: "Use S3cmd cli to interact with s3 object storage"
34
branding:
45
icon: "award"
56
color: "green"
67
inputs:
8+
s3cmd_version:
9+
description: "s3cmd version to use (default: 2.4.0)"
10+
default: "2.4.0"
11+
required: false
712
provider:
813
description: "config provider to make it easier to use the cli as action"
914
default: "linode"

0 commit comments

Comments
 (0)