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

Beta #3

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions .github/actions/common-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Common setup for JS
description: Configure tools every job in JS projects, node version, code artifact and dependency installation
branding:
icon: "cloud"
color: "green"
inputs:
aws-access-key-id:
description: Key to connect with AWS
required: true
type: string
aws-secret-access-key:
description: Secret key to connect with AWS
required: true
type: string
aws-region:
description: Region AWS
required: true
type: string
aws-domain:
description: AWS domain
required: true
type: string
runs:
using: "composite"
steps:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ inputs.aws-access-key-id }}
aws-secret-access-key: ${{ inputs.aws-secret-access-key }}
aws-region: ${{ inputs.aws-region }}
- name: Configure CodeArtifact
run: aws codeartifact login --tool npm --repository npm-store --domain ${{ inputs.aws-domain }} --domain-owner 115365964428 --namespace @platzi
shell: bash
- name: Configure yarn with CodeArtifact
run: echo always-auth=true >> ~/.npmrc
shell: bash
- name: Install dependencies
uses: bahmutov/npm-install@v1
80 changes: 80 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: platzi/Honeycomb library
on:
pull_request:
branches:
- '[0-9]+.x'
- 'master'
- 'next'
- 'beta'
- 'alpha'
- 'infra'
push:
branches:
- '[0-9]+.x'
- 'master'
- 'next'
- 'beta'
- 'alpha'
- 'infra'
jobs:
common:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Setup action
uses: ./.github/actions/common-setup
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
aws-domain: ${{ secrets.SR_CA_DOMAIN }}
release:
needs: common
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Setup action
uses: ./.github/actions/common-setup
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
aws-domain: ${{ secrets.SR_CA_DOMAIN }}
- name: Build
run: yarn build --filter=@platzi/honeycomb-workers
- name: Release
uses: cycjimmy/semantic-release-action@v3
with:
semantic_version: 19.0.3
branches: |
[
'+([0-9])?(.{+([0-9]),x}).x',
'master',
'next',
{name: 'beta', prerelease: true},
{name: 'alpha', prerelease: true},
{name: 'infra', prerelease: true}
]
extends: |
[email protected]
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/git@^10.0.0
working_directory: ./packages/testing
tag_format: platzi-testing-${version}
env:
GITHUB_TOKEN: ${{ secrets.GB_ACCESS_TOKEN }}
GH_TOKEN: ${{ secrets.GB_ACCESS_TOKEN }}
23 changes: 23 additions & 0 deletions run/queue-consumer-worker/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"private": true,
"name": "module-worker",
"version": "1.0.0",
"description": "A template for kick starting a Cloudflare Workers project",
"module": "./dist/index.mjs",
"scripts": {
"build": "rollup -c",
"test": "echo \"Error: no test specified\" && exit 1",
"format": "prettier --write '**/*.{js,css,json,md}'"
},
"author": "{{ authors }}",
"license": "MIT",
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.1.0",
"@rollup/plugin-replace": "^2.4.2",
"prettier": "^1.19.1",
"rollup": "^2.36.1",
"rollup-plugin-copy": "^3.3.0",
"rollup-plugin-terser": "^7.0.2"
}
}
25 changes: 25 additions & 0 deletions run/queue-consumer-worker/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// plugin-node-resolve and plugin-commonjs are required for a rollup bundled project
// to resolve dependencies from node_modules. See the documentation for these plugins
// for more details.
import dotenv from 'dotenv'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace'

dotenv.config()

const replace_plugin = replace({
__HONEYCOMB_API_KEY__: process.env.HONEYCOMB_API_KEY,
preventAssignment: true,
})

export default {
input: 'src/index.mjs',
output: {
exports: 'named',
format: 'es',
file: 'dist/index.mjs',
sourcemap: true,
},
plugins: [commonjs(), nodeResolve({ browser: true }), replace_plugin],
}
66 changes: 66 additions & 0 deletions run/queue-consumer-worker/src/index.mTs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/** BSD 3-Clause License

Copyright (c) 2021, Cloudflare Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import { wrapModule } from '../../../dist/index'

import { QueueHanderResult } from '../../../dist/index'
import { MessageBatch } from '../../../dist/queues'

import { Span } from '../../../dist/index'

const worker = {
async queue(request: MessageBatch, env, ctx, span: Span): Promise<QueueHanderResult<boolean>> {

const result = await span.fetch('https://cloudflare.com')
return {
success: true,
data: result.ok,
}
},
}

const sampleQueue = (data: QueueHanderResult<boolean>) => {
if (!data.success) {
return 1;
}
return 10
}



const config = {
apiKey: '__HONEYCOMB_API_KEY__',
dataset: 'my-first-dataset',
queueUrl: '',
sampleRates: sampleQueue
}

export default wrapModule(config, worker)
14 changes: 14 additions & 0 deletions run/queue-consumer-worker/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name = "module-worker"
# type = "javascript" is required to use the `[build]` section
type = "javascript"
account_id = "03bac747018bef5f4ad236a15c22c360"
workers_dev = true
route = ""
zone_id = ""

[build]
command = "yarn install && yarn build"
[build.upload]
# The "modules" upload format is required for all projects that export a Durable Objects class
format = "modules"
main = "./index.mts"
Loading