diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0cfaa25..ab882ea 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,18 +1,66 @@ name: Pull Request - on: pull_request: branches: - main - + types: + - opened + - edited + - synchronize jobs: + pr-title: + runs-on: ubuntu-latest + steps: + - name: Check PR Title + uses: deepakputhraya/action-pr-title@master + with: + allowed_prefixes: 'Breaking:,Fix:,Update:,New:,Build:,Upgrade:,Chore:,NoBuild:' + prefix_case_sensitive: true + lint: + runs-on: ubuntu-latest + steps: + # pull the repo + - name: Check out Git repository + uses: actions/checkout@v2 + # setup node + - name: Setup Node.js 18 + uses: actions/setup-node@v2 + with: + node-version: 18 + # install dependencies + - name: Install Node.js dependencies + run: npm ci + # run eslint + - name: Run linters + uses: wearerequired/lint-action@master + with: + auto_fix: false + eslint: true + eslint_fix: false + eslint_extensions: "js,ts" build: runs-on: ubuntu-latest - steps: + # pull the repo + - name: Check out Git repository + uses: actions/checkout@v2 + # setup node + - name: Setup Node.js 18 + uses: actions/setup-node@v2 + with: + node-version: 18 + # install dependencies + - name: Install Node.js dependencies + run: npm ci + # build the app + - name: Build TVBot + run: npm run build + build_docker: + runs-on: ubuntu-latest + steps: + # pull the repo - name: Checkout uses: actions/checkout@v3 - # just check that it builds, dont push it anywhere cuz whatever - name: Build and push uses: docker/build-push-action@v3 diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index c99919e..bcb693b 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,41 +1,46 @@ -name: SemanticRelease - +name: Push on: workflow_dispatch: push: branches: - main - + tags: + - '*.*.*' jobs: - build: + release: + name: Semantic Release runs-on: ubuntu-latest - + if: startsWith(github.ref, 'refs/heads/') steps: - name: Checkout uses: actions/checkout@v3 with: persist-credentials: false - - name: Setup Node.js 18 uses: actions/setup-node@v2 with: node-version: 18 - - name: Install Semantic Release run: npm install semantic-release @codedependant/semantic-release-docker conventional-changelog-eslint - - name: Semantic Release env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} DOCKER_REGISTRY_USER: ${{ github.actor }} DOCKER_REGISTRY_PASSWORD: ${{ secrets.GHCR_TOKEN }} run: npx semantic-release - - - name: Slack Notification - uses: rtCamp/action-slack-notify@v2 + notify: + name: Discord Notify + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Extract tag name + id: tag + run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + - name: Discord notification + uses: Ilshidur/action-discord@master env: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} - SLACK_ICON: https://avatars.githubusercontent.com/u/9919?s=200&v=4 - SLACK_USERNAME: GitHub Actions - SLACK_COLOR: ${{ job.status }} - SLACK_FOOTER: "" + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + with: + args: 'Version {{ TAG_NAME }} of {{ EVENT_PAYLOAD.repository.full_name }} has been released!' diff --git a/package.json b/package.json index 1c6fa43..128549a 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "scripts": { "build": "node esbuild.mjs", "dev": "export NODE_ENV=development; node --enable-source-maps esbuild.mjs", + "lint": "eslint 'src/**'", "db:migrate": "prisma migrate dev", "db:studio": "prisma studio" }, diff --git a/src/app.ts b/src/app.ts index ff95db2..5e5c9f6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -60,6 +60,7 @@ export class App { // run initial scheduled activities setTVDBLoadingActivity(user) if (process.env.UPDATE_SHOWS !== 'false') await checkForAiringEpisodes() + await pruneUnsubscribedShows() void scheduleAiringMessages(this) void setRandomShowActivity(user) @@ -70,6 +71,7 @@ export class App { schedule.scheduleJob('lifecycle:4hours:fetchEpisoded', '0 */4 * * *', async () => { setTVDBLoadingActivity(user) await checkForAiringEpisodes() + await pruneUnsubscribedShows() await scheduleAiringMessages(this) void setRandomShowActivity(user) }) diff --git a/src/commands/unlink.ts b/src/commands/unlink.ts index a9643b3..f22e796 100644 --- a/src/commands/unlink.ts +++ b/src/commands/unlink.ts @@ -4,6 +4,7 @@ import { type CommandV2 } from '../interfaces/command' import { type App } from '../app' import { ProgressError } from '../interfaces/error' import { ProgressMessageBuilder } from '../lib/progressMessages' +import { pruneUnsubscribedShows } from 'src/lib/shows' export const command: CommandV2 = { slashCommand: { @@ -113,6 +114,8 @@ export const command: CommandV2 = { } }) + await pruneUnsubscribedShows() + return await interaction.editReply({ content: `Unlinked ${s.count} shows from <#${channelId}>`, components: [] }) } } diff --git a/src/lib/shows.ts b/src/lib/shows.ts index 6bf6712..6c8c1df 100644 --- a/src/lib/shows.ts +++ b/src/lib/shows.ts @@ -234,7 +234,7 @@ export async function removeAllSubscriptions (id: string, idType: keyof Destinat * removes all shows that have no destinations */ export async function pruneUnsubscribedShows (): Promise { - await client.show.deleteMany({ + const result = await client.show.deleteMany({ where: { destinations: { isEmpty: true @@ -242,5 +242,5 @@ export async function pruneUnsubscribedShows (): Promise { } }) - console.info('Pruned shows with no destinations') + console.info(`Pruned shows ${result.count} with no destinations`) }