diff --git a/.github/workflows/canary.yaml b/.github/workflows/canary.yaml index 0b74431f..f98238b0 100644 --- a/.github/workflows/canary.yaml +++ b/.github/workflows/canary.yaml @@ -67,6 +67,27 @@ jobs: - name: Test run: wing test working-directory: checks + canary-eventbridge: + name: Test eventbridge + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + sparse-checkout: eventbridge + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20.x + registry-url: https://registry.npmjs.org + - name: Install winglang + run: npm i -g winglang + - name: Install dependencies + run: npm install --include=dev + working-directory: eventbridge + - name: Test + run: wing test + working-directory: eventbridge canary-fifoqueue: name: Test fifoqueue runs-on: ubuntu-latest @@ -109,6 +130,27 @@ jobs: - name: Test run: wing test working-directory: github + canary-lock: + name: Test lock + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + sparse-checkout: lock + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20.x + registry-url: https://registry.npmjs.org + - name: Install winglang + run: npm i -g winglang + - name: Install dependencies + run: npm install --include=dev + working-directory: lock + - name: Test + run: wing test + working-directory: lock canary-ngrok: name: Test ngrok runs-on: ubuntu-latest diff --git a/.github/workflows/eventbridge-pull.yaml b/.github/workflows/eventbridge-pull.yaml index 4a133ffb..d4e97cba 100644 --- a/.github/workflows/eventbridge-pull.yaml +++ b/.github/workflows/eventbridge-pull.yaml @@ -4,7 +4,7 @@ on: paths: - eventbridge/** jobs: - build: + build-eventbridge: runs-on: ubuntu-latest steps: - name: Checkout @@ -14,7 +14,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 20.x registry-url: https://registry.npmjs.org - name: Install winglang run: npm i -g winglang diff --git a/.github/workflows/eventbridge-release.yaml b/.github/workflows/eventbridge-release.yaml index 92b3bd3a..1c40e6e9 100644 --- a/.github/workflows/eventbridge-release.yaml +++ b/.github/workflows/eventbridge-release.yaml @@ -5,8 +5,9 @@ on: - main paths: - eventbridge/** + - "!eventbridge/package-lock.json" jobs: - build: + build-eventbridge: runs-on: ubuntu-latest steps: - name: Checkout @@ -16,7 +17,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 20.x registry-url: https://registry.npmjs.org - name: Install winglang run: npm i -g winglang @@ -29,9 +30,25 @@ jobs: - name: Pack run: wing pack working-directory: eventbridge + - name: Get package version + run: echo WINGLIB_VERSION=$(node -p "require('./package.json').version") >> + "$GITHUB_ENV" + working-directory: eventbridge - name: Publish run: npm publish --access=public --registry https://registry.npmjs.org --tag latest *.tgz working-directory: eventbridge env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Tag commit + uses: tvdias/github-tagger@v0.0.1 + with: + repo-token: ${{ secrets.PROJEN_GITHUB_TOKEN }} + tag: eventbridge-v${{ env.WINGLIB_VERSION }} + - name: GitHub release + uses: softprops/action-gh-release@v1 + with: + name: eventbridge v${{ env.WINGLIB_VERSION }} + tag_name: eventbridge-v${{ env.WINGLIB_VERSION }} + files: "*.tgz" + token: ${{ secrets.PROJEN_GITHUB_TOKEN }} diff --git a/.github/workflows/lock-pull.yaml b/.github/workflows/lock-pull.yaml index 8f41b4d3..ae31af7d 100644 --- a/.github/workflows/lock-pull.yaml +++ b/.github/workflows/lock-pull.yaml @@ -4,7 +4,7 @@ on: paths: - lock/** jobs: - build: + build-lock: runs-on: ubuntu-latest steps: - name: Checkout @@ -14,7 +14,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 20.x registry-url: https://registry.npmjs.org - name: Install winglang run: npm i -g winglang diff --git a/.github/workflows/lock-release.yaml b/.github/workflows/lock-release.yaml index 3c45344d..55210ab4 100644 --- a/.github/workflows/lock-release.yaml +++ b/.github/workflows/lock-release.yaml @@ -5,8 +5,9 @@ on: - main paths: - lock/** + - "!lock/package-lock.json" jobs: - build: + build-lock: runs-on: ubuntu-latest steps: - name: Checkout @@ -16,7 +17,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 20.x registry-url: https://registry.npmjs.org - name: Install winglang run: npm i -g winglang @@ -29,9 +30,25 @@ jobs: - name: Pack run: wing pack working-directory: lock + - name: Get package version + run: echo WINGLIB_VERSION=$(node -p "require('./package.json').version") >> + "$GITHUB_ENV" + working-directory: lock - name: Publish run: npm publish --access=public --registry https://registry.npmjs.org --tag latest *.tgz working-directory: lock env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Tag commit + uses: tvdias/github-tagger@v0.0.1 + with: + repo-token: ${{ secrets.PROJEN_GITHUB_TOKEN }} + tag: lock-v${{ env.WINGLIB_VERSION }} + - name: GitHub release + uses: softprops/action-gh-release@v1 + with: + name: lock v${{ env.WINGLIB_VERSION }} + tag_name: lock-v${{ env.WINGLIB_VERSION }} + files: "*.tgz" + token: ${{ secrets.PROJEN_GITHUB_TOKEN }} diff --git a/.mergify.yml b/.mergify.yml index 883ffa44..964c4fc8 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -44,12 +44,18 @@ pull_request_rules: - -check-failure=build-containers - -check-pending=build-containers - -check-stale=build-containers + - -check-failure=build-eventbridge + - -check-pending=build-eventbridge + - -check-stale=build-eventbridge - -check-failure=build-fifoqueue - -check-pending=build-fifoqueue - -check-stale=build-fifoqueue - -check-failure=build-github - -check-pending=build-github - -check-stale=build-github + - -check-failure=build-lock + - -check-pending=build-lock + - -check-stale=build-lock - -check-failure=build-ngrok - -check-pending=build-ngrok - -check-stale=build-ngrok @@ -95,12 +101,18 @@ pull_request_rules: - -check-failure=build-containers - -check-pending=build-containers - -check-stale=build-containers + - -check-failure=build-eventbridge + - -check-pending=build-eventbridge + - -check-stale=build-eventbridge - -check-failure=build-fifoqueue - -check-pending=build-fifoqueue - -check-stale=build-fifoqueue - -check-failure=build-github - -check-pending=build-github - -check-stale=build-github + - -check-failure=build-lock + - -check-pending=build-lock + - -check-stale=build-lock - -check-failure=build-ngrok - -check-pending=build-ngrok - -check-stale=build-ngrok diff --git a/eventbridge/README.md b/eventbridge/README.md index f24c94e8..35d69289 100644 --- a/eventbridge/README.md +++ b/eventbridge/README.md @@ -20,7 +20,7 @@ bring eventbridge; let bus = new eventbridge.Bus(name: "my-bus"); -bus.subscribeFunction("github.pull-request.created", inflight (event) => { +bus.onEvent("github.pull-request.created", inflight (event) => { log("subscribed event received {Json.stringify(event)}"); }, { "detail-type": [{"prefix": "pull-request."}], @@ -28,7 +28,7 @@ bus.subscribeFunction("github.pull-request.created", inflight (event) => { }); new cloud.Function(inflight () => { - bus.putEvents([{ + bus.putEvents({ detailType: "pull-request.created", resources: ["test"], source: "github.com", @@ -36,7 +36,7 @@ new cloud.Function(inflight () => { detail: { "test": "test", }, - }]); + }); }); ``` @@ -44,6 +44,12 @@ new cloud.Function(inflight () => { * eventBridgeName - `str` - Optional. Name of an existing EventBridge to reference. +#### Usage + +```sh +wing compile -t @winglang/platform-awscdk -v eventBridgeName="my-bus" main.w +``` + ## License This library is licensed under the [MIT License](./LICENSE). diff --git a/eventbridge/lib.test.w b/eventbridge/lib.test.w index 5fe6833d..3e607059 100644 --- a/eventbridge/lib.test.w +++ b/eventbridge/lib.test.w @@ -13,7 +13,7 @@ class InboundGithubEvents { this.bucket = new cloud.Bucket(); let counter = new cloud.Counter(); - eventBridge.subscribeFunction("github.pull-request.created", inflight (event) => { + eventBridge.onEvent("github.pull-request.created", inflight (event) => { log("subscribed event received {Json.stringify(event)}"); this.bucket.put("test-{counter.inc()}", Json.stringify(event)); }, { @@ -46,7 +46,7 @@ let env = new Environments(); test "publish to eventbridge" { log("publishing to eventbridge"); - eventBridge.putEvents([{ + eventBridge.putEvents({ detailType: "pull-request.created", resources: ["test"], source: "github.com", @@ -54,7 +54,7 @@ test "publish to eventbridge" { detail: { "test": "test", }, - }]); + }); log("published"); @@ -73,7 +73,7 @@ test "publish to eventbridge" { expect.equal(0, env.bucket.list().length); - eventBridge.putEvents([{ + eventBridge.putEvents({ detailType: "myTest.check", resources: ["test"], source: "myTest", @@ -81,7 +81,7 @@ test "publish to eventbridge" { detail: { "fake": "env", }, - }]); + }); log("published 2nd event"); diff --git a/eventbridge/lib.w b/eventbridge/lib.w index 737f64ed..0d7180d5 100644 --- a/eventbridge/lib.w +++ b/eventbridge/lib.w @@ -11,7 +11,7 @@ bring "./platform/awscdk" as awscdk; pub class Bus impl types.IBus { inner: types.IBus; - new(props: types.BusProps) { + new(props: types.BusProps?) { let target = util.env("WING_TARGET"); if target == "sim" { this.inner = new sim.Bus(props) as "sim"; @@ -24,12 +24,12 @@ pub class Bus impl types.IBus { } } - pub inflight putEvents(events: Array): void { + pub inflight putEvents(...events: Array): void { this.inner.putEvents(events); } - pub subscribeFunction(name: str, handler: inflight (types.Event): void, pattern: Json): void { - this.inner.subscribeFunction(name, handler, pattern); + pub onEvent(name: str, handler: inflight (types.Event): void, pattern: Json): void { + this.inner.onEvent(name, handler, pattern); } pub subscribeQueue(name: str, queue: cloud.Queue, pattern: Json): void { this.inner.subscribeQueue(name, queue, pattern); diff --git a/eventbridge/package-lock.json b/eventbridge/package-lock.json index 7c874dd7..75d4831b 100644 --- a/eventbridge/package-lock.json +++ b/eventbridge/package-lock.json @@ -1,12 +1,12 @@ { "name": "@winglibs/eventbridge", - "version": "0.0.2", + "version": "0.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@winglibs/eventbridge", - "version": "0.0.2", + "version": "0.0.3", "license": "MIT", "devDependencies": { "@cdktf/provider-aws": "^18.2.0", diff --git a/eventbridge/package.json b/eventbridge/package.json index c672f6af..ad2c154b 100644 --- a/eventbridge/package.json +++ b/eventbridge/package.json @@ -1,7 +1,7 @@ { "name": "@winglibs/eventbridge", "description": "Amazon EventBridge library for Wing", - "version": "0.0.2", + "version": "0.0.3", "repository": { "type": "git", "url": "https://github.com/winglang/winglibs.git", diff --git a/eventbridge/platform/awscdk/eventbridge.w b/eventbridge/platform/awscdk/eventbridge.w index 1e0bbf3b..3d5fe5a8 100644 --- a/eventbridge/platform/awscdk/eventbridge.w +++ b/eventbridge/platform/awscdk/eventbridge.w @@ -9,17 +9,17 @@ pub class Bus impl types.IBus { eventBridge: cdk.aws_events.IEventBus; - new(props: types.BusProps) { + new(props: types.BusProps?) { let app = nodeof(this).app; // TODO: use typed properties when its available if let eventBridgeName = unsafeCast(app)?.platformParameters?.getParameterValue("eventBridgeName") { this.eventBridge = cdk.aws_events.EventBus.fromEventBusName(this, "EventBridge", eventBridgeName); } else { - this.eventBridge = new cdk.aws_events.EventBus(eventBusName: props.name) as "EventBridge"; + this.eventBridge = new cdk.aws_events.EventBus(eventBusName: props?.name ?? "eventbridge-{this.node.addr.substring(0, 8)}") as "EventBridge"; } } - pub subscribeFunction(name: str, handler: inflight (types.Event): void, pattern: Json): void { + pub onEvent(name: str, handler: inflight (types.Event): void, pattern: Json): void { // event will be json of type `types.Event` let funk = new cloud.Function(inflight (event) => { // since wing structs don't supoort custom serialization we need to do it manually diff --git a/eventbridge/platform/sim/bus.w b/eventbridge/platform/sim/bus.w index ba3cd07a..f31e9a8a 100644 --- a/eventbridge/platform/sim/bus.w +++ b/eventbridge/platform/sim/bus.w @@ -7,7 +7,7 @@ pub class EventBridgeBus { topic: cloud.Topic; var handlerCount: num; - new(props: types.BusProps) { + new(props: types.BusProps?) { this.topic = new cloud.Topic() as "EventBridge"; this.handlerCount = 0; diff --git a/eventbridge/platform/sim/eventbridge.w b/eventbridge/platform/sim/eventbridge.w index 2833c53a..29a08dce 100644 --- a/eventbridge/platform/sim/eventbridge.w +++ b/eventbridge/platform/sim/eventbridge.w @@ -5,11 +5,11 @@ bring "./bus.w" as bus; pub class Bus impl types.IBus { bus: bus.EventBridgeBus; - new(props: types.BusProps) { + new(props: types.BusProps?) { this.bus = new bus.EventBridgeBus(props); } - pub subscribeFunction(name: str, handler: inflight (types.Event): void, pattern: Json): void { + pub onEvent(name: str, handler: inflight (types.Event): void, pattern: Json): void { class FnRule { new(bus: bus.EventBridgeBus) { let onMessageHandler = bus.subscribe(inflight (event) => { diff --git a/eventbridge/platform/tfaws/eventbridge.w b/eventbridge/platform/tfaws/eventbridge.w index d36988b1..8567c7fc 100644 --- a/eventbridge/platform/tfaws/eventbridge.w +++ b/eventbridge/platform/tfaws/eventbridge.w @@ -9,7 +9,7 @@ pub class Bus impl types.IBus { busName: str; busArn: str; - new(props: types.BusProps) { + new(props: types.BusProps?) { let app = nodeof(this).app; // TODO: use typed properties when its available if let eventBridgeName = unsafeCast(app)?.platformParameters?.getParameterValue("eventBridgeName") { @@ -19,13 +19,13 @@ pub class Bus impl types.IBus { this.busName = bus.name; this.busArn = bus.arn; } else { - let bus = new tfAws.cloudwatchEventBus.CloudwatchEventBus(name: props.name) as "EventBridge"; + let bus = new tfAws.cloudwatchEventBus.CloudwatchEventBus(name: props?.name ?? "eventbridge-{this.node.addr.substring(0, 8)}") as "EventBridge"; this.busName = bus.name; this.busArn = bus.arn; } } - pub subscribeFunction(name: str, handler: inflight (types.Event): void, pattern: Json): void { + pub onEvent(name: str, handler: inflight (types.Event): void, pattern: Json): void { let rule = new tfAws.cloudwatchEventRule.CloudwatchEventRule( name: name, eventBusName: this.busName, diff --git a/eventbridge/types.w b/eventbridge/types.w index ecfa82c2..5ba96877 100644 --- a/eventbridge/types.w +++ b/eventbridge/types.w @@ -27,6 +27,6 @@ pub struct PublishEvent { pub interface IBus extends std.IResource { inflight putEvents(events: Array): void; - subscribeFunction(name: str, handler: inflight (Event): void, pattern: Json): void; + onEvent(name: str, handler: inflight (Event): void, pattern: Json): void; subscribeQueue(name: str, queue: cloud.Queue, pattern: Json): void; }