Skip to content

Commit

Permalink
Merge pull request #7 from arcezd/main
Browse files Browse the repository at this point in the history
update documentation and github release pipeline
  • Loading branch information
arcezd authored Apr 21, 2022
2 parents 58801b7 + 4088243 commit d063583
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 44 deletions.
171 changes: 127 additions & 44 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create new release
name: Generate and publish NPM package

on:
push:
Expand All @@ -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 "[email protected]"
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
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 }}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down

0 comments on commit d063583

Please sign in to comment.