Skip to content

Commit

Permalink
Add cleanup GH job
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Nov 23, 2023
1 parent 498d169 commit 25e42d9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Cleanup after tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STREAM_API_KEY: ${{ vars.TEST_API_KEY }}
STREAM_SECRET: ${{ secrets.TEST_SECRET }}

# Runs midnight at every Sunday https://crontab.guru/weekly
on:
schedule:
- cron: "0 0 * * 0"

cleanup:
runs-on: ubuntu-latest
concurrency:
group: test-workflow
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20
cache: "yarn"

- name: Install Dependencies
run: yarn install --immutable
- name: Build
run: yarn build
- name: Cleanup
run: node test-cleanup.js
6 changes: 5 additions & 1 deletion __tests__/messages.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dotenv/config';
import { beforeAll, describe, expect, it } from 'vitest';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { createTestClient } from './create-test-client';
import { StreamChannel } from '../src/StreamChannel';
import { StreamClient } from '../src/StreamClient';
Expand Down Expand Up @@ -188,4 +188,8 @@ describe('messages API', () => {
`Stream error code 4: GetMessage failed with error: "Message with id ${messageId} doesn't exist"`,
);
});

afterAll(async () => {
await channel.delete({ hardDelete: true });
});
});
4 changes: 3 additions & 1 deletion test-cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const cleanUpChannels = async () => {

await Promise.all(
channels.map((c) =>
client.chat.channel(c.channel.type, c.channel.id).delete(),
client.chat
.channel(c.channel.type, c.channel.id)
.delete({ hardDelete: true }),
),
);
};
Expand Down

0 comments on commit 25e42d9

Please sign in to comment.