Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(ci): add basic CI tests and fix POST requests bug #68

Merged
merged 31 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d9e3e5c
Update everything
Shillaker Oct 31, 2023
4f1e419
Fix POST requests
Shillaker Oct 31, 2023
519b485
Formatting
Shillaker Oct 31, 2023
b3cf734
Formatting
Shillaker Nov 6, 2023
6f36650
Resurrect POST example
Shillaker Nov 6, 2023
04920c7
Fix formatting
Shillaker Nov 6, 2023
8e17d22
Add simple test
Shillaker Nov 6, 2023
2151899
Working local test
Shillaker Nov 6, 2023
cee3077
Docs and formatting
Shillaker Nov 6, 2023
320484d
Self-review
Shillaker Nov 6, 2023
94ed695
Review comments
Shillaker Nov 7, 2023
ea0fe4e
Add examples checks
Shillaker Nov 7, 2023
470604c
npm cache
Shillaker Nov 7, 2023
8b14b06
Default dir
Shillaker Nov 7, 2023
c9afc8b
More GHA syntax
Shillaker Nov 7, 2023
bc17c59
Formatting
Shillaker Nov 7, 2023
bb520d1
Tests only with 18
Shillaker Nov 7, 2023
622d45f
Install local version of framework
Shillaker Nov 7, 2023
a49d27d
Link in script
Shillaker Nov 7, 2023
23ab8fd
Reduce sleep
Shillaker Nov 7, 2023
d540f13
Remove workflow names
Shillaker Nov 7, 2023
56ae9c0
Update test
Shillaker Nov 7, 2023
59eed95
try to retrigger GHA
Shillaker Nov 7, 2023
8b1368b
Reinstate example runner
Shillaker Nov 7, 2023
159d91c
self-hosted runners
Shillaker Nov 8, 2023
a42dc6d
Revert self-hosted change
Shillaker Nov 8, 2023
06f6026
Fix package-locks
Shillaker Nov 8, 2023
d74350a
Add scope to link command
Shillaker Nov 8, 2023
8fbb9a5
Attempt linking
Shillaker Nov 8, 2023
4bafd68
Avoid starting twice
Shillaker Nov 8, 2023
475f3e4
Revert dodgy package-lock changes
Shillaker Nov 8, 2023
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
11 changes: 3 additions & 8 deletions .github/workflows/npmtest.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
name: npmtest

on:
push:
branches: ["main"]
Expand All @@ -20,18 +18,15 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up node ${{ matrix.node-version }}
- name: "Set up node ${{ matrix.node-version }}"
id: setup-node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install dependencies
- name: "Install dependencies"
run: npm ci

- name: Check formatting
run: npx prettier --check .

- name: Build package
- name: "Build package"
run: npm run build
14 changes: 6 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Publish to NPM

---
on:
release:
types: [published]
Expand All @@ -8,19 +7,18 @@ jobs:
release:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Setup Node
- name: "Set up Node"
uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "18.x"
registry-url: "https://registry.npmjs.org"

- name: Install dependencies and build
- name: "Install dependencies and build"
run: npm ci && npm run build

- name: Publish package on NPM
- name: "Publish package on NPM"
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
83 changes: 83 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: "Set up node ${{ matrix.node-version }}"
id: setup-node
uses: actions/setup-node@v4
with:
node-version: "18.x"
Bemilie marked this conversation as resolved.
Show resolved Hide resolved
cache: "npm"

- name: "Install dependencies"
run: npm ci

- name: "Check formatting"
run: npx prettier --check .

- name: "Run tests"
run: npm test

examples:
defaults:
run:
working-directory: ./examples

strategy:
matrix:
node-version: ["16.x", "18.x"]
example:
[
"not_stringified_body",
"print_event_context",
"stringified_body",
"upload_file_multipart",
"with_callback",
"with_event_components",
"with_http_get",
"with_http_post",
"with_object",
"with_promise",
]

runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: "Set up node ${{ matrix.node-version }}"
id: setup-node
uses: actions/setup-node@v4
with:
node-version: "${{ matrix.node-version }}"
cache: "npm"

- name: "Link top-level"
run: npm link

- name: "Install dependencies"
run: npm ci
working-directory: "examples"

- name: "Link local framework"
run: npm link @scaleway/serverless-functions
working-directory: "examples"

- name: "Run example"
run: node ${{ matrix.example }}/handler.js &
working-directory: "examples"

- name: "Wait for it to start"
run: sleep 1

- name: "Launch a request"
run: curl http://localhost:8080
working-directory: "examples"
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ By running a function locally like this, we can be sure it will work when deploy

You can find a number of examples in the [`examples` folder](examples/). These include:

- [Accessing the event context](examples/print_event_context)
- [Making HTTP GET requests](examples/with_http_services)
- [Making HTTP POST requests](examples/with_http_services)
- [Uploading files](examples/upload_file_multipart)
- [Using promises](examples/with_promise)
- [Using callbacks](examples/with_callback)
- [Interacting with HTTP services](examples/with_http_services)

## 🏡 Local testing

Expand Down
64 changes: 64 additions & 0 deletions docs/dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Development

To test your local version of this package, you can use [`npm link`](https://docs.npmjs.com/cli/v6/commands/npm-link).

You can do this from the `examples` directory with:

```sh
cd examples
npm link ..

node with_object/handler.js
```

## Tests

You can run tests locally with:

```sh
npm test
```

Make sure you have at least Node 18 installed (see below).

## Releasing

To release a new version:

- Update the version in `package.json`
- Create a PR (or add to an existing PR)
- Merge the PR to `main`
- Create a new Release [in Github](https://github.com/scaleway/serverless-functions-node/releases)

Please follow [Semantic Versioning](https://semver.org/) guidelines when deciding which version to go to.

## Managing multiple Node versions

The build runs on multiple versions of Node. To manage multiple Node versions locally, you can use [`nvm`](https://github.com/nvm-sh/nvm).

Once installed, you can install versions with:

```sh
# Install versions
nvm install 16
nvm install 18

# Check
nvm use 16
npm i
which node

nvm use 18
npm i
which node
```

From there, you can check the build:

```sh
nvm use 16
npm run build

nvm use 18
npm run build
```
Loading