From 2436de00ee3bd825f5446c135c15b57a7ed66894 Mon Sep 17 00:00:00 2001 From: Diego Arce Date: Wed, 20 Apr 2022 20:19:23 -0600 Subject: [PATCH 1/2] fix: add options documentation Signed-off-by: Diego Arce --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 12ef4a3..33b1ba2 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,19 @@ Using yarn: yarn add joi @bits-cr/middy-joi-validator ``` +## Options +- inputSchema (Joi.AnySchema object) (optional): The Joi schema object that will be used to validate the input body (request.event.body) of the Lambda handler. +- inputValidationOptions (ValidationOptions 'joi') (optional): This can be used to override the options for the joi any.validate method for the input schema. More info: [joi.dev - any.validate(value, [options]) ](https://joi.dev/api/?v=latest#anyvalidatevalue-options). `Defaults: Joi defaults options` +- preserveRawBody (boolean) (optional): This can be used to preserve the original input body at `event.rawBody`. `Defaults: false` +- inputErrorValidationMessage (string) (optional): This can be used to replace the error message in case of an input schema validation error. +- headersSchema (Joi.AnySchema object) (optional): The Joi schema object that will be used to validate the input headers (request.event.headers) of the Lambda handler. +- headersValidationOptions (ValidationOptions 'joi') (optional): This can be used to override the options for the joi any.validate method for the headers schema. More info: [joi.dev - any.validate(value, [options]) ](https://joi.dev/api/?v=latest#anyvalidatevalue-options). `Defaults: { allowUnknown: true }` +- preserveRawHeaders (boolean) (optional): This can be used to preserve the original input headers at `event.rawHeaders`. `Defaults: false` +- headersErrorValidationMessage (string) (optional): This can be used to replace the error message in case of an headers schema validation error. +- outputSchema (Joi.AnySchema object) (optional): The Joi schema object that will be used to validate the output (request.response) of the Lambda handler +- outputValidationOptions (ValidationOptions 'joi') (optional): This can be used to override the options for the joi any.validate method for the input schema. More info: [joi.dev - any.validate(value, [options]) ](https://joi.dev/api/?v=latest#anyvalidatevalue-options). `Defaults: Joi defaults options` +- outputErrorValidationMessage (string) (optional): This can be used to replace the error message in case of an output schema validation error. + ## Documentation and examples ```javascript //# handler.js # From 40882436e5f10397d595ac92a8dd7a61b60095f4 Mon Sep 17 00:00:00 2001 From: Diego Arce Date: Wed, 20 Apr 2022 20:32:14 -0600 Subject: [PATCH 2/2] feat: enhances GitHub release pipeline Signed-off-by: Diego Arce --- .github/workflows/release.yml | 171 +++++++++++++++++++++++++--------- 1 file changed, 127 insertions(+), 44 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bae8aec..348e81f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Create new release +name: Generate and publish NPM package on: push: @@ -7,62 +7,145 @@ on: - 'beta' jobs: - release: - + package: + name: Generate new package runs-on: ubuntu-latest - + outputs: + version: ${{ steps.vars.outputs.version }} + git-tag: ${{ steps.vars.outputs.git-tag }} + release-filename: ${{ steps.vars.outputs.release-filename }} + artifact-name: ${{ steps.vars.outputs.artifact-name }} steps: - name: Checkout repo id: checkout uses: actions/checkout@v3 - - name: Use Node.js - id: use-nodejs - uses: actions/setup-node@v3 + - name: Import GPG key for bot + id: bot-signing-key + uses: crazy-max/ghaction-import-gpg@v4 with: - node-version: '14.x' - registry-url: 'https://registry.npmjs.org' - - name: Install dependencies - id: install-dependencies - run: yarn install --frozen-lockfile - - name: Execute tests - id: yarn-test - run: yarn test - - name: Prepare git user + gpg_private_key: ${{ secrets.BOT_GPG_SIGNING_KEY }} + passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} + fingerprint: "F0637CD9BCDAACC51D7976F3071E232FF33B2800" + - name: Prepare git user for bot run: | - git config --global user.name "github-actions[bot]" - git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - - name: Create new version - run: | - yarn config set version-git-tag true - yarn version --patch - - name: Execute building - id: yarn-build - run: yarn build + git config --global user.name "arce-bot" + git config --global user.email "bot@arce.cr" + git config --global user.signingkey $KEY_ID + git config --global commit.gpgsign true + env: + KEY_ID: ${{ steps.bot-signing-key.outputs.keyid }} + - name: Create prerelease version + if: ${{ github.ref_name == 'beta' }} + id: yarn-prerelease + run: yarn version --prerelease --preid beta + - name: Create patch version + if: ${{ github.ref_name == 'main' }} + id: yarn-patch + run: yarn version --patch + - name: Get version number + id: vars + run: | + echo ::set-output name=version::$(sed -En "s/$VERSION_REGEX/\1/p" package.json) + echo ::set-output name=git-tag::$(sed -En "s/$VERSION_REGEX/refs\/tags\/v\1/p" package.json) + echo ::set-output name=release-filename::$(sed -En "s/$VERSION_REGEX/bits-cr-middy-joi-validator-v\1.tgz/p" package.json) + echo ::set-output name=artifact-name::$(sed -En "s/$VERSION_REGEX/npm-package-v\1/p" package.json) + env: + VERSION_REGEX: .*"version".+"(([0-9]+\.[0-9]+\.[0-9]+)(-beta\.[0-9]+)*)".* - name: Generate package id: yarn-pack - run: yarn pack --filename bits-cr-middy-joi-validator.tgz + run: yarn pack - name: Upload package to artifacts id: upload-tgz-artifact uses: actions/upload-artifact@v3 with: - name: bits-cr-middy-joi-validator.tgz - path: bits-cr-middy-joi-validator.tgz - - name: Publish to npmjs.org - id: publish-to-npm - run: yarn publish bits-cr-middy-joi-validator.tgz - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - name: Setup github npm registry - id: registry-npm-github - uses: actions/setup-node@v3 - with: - registry-url: 'https://npm.pkg.github.com' - - name: Publish to npm.pkg.github.com - id: publish-to-npm-github - run: yarn publish bits-cr-middy-joi-validator.tgz - env: - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + name: ${{ steps.vars.outputs.artifact-name }} + path: | + ${{ steps.vars.outputs.release-filename }} + package.json + if-no-files-found: error - name: Push changes and release tag + id: git-push run: | git push origin - git push origin --tags \ No newline at end of file + git push origin --tags + - name: Create Github.com prerelease + if: ${{ github.ref_name == 'beta' }} + uses: softprops/action-gh-release@v1 + with: + prerelease: true + name: ${{ steps.vars.outputs.version }} + tag_name: ${{ steps.vars.outputs.git-tag }} + files: | + ${{ steps.vars.outputs.release-filename }} + - name: Create Github.com release + if: ${{ github.ref_name == 'main' }} + uses: softprops/action-gh-release@v1 + with: + name: ${{ steps.vars.outputs.version }} + tag_name: ${{ steps.vars.outputs.git-tag }} + files: | + ${{ steps.vars.outputs.release-filename }} + - name: Create Github.com release + if: ${{ github.ref_name == 'main' }} + uses: softprops/action-gh-release@v1 + with: + name: ${{ steps.vars.outputs.version }} + tag_name: ${{ steps.vars.outputs.git-tag }} + files: | + ${{ steps.vars.outputs.release-filename }} + publish-npmjs: + name: Publish package to npmjs + runs-on: ubuntu-latest + needs: + - package + steps: + - name: Setup npm and registry + id: registry-npm-npmjs + uses: actions/setup-node@v3 + with: + registry-url: 'https://registry.npmjs.org' + - name: Download package + id: download + uses: actions/download-artifact@v3 + with: + name: ${{ needs.package.outputs.artifact-name }} + - name: Publish beta to npmjs.org + if: ${{ github.ref_name == 'beta' }} + id: publish-beta-to-npm + run: yarn publish --tag beta ${{ steps.download.outputs.download-path }}/${{ needs.package.outputs.release-filename }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Publish to npmjs.org + if: ${{ github.ref_name == 'main' }} + id: publish-to-npm + run: yarn publish ${{ steps.download.outputs.download-path }}/${{ needs.package.outputs.release-filename }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + publish-npmgithub: + name: Publish package to npm.pkg.github.com + runs-on: ubuntu-latest + needs: + - package + steps: + - name: Setup npm and registry + id: registry-npm-github + uses: actions/setup-node@v3 + with: + registry-url: "https://npm.pkg.github.com" + - name: Download package + id: download + uses: actions/download-artifact@v3 + with: + name: ${{ needs.package.outputs.artifact-name }} + - name: Publish beta to npm.pkg.github.com + if: ${{ github.ref_name == 'beta' }} + id: publish-beta-to-npm + run: yarn publish --tag beta ${{ steps.download.outputs.download-path }}/${{ needs.package.outputs.release-filename }} + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Publish to npm.pkg.github.com + if: ${{ github.ref_name == 'main' }} + id: publish-to-npm + run: yarn publish ${{ steps.download.outputs.download-path }}/${{ needs.package.outputs.release-filename }} + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file