Skip to content

Commit d965743

Browse files
committed
export
0 parents  commit d965743

15 files changed

+892
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Build and publish package
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tag-prefix:
7+
required: true
8+
type: string
9+
version-bump:
10+
type: string
11+
required: true
12+
default: 'minor'
13+
secrets:
14+
SONATYPE_TOKEN:
15+
required: true
16+
GPG_SECRET_KEY:
17+
required: true
18+
GPG_SECRET_KEY_ID:
19+
required: true
20+
21+
permissions:
22+
id-token: write # This is required for requesting the JWT
23+
contents: write # This is required for actions/checkout
24+
packages: write
25+
pull-requests: write
26+
27+
env:
28+
TAG_PREFIX: '${{ inputs.tag-prefix }}-'
29+
30+
jobs:
31+
buildAndPublishPackage:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
- uses: coursier/cache-action@v6
38+
- uses: VirtusLab/scala-cli-setup@main
39+
with:
40+
jvm: adoptium:1.21
41+
- name: Setup gpg
42+
id: gpg
43+
run: |
44+
echo "${{ secrets.GPG_SECRET_KEY }}" | base64 -d | gpg --import
45+
gpg -K
46+
- id: version
47+
name: Compute new version
48+
run: ./scripts/computeNewVersion.sc --prefix='${{ env.TAG_PREFIX }}' --bump=${{ inputs.version-bump }} >> "$GITHUB_OUTPUT"
49+
- name: Create release bundle
50+
run: './scripts/createReleaseBundle.sc --version=${{ steps.version.outputs.new_version }} --gpg-key=${{ secrets.GPG_SECRET_KEY_ID }}'
51+
- name: Upload bundle to Sonatype
52+
run: |
53+
curl --request POST \
54+
--verbose \
55+
--header 'Authorization: Bearer ${{ secrets.SONATYPE_TOKEN }}' \
56+
57+
https://central.sonatype.com/api/v1/publisher/upload?publishingType=AUTOMATIC&name=${{ env.TAG_PREFIX }}-${{ steps.version.outputs.new_version }}
58+
- name: Push tag
59+
id: tag_version
60+
uses: mathieudutour/[email protected]
61+
with:
62+
github_token: ${{ secrets.GITHUB_TOKEN }}
63+
custom_tag: ${{ steps.version.outputs.new_version }}
64+
tag_prefix: ${{ env.TAG_PREFIX }}
65+
- name: Create GitHub Release
66+
if: ${{ inputs.version-bump != 'keep' }}
67+
uses: actions/create-release@v1
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
with:
71+
tag_name: ${{ env.TAG_PREFIX }}${{ steps.version.outputs.new_version }}
72+
release_name: ${{ inputs.tag-prefix }} release ${{ steps.version.outputs.new_version }}
73+
draft: false
74+
prerelease: false
75+
- name: Move version tag
76+
if: ${{ inputs.version-bump == 'keep' }}
77+
uses: richardsimko/update-tag@v1
78+
with:
79+
tag_name: ${{ env.TAG_PREFIX }}${{ steps.version.outputs.new_version }}
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
83+

.github/workflows/release.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Release new package version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version-bump:
7+
type: choice
8+
description: 'How to bump a version?'
9+
required: true
10+
default: 'patch'
11+
options:
12+
- major
13+
- minor
14+
- patch
15+
- keep
16+
# push:
17+
# branches: [main]
18+
# paths:
19+
# - '*.scala'
20+
21+
jobs:
22+
ReleasePackage:
23+
uses: ./.github/workflows/buildAndPublishPackage.yaml
24+
secrets: inherit
25+
with:
26+
tag-prefix: 'version'
27+
version-bump: ${{ inputs.version-bump || 'patch' }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.bsp/
2+
.scala-build/
3+
.metals/
4+
.vscode/

.scalafmt.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version = "3.7.15"
2+
runner.dialect = scala3
3+
maxColumn = 120

ApiGatewayRequestHandler.scala

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.encalmo.lambda
2+
3+
import scala.util.matching.Regex
4+
5+
/** Abstract base class of an http request handler. */
6+
trait ApiGatewayRequestHandler[OtherContext] {
7+
8+
type Resource = (String, Regex)
9+
10+
def handleRequest(
11+
request: ApiGatewayRequest
12+
)(using LambdaContext, OtherContext): Option[ApiGatewayResponse]
13+
14+
extension (r: Resource)
15+
inline def httpMethod: String = r._1
16+
inline def pathRegex: Regex = r._2
17+
inline def unapplySeq(request: ApiGatewayRequest) =
18+
if (request.httpMethod == r._1 || r._1 == "ANY")
19+
then r._2.unapplySeq(request.getResourceOrPathIfProxy)
20+
else None
21+
22+
final def createApiGatewaySuccessResponse(body: String): ApiGatewayResponse =
23+
ApiGatewayResponse(
24+
statusCode = 200,
25+
headers = Map("Content-Type" -> "application/json"),
26+
isBase64Encoded = false,
27+
body = body
28+
)
29+
30+
final def createApiGatewaySuccessResponse(
31+
json: ujson.Value
32+
): ApiGatewayResponse =
33+
ApiGatewayResponse(
34+
statusCode = 200,
35+
headers = Map("Content-Type" -> "application/json"),
36+
isBase64Encoded = false,
37+
body = ujson.write(json)
38+
)
39+
40+
final def returnErrorResponseWhenException(e: Throwable): ApiGatewayResponse =
41+
ApiGatewayResponse(
42+
statusCode = 501,
43+
headers = Map("Content-Type" -> "plain/text"),
44+
isBase64Encoded = false,
45+
body = s"${e.getClass.getName()} ${e
46+
.getMessage()}\n${e.getStackTrace().take(10).mkString("\n")}"
47+
)
48+
}

GenericEventHandler.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.encalmo.lambda
2+
3+
import ujson.Value
4+
5+
/** Abstract base class of an generic event handler. */
6+
trait GenericEventHandler[OtherContext] {
7+
8+
/** Optional function name for handling events having `function` property. If not defined it will default to the
9+
* simple class name.
10+
*/
11+
def functionName: Option[String] = None
12+
13+
def handleEvent(
14+
event: Value
15+
)(using LambdaContext, OtherContext): Option[String]
16+
}

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2024 encalmo.org
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the " Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)