Skip to content

Commit c342ed2

Browse files
authored
feat!: Cloudflare workers (#22)
1 parent 8e89e45 commit c342ed2

34 files changed

+2107
-1467
lines changed

.dockerignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@
2121
**/obj
2222
**/secrets.dev.yaml
2323
**/values.dev.yaml
24-
README.md
24+
.github/
25+
.wrangler/
26+
.*.vars
27+
build/
28+
target/
29+
README.md
30+
fly.toml
31+
test.mjs
32+
wrangler.toml

.github/workflows/build-docker.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Docker Build
2+
on:
3+
workflow_call:
4+
inputs:
5+
tag:
6+
required: false
7+
type: string
8+
no_push:
9+
required: false
10+
type: boolean
11+
default: false
12+
workflow_dispatch:
13+
inputs:
14+
tag:
15+
required: false
16+
description: 'Tag to build and push'
17+
type: string
18+
env:
19+
REGISTRY_IMAGE: ghcr.io/cbackas/hookbuffer
20+
jobs:
21+
build-docker:
22+
runs-on: ${{ matrix.platform }}
23+
permissions:
24+
contents: read
25+
packages: write
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
platform:
30+
- ubuntu-latest
31+
- ubuntu-24.04-arm
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Docker meta
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY_IMAGE }}
40+
- uses: docker/setup-buildx-action@v3
41+
42+
- uses: docker/login-action@v3
43+
with:
44+
registry: ghcr.io
45+
username: ${{ github.actor }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Build and push
49+
uses: docker/build-push-action@v6
50+
id: build
51+
with:
52+
labels: ${{ steps.meta.outputs.labels }}
53+
tags: ${{ env.REGISTRY_IMAGE }}
54+
outputs: type=image,push-by-digest=true,name-canonical=true,push=${{ !inputs.no_push }}
55+
cache-from: type=gha,scope=build-${{ matrix.platform }}
56+
cache-to: type=gha,scope=build-${{ matrix.platform }}
57+
58+
- name: Export digest
59+
run: |
60+
mkdir -p ${{ runner.temp }}/digests
61+
digest="${{ steps.build.outputs.digest }}"
62+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
63+
64+
- name: Upload digest
65+
uses: actions/upload-artifact@v4
66+
if: ${{ !inputs.no_push }}
67+
with:
68+
name: digests-${{ matrix.platform }}
69+
path: ${{ runner.temp }}/digests/*
70+
if-no-files-found: error
71+
retention-days: 1
72+
merge-docker-digests:
73+
runs-on: ubuntu-latest
74+
needs: build-docker
75+
if: ${{ !inputs.no_push }}
76+
steps:
77+
- name: Download digests
78+
uses: actions/download-artifact@v4
79+
with:
80+
path: ${{ runner.temp }}/digests
81+
pattern: digests-*
82+
merge-multiple: true
83+
84+
- uses: docker/login-action@v3
85+
with:
86+
registry: ghcr.io
87+
username: ${{ github.actor }}
88+
password: ${{ secrets.GITHUB_TOKEN }}
89+
90+
- uses: docker/setup-buildx-action@v3
91+
92+
- uses: docker/metadata-action@v5
93+
id: meta
94+
with:
95+
images: ${{ env.REGISTRY_IMAGE }}
96+
tags: |
97+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
98+
type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }}
99+
type=ref,event=pr
100+
101+
- name: Create manifest list and push
102+
working-directory: ${{ runner.temp }}/digests
103+
run: |
104+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
105+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
106+
107+
- name: Inspect image
108+
run: |
109+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

.github/workflows/build.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build
2+
on:
3+
workflow_call:
4+
workflow_dispatch:
5+
env:
6+
REGISTRY_IMAGE: ghcr.io/cbackas/hookbuffer
7+
jobs:
8+
build-full:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: dtolnay/rust-toolchain@stable
13+
- uses: Swatinem/rust-cache@v2
14+
- name: Build
15+
run: cargo build --verbose
16+
build-worker:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: dtolnay/rust-toolchain@stable
21+
- uses: actions/setup-node@v4
22+
with:
23+
node-version: 22
24+
- run: npm install wrangler
25+
- uses: Swatinem/rust-cache@v2
26+
- run: npx wrangler deploy --dry-run
27+
build-docker:
28+
uses: ./.github/workflows/build-docker.yml
29+
with:
30+
no_push: true
31+

.github/workflows/pr.yml

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ name: Pull Request
22
on:
33
pull_request:
44
branches:
5-
- master
5+
- main
66
types:
77
- opened
88
- edited
99
- synchronize
1010
jobs:
1111
pr-title:
1212
runs-on: ubuntu-latest
13+
permissions:
14+
pull-requests: read
1315
steps:
14-
- name: Check PR Title
15-
uses: deepakputhraya/action-pr-title@master
16-
with:
17-
allowed_prefixes: 'Breaking:,Fix:,Update:,New:,Build:,Upgrade:,Chore:,NoBuild:'
18-
prefix_case_sensitive: true
16+
- uses: amannn/action-semantic-pull-request@v5
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1919
lint:
2020
runs-on: ubuntu-latest
2121
steps:
@@ -36,18 +36,4 @@ jobs:
3636
run: |
3737
cargo test --verbose
3838
build:
39-
runs-on: ubuntu-latest
40-
steps:
41-
- uses: actions/checkout@v4
42-
- uses: dtolnay/rust-toolchain@stable
43-
- name: Build
44-
run: cargo build --verbose
45-
build_docker:
46-
runs-on: ubuntu-latest
47-
steps:
48-
- uses: actions/checkout@v4
49-
- name: Build and push
50-
uses: docker/build-push-action@v3
51-
with:
52-
push: false
53-
tags: cbackas/hookbuffer:pr
39+
uses: ./.github/workflows/build.yml

.github/workflows/push.yml

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
1-
name: SemanticRelease
1+
name: Automated Release
22
on:
33
workflow_dispatch:
44
push:
55
branches:
6-
- master
7-
tags:
8-
- "*.*.*"
6+
- main
97
jobs:
10-
release:
8+
build:
9+
uses: ./.github/workflows/build.yml
10+
release-please:
11+
needs: build
1112
runs-on: ubuntu-latest
12-
if: startsWith(github.ref, 'refs/heads/')
13+
permissions:
14+
contents: write
15+
pull-requests: write
1316
steps:
14-
- uses: actions/checkout@v4
15-
with:
16-
persist-credentials: false
17-
- name: Setup Node.js
18-
uses: actions/setup-node@v4
17+
- uses: googleapis/release-please-action@v4
18+
id: release
1919
with:
20-
node-version: 22
21-
- name: Install Semantic Release
22-
run: npm install semantic-release @codedependant/semantic-release-docker conventional-changelog-eslint
23-
- name: Semantic Release
24-
env:
25-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
26-
DOCKER_REGISTRY_USER: ${{ github.actor }}
27-
DOCKER_REGISTRY_PASSWORD: ${{ secrets.GHCR_TOKEN }}
28-
run: npx semantic-release
29-
deploy:
20+
token: ${{ secrets.GH_TOKEN }}
21+
release-type: rust
22+
outputs:
23+
release_created: ${{ steps.release.outputs.release_created }}
24+
version: ${{ steps.release.outputs.tag_name }}
25+
docker-publish:
26+
needs: release-please
27+
if: ${{ needs.release-please.outputs.release_created == 'true' }}
28+
uses: ./.github/workflows/build-docker.yml
29+
secrets: inherit
30+
with:
31+
tag: ${{ needs.release-please.outputs.version }}
32+
deploy-worker:
33+
needs: release-please
34+
if: ${{ needs.release-please.outputs.release_created == 'true' }}
3035
runs-on: ubuntu-latest
31-
if: startsWith(github.ref, 'refs/heads/')
32-
needs: release
3336
steps:
3437
- uses: actions/checkout@v4
35-
- uses: superfly/flyctl-actions/setup-flyctl@master
36-
- run: flyctl deploy --local-only
37-
env:
38-
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
38+
- uses: dtolnay/rust-toolchain@stable
39+
- uses: actions/setup-node@v4
40+
with:
41+
node-version: 22
42+
- run: npm install wrangler
43+
- run: npx wrangler deploy
3944
notify:
4045
runs-on: ubuntu-latest
41-
if: startsWith(github.ref, 'refs/tags/')
46+
needs: [release-please, docker-publish, deploy-worker]
47+
if: ${{ needs.release-please.outputs.release_created == 'true' }}
4248
steps:
43-
- uses: actions/checkout@v4
44-
- name: Extract tag name
45-
id: tag
46-
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
4749
- name: Discord notification
4850
uses: Ilshidur/action-discord@master
4951
env:
5052
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
5153
with:
52-
args: "Version {{ TAG_NAME }} of {{ EVENT_PAYLOAD.repository.full_name }} has been released!"
54+
args: "Version ${{ needs.release-please.outputs.version }} of Hookbuffer has been released!"
55+

.gitignore

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
*.exe
2-
3-
# Added by cargo
4-
5-
/target
1+
target
2+
node_modules
3+
.wrangler
4+
*.vars

0 commit comments

Comments
 (0)