Skip to content

Commit 7c6a8fd

Browse files
committed
Execute both localstack and fauxqs
1 parent 9669996 commit 7c6a8fd

10 files changed

Lines changed: 139 additions & 35 deletions

File tree

.github/workflows/ci.common.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
node_version:
99
required: true
1010
type: string
11+
queue_backend:
12+
required: false
13+
type: string
14+
default: 'fauxqs'
1115

1216
jobs:
1317
build:
@@ -32,9 +36,15 @@ jobs:
3236

3337
- name: Docker start
3438
run: npm run docker:start:ci -- --filter=${{ inputs.package_name }}
39+
env:
40+
QUEUE_BACKEND: ${{ inputs.queue_backend }}
3541

3642
- name: Run Tests
3743
run: npm run test:ci -- --filter=${{ inputs.package_name }}
44+
env:
45+
QUEUE_BACKEND: ${{ inputs.queue_backend }}
3846

3947
- name: Docker stop
4048
run: npm run docker:stop:ci -- --filter=${{ inputs.package_name }}
49+
env:
50+
QUEUE_BACKEND: ${{ inputs.queue_backend }}

.github/workflows/ci.yml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
outputs:
1414
packages: ${{ steps.detect.outputs.packages }}
15+
aws_packages: ${{ steps.detect.outputs.aws_packages }}
1516
steps:
1617
- name: Get changed files
1718
id: changed-files
@@ -39,22 +40,45 @@ jobs:
3940
["packages/sqs"]="@message-queue-toolkit/sqs"
4041
)
4142
43+
AWS_PACKAGE_PATHS=("packages/sqs" "packages/sns")
44+
4245
PACKAGES=()
46+
AWS_PACKAGES=()
4347
for path in "${!PATH_TO_NAME[@]}"; do
4448
if echo "$ALL_CHANGED_FILES" | grep -q "$path/"; then
45-
PACKAGES+=("\"${PATH_TO_NAME[$path]}\"")
49+
is_aws=false
50+
for aws_path in "${AWS_PACKAGE_PATHS[@]}"; do
51+
if [ "$path" = "$aws_path" ]; then
52+
is_aws=true
53+
break
54+
fi
55+
done
56+
if [ "$is_aws" = true ]; then
57+
AWS_PACKAGES+=("\"${PATH_TO_NAME[$path]}\"")
58+
else
59+
PACKAGES+=("\"${PATH_TO_NAME[$path]}\"")
60+
fi
4661
fi
4762
done
4863
4964
if [ ${#PACKAGES[@]} -eq 0 ]; then
5065
echo 'packages=[]' >> $GITHUB_OUTPUT
51-
echo "No packages changed"
66+
echo "No non-AWS packages changed"
5267
else
5368
JSON="[$(IFS=,; echo "${PACKAGES[*]}")]"
5469
echo "packages=$JSON" >> $GITHUB_OUTPUT
5570
echo "Changed packages: $JSON"
5671
fi
5772
73+
if [ ${#AWS_PACKAGES[@]} -eq 0 ]; then
74+
echo 'aws_packages=[]' >> $GITHUB_OUTPUT
75+
echo "No AWS packages changed"
76+
else
77+
AWS_JSON="[$(IFS=,; echo "${AWS_PACKAGES[*]}")]"
78+
echo "aws_packages=$AWS_JSON" >> $GITHUB_OUTPUT
79+
echo "Changed AWS packages: $AWS_JSON"
80+
fi
81+
5882
general:
5983
needs: [changed-files-job]
6084
if: needs.changed-files-job.outputs.packages != '[]'
@@ -67,9 +91,23 @@ jobs:
6791
node_version: ${{ matrix.node-version }}
6892
package_name: ${{ matrix.package-name }}
6993

94+
aws-packages:
95+
needs: [changed-files-job]
96+
if: needs.changed-files-job.outputs.aws_packages != '[]'
97+
strategy:
98+
matrix:
99+
node-version: [22.x, 24.x]
100+
package-name: ${{ fromJson(needs.changed-files-job.outputs.aws_packages) }}
101+
queue-backend: [fauxqs, localstack]
102+
uses: ./.github/workflows/ci.common.yml
103+
with:
104+
node_version: ${{ matrix.node-version }}
105+
package_name: ${{ matrix.package-name }}
106+
queue_backend: ${{ matrix.queue-backend }}
107+
70108
automerge:
71-
needs: [general]
72-
if: always() && (needs.general.result == 'success' || needs.general.result == 'skipped')
109+
needs: [general, aws-packages]
110+
if: always() && (needs.general.result == 'success' || needs.general.result == 'skipped') && (needs.aws-packages.result == 'success' || needs.aws-packages.result == 'skipped')
73111
runs-on: ubuntu-latest
74112
permissions:
75113
pull-requests: write

docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ services:
7676
retries: 10
7777
start_period: 10s
7878

79+
localstack:
80+
image: localstack/localstack:4.13.1
81+
network_mode: bridge
82+
hostname: localstack
83+
ports:
84+
- '127.0.0.1:4566:4566'
85+
- '127.0.0.1:4510-4559:4510-4559'
86+
environment:
87+
- SERVICES=sns,sqs,s3,sts
88+
- DEBUG=0
89+
- LOCALSTACK_HOST=localstack
90+
volumes:
91+
- '${TMPDIR:-/tmp}/localstack:/var/log/localstack'
92+
- '/var/run/docker.sock:/var/run/docker.sock'
93+
restart: on-failure
94+
7995
volumes:
8096
rabbit_data:
8197
driver: local

packages/s3-payload-store/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@lokalise/tsconfig": "^3.0.0",
4242
"@types/node": "^25.0.2",
4343
"@vitest/coverage-v8": "^4.0.15",
44-
"fauxqs": "^1.7.0",
44+
"fauxqs": "^1.8.0",
4545
"rimraf": "^6.0.1",
4646
"typescript": "^5.9.3",
4747
"vitest": "^4.0.15"

packages/sns/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test:coverage": "npm run test -- --coverage",
2424
"lint": "biome check . && tsc",
2525
"lint:fix": "biome check --write .",
26-
"docker:start": "docker compose up -d redis",
26+
"docker:start": "docker compose up -d redis && if [ \"$QUEUE_BACKEND\" = \"localstack\" ]; then docker compose up -d --quiet-pull --wait localstack; fi",
2727
"docker:stop": "docker compose down",
2828
"prepublishOnly": "npm run lint && npm run build"
2929
},
@@ -55,7 +55,7 @@
5555
"@vitest/coverage-v8": "^4.0.15",
5656
"awilix": "^12.1.1",
5757
"awilix-manager": "^6.1.0",
58-
"fauxqs": "^1.7.0",
58+
"fauxqs": "^1.8.0",
5959
"ioredis": "^5.7.0",
6060
"rimraf": "^6.0.1",
6161
"typescript": "^5.9.3",
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { startFauxqs } from 'fauxqs'
1+
const isLocalstack = process.env.QUEUE_BACKEND === 'localstack'
22

3-
let server: Awaited<ReturnType<typeof startFauxqs>>
3+
let server: { stop: () => Promise<void> } | undefined
44

55
export async function setup() {
6-
server = await startFauxqs({ port: 4566, logger: false, host: 'localstack' })
6+
if (!isLocalstack) {
7+
const { startFauxqs } = await import('fauxqs')
8+
server = await startFauxqs({ port: 4566, logger: false, host: 'localstack' })
9+
}
710
}
811

912
export async function teardown() {
10-
await server.stop()
13+
await server?.stop()
1114
}
Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { S3ClientConfig } from '@aws-sdk/client-s3'
22
import type { SNSClientConfig } from '@aws-sdk/client-sns'
33
import type { SQSClientConfig } from '@aws-sdk/client-sqs'
4-
import { createLocalhostHandler } from 'fauxqs'
4+
5+
const isLocalstack = process.env.QUEUE_BACKEND === 'localstack'
56

67
export const TEST_AWS_CONFIG: SNSClientConfig & SQSClientConfig = {
78
endpoint: 'http://localhost:4566',
@@ -12,12 +13,28 @@ export const TEST_AWS_CONFIG: SNSClientConfig & SQSClientConfig = {
1213
},
1314
}
1415

15-
export const TEST_S3_CONFIG: S3ClientConfig = {
16-
endpoint: 'http://s3.localhost:4566',
17-
region: 'eu-west-1',
18-
credentials: {
19-
accessKeyId: 'access',
20-
secretAccessKey: 'secret',
21-
},
22-
requestHandler: createLocalhostHandler(),
16+
let s3Config: S3ClientConfig
17+
18+
if (isLocalstack) {
19+
s3Config = {
20+
endpoint: 'http://s3.localhost.localstack.cloud:4566',
21+
region: 'eu-west-1',
22+
credentials: {
23+
accessKeyId: 'access',
24+
secretAccessKey: 'secret',
25+
},
26+
}
27+
} else {
28+
const { createLocalhostHandler } = await import('fauxqs')
29+
s3Config = {
30+
endpoint: 'http://s3.localhost:4566',
31+
region: 'eu-west-1',
32+
credentials: {
33+
accessKeyId: 'access',
34+
secretAccessKey: 'secret',
35+
},
36+
requestHandler: createLocalhostHandler(),
37+
}
2338
}
39+
40+
export const TEST_S3_CONFIG: S3ClientConfig = s3Config

packages/sqs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test:coverage": "npm run test -- --coverage",
2424
"lint": "biome check && tsc",
2525
"lint:fix": "biome check --write .",
26-
"docker:start": "docker compose up -d redis",
26+
"docker:start": "docker compose up -d redis && if [ \"$QUEUE_BACKEND\" = \"localstack\" ]; then docker compose up -d --quiet-pull --wait localstack; fi",
2727
"docker:stop": "docker compose down",
2828
"prepublishOnly": "npm run lint && npm run build"
2929
},
@@ -50,7 +50,7 @@
5050
"@vitest/coverage-v8": "^4.0.15",
5151
"awilix": "^12.0.5",
5252
"awilix-manager": "^6.1.0",
53-
"fauxqs": "^1.7.0",
53+
"fauxqs": "^1.8.0",
5454
"ioredis": "^5.6.1",
5555
"rimraf": "^6.0.1",
5656
"typescript": "^5.9.3",
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { startFauxqs } from 'fauxqs'
1+
const isLocalstack = process.env.QUEUE_BACKEND === 'localstack'
22

3-
let server: Awaited<ReturnType<typeof startFauxqs>>
3+
let server: { stop: () => Promise<void> } | undefined
44

55
export async function setup() {
6-
server = await startFauxqs({ port: 4566, logger: false, host: 'localstack' })
6+
if (!isLocalstack) {
7+
const { startFauxqs } = await import('fauxqs')
8+
server = await startFauxqs({ port: 4566, logger: false, host: 'localstack' })
9+
}
710
}
811

912
export async function teardown() {
10-
await server.stop()
13+
await server?.stop()
1114
}
Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { S3ClientConfig } from '@aws-sdk/client-s3'
22
import type { SQSClientConfig } from '@aws-sdk/client-sqs'
3-
import { createLocalhostHandler } from 'fauxqs'
3+
4+
const isLocalstack = process.env.QUEUE_BACKEND === 'localstack'
45

56
export const TEST_AWS_CONFIG: SQSClientConfig = {
67
endpoint: 'http://localhost:4566',
@@ -11,12 +12,28 @@ export const TEST_AWS_CONFIG: SQSClientConfig = {
1112
},
1213
}
1314

14-
export const TEST_S3_CONFIG: S3ClientConfig = {
15-
endpoint: 'http://s3.localhost:4566',
16-
region: 'eu-west-1',
17-
credentials: {
18-
accessKeyId: 'access',
19-
secretAccessKey: 'secret',
20-
},
21-
requestHandler: createLocalhostHandler(),
15+
let s3Config: S3ClientConfig
16+
17+
if (isLocalstack) {
18+
s3Config = {
19+
endpoint: 'http://s3.localhost.localstack.cloud:4566',
20+
region: 'eu-west-1',
21+
credentials: {
22+
accessKeyId: 'access',
23+
secretAccessKey: 'secret',
24+
},
25+
}
26+
} else {
27+
const { createLocalhostHandler } = await import('fauxqs')
28+
s3Config = {
29+
endpoint: 'http://s3.localhost:4566',
30+
region: 'eu-west-1',
31+
credentials: {
32+
accessKeyId: 'access',
33+
secretAccessKey: 'secret',
34+
},
35+
requestHandler: createLocalhostHandler(),
36+
}
2237
}
38+
39+
export const TEST_S3_CONFIG: S3ClientConfig = s3Config

0 commit comments

Comments
 (0)