Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
chore: migrate workflows to use Docker Hub (#182)
Sakurad3f9729d1714
diff --git a/.github/workflows/backend-build.yml b/.github/workflows/backend-build.ymlindex d3725da7..6304522a 100644--- a/.github/workflows/backend-build.yml+++ b/.github/workflows/backend-build.yml@@ -1,6 +1,29 @@name: Build Backend Imageson:+ push:+ branches:+ - main+ paths:+ - 'project/backend/**'+ - '.github/workflows/backend-build.yml'+ workflow_dispatch:+ inputs:+ build_aitoearn_channel:+ description: 'aitoearn-channel'+ required: false+ type: boolean+ default: false+ build_aitoearn_server:+ description: 'aitoearn-server'+ required: false+ type: boolean+ default: false+ push_latest:+ description: 'Push as latest tag'+ required: false+ type: boolean+ default: falseworkflow_call:inputs:base_ref:@@ -19,20 +42,50 @@ on:value: ${{ jobs.generate-matrix.outputs.has_changes }}permissions:- id-token: writecontents: readactions: writeenv:- AWS_REGION: ap-southeast-1- ECR_REGISTRY: 339388639667.dkr.ecr.ap-southeast-1.amazonaws.com- IMAGE_REPO: aitoearn+ DOCKER_HUB_USERNAME: aitoearnNX_NO_CLOUD: true- MONOREPO_DIR: project/aitoearn-monorepo+ MONOREPO_DIR: project/backendjobs:+ parse-manual-apps:+ runs-on: ubuntu-latest+ outputs:+ manual_apps: ${{ steps.parse.outputs.manual_apps }}+ if: github.event_name == 'workflow_dispatch'+ steps:+ - name: Parse manual app selection+ id: parse+ run: |+ APPS=""++ if [ "${{ inputs.build_aitoearn_channel }}" = "true" ]; then+ APPS="aitoearn-channel"+ fi++ if [ "${{ inputs.build_aitoearn_server }}" = "true" ]; then+ if [ -n "$APPS" ]; then+ APPS="$APPS,aitoearn-server"+ else+ APPS="aitoearn-server"+ fi+ fi++ echo "manual_apps=$APPS" >> $GITHUB_OUTPUT++ if [ -n "$APPS" ]; then+ echo "✅ Manually selected apps: $APPS"+ else+ echo "⚠️ No apps selected"+ fi+generate-matrix:runs-on: ubuntu-latest+ needs: [parse-manual-apps]+ if: always() && (needs.parse-manual-apps.result == 'success' || needs.parse-manual-apps.result == 'skipped')outputs:matrix: ${{ steps.set-matrix.outputs.matrix }}has_changes: ${{ steps.set-matrix.outputs.has_changes }}@@ -45,13 +98,11 @@ jobs:fetch-depth: 0- name: Install pnpm- if: inputs.manual_apps == ''uses: pnpm/action-setup@v4with:version: 10- name: Setup Node.js- if: inputs.manual_apps == ''uses: actions/setup-node@v4with:node-version: 22@@ -59,7 +110,6 @@ jobs:cache-dependency-path: ${{ env.MONOREPO_DIR }}/pnpm-lock.yaml- name: Install dependencies- if: inputs.manual_apps == ''working-directory: ${{ env.MONOREPO_DIR }}run: pnpm install --frozen-lockfile@@ -67,26 +117,41 @@ jobs:id: detect-changesworking-directory: ${{ env.MONOREPO_DIR }}run: |- # 检查是否为手动部署模式- if [ -n "${{ inputs.manual_apps }}" ]; then- echo "🎯 手动部署模式: 使用指定的应用列表"- AFFECTED_APPS="${{ inputs.manual_apps }}"- echo "✅ 手动选择的应用: $AFFECTED_APPS"+ # Get manually selected apps (from workflow_dispatch or workflow_call)+ MANUAL_APPS=""+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then+ MANUAL_APPS="${{ needs.parse-manual-apps.outputs.manual_apps }}"+ if [ -z "$MANUAL_APPS" ]; then+ echo "⚠️ Manual trigger but no apps selected, will auto-detect affected apps"+ fi+ elif [ "${{ github.event_name }}" = "workflow_call" ] && [ -n "${{ inputs.manual_apps }}" ]; then+ MANUAL_APPS="${{ inputs.manual_apps }}"+ fi++ # Check if manual mode+ if [ -n "$MANUAL_APPS" ]; then+ echo "🎯 Manual build mode: Using specified app list"+ AFFECTED_APPS="$MANUAL_APPS"+ echo "✅ Manually selected apps: $AFFECTED_APPS"echo "affected_apps=$AFFECTED_APPS" >> $GITHUB_OUTPUTecho ""- echo "详细信息:"+ echo "Details:"for APP in $(echo "$AFFECTED_APPS" | tr ',' ' '); doecho " - $APP"doneelse- # 根据触发方式设置 base 分支+ # Set base branch based on trigger typeif [ -n "${{ inputs.base_ref }}" ]; thenBASE_REF="origin/${{ inputs.base_ref }}"- echo "📋 PR 模式: 检测从 $BASE_REF 到 HEAD 的变更"+ echo "📋 PR mode: Detecting changes from $BASE_REF to HEAD"elseBASE_REF="HEAD~1"- echo "📋 Push 模式: 检测最近一次提交的变更"+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then+ echo "📋 Manual trigger mode: Detecting changes from last commit"+ else+ echo "📋 Push mode: Detecting changes from last commit"+ fifiecho "Base: $BASE_REF"@@ -95,14 +160,14 @@ jobs:AFFECTED_APPS=$(pnpm nx show projects --affected --type=app --sep "," --exclude="@yikart/source" --exclude="browser-automation-worker" --base=$BASE_REF --head=HEAD 2>/dev/null || echo "")if [ -z "$AFFECTED_APPS" ]; then- echo "⚠️ 未检测到受影响的应用"+ echo "⚠️ No affected apps detected"echo "affected_apps=" >> $GITHUB_OUTPUTelse- echo "✅ 受影响的应用: $AFFECTED_APPS"+ echo "✅ Affected apps: $AFFECTED_APPS"echo "affected_apps=$AFFECTED_APPS" >> $GITHUB_OUTPUTecho ""- echo "详细信息:"+ echo "Details:"for APP in $(echo "$AFFECTED_APPS" | tr ',' ' '); doecho " - $APP"done@@ -114,7 +179,7 @@ jobs:run: |VERSION="$(date +%Y%m%d)-$(git rev-parse --short HEAD)"echo "version=$VERSION" >> $GITHUB_OUTPUT- echo "📦 版本: $VERSION"+ echo "📦 Version: $VERSION"- name: Generate matrixid: set-matrix@@ -126,13 +191,25 @@ jobs:if [ -z "$AFFECTED_APPS" ]; thenecho "has_changes=false" >> $GITHUB_OUTPUTecho "matrix={\"include\":[]}" >> $GITHUB_OUTPUT- echo "⚠️ 无变更,跳过构建"+ echo "⚠️ No changes, skipping build"exit 0fiecho "has_changes=true" >> $GITHUB_OUTPUT- # 构建 matrix JSON 数组+ # Determine if should push latest tag+ PUSH_LATEST=false+ if [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref }}" = "refs/heads/main" ]; then+ PUSH_LATEST=true+ echo "📌 Main branch push: Will push latest tag"+ elif [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.push_latest }}" = "true" ]; then+ PUSH_LATEST=true+ echo "📌 Manual trigger with push_latest: Will push latest tag"+ fi++ echo "push_latest=$PUSH_LATEST" >> $GITHUB_OUTPUT++ # Build matrix JSON arrayMATRIX_JSON="{"MATRIX_JSON="$MATRIX_JSON\"include\":["@@ -140,16 +217,16 @@ jobs:IFS=',' read -ra APPS <<< "$AFFECTED_APPS"for APP in "${APPS[@]}"; do- IMAGE_TAG="${{ env.ECR_REGISTRY }}/${{ env.IMAGE_REPO }}/$APP:$VERSION"+ IMAGE_TAG="${{ env.DOCKER_HUB_USERNAME }}/$APP:$VERSION"- # 添加到 matrix+ # Add to matrixif [ "$FIRST" = true ]; thenFIRST=falseelseMATRIX_JSON="$MATRIX_JSON,"fi- MATRIX_JSON="$MATRIX_JSON{\"app\":\"$APP\",\"image\":\"$IMAGE_TAG\"}"+ MATRIX_JSON="$MATRIX_JSON{\"app\":\"$APP\",\"image\":\"$IMAGE_TAG\",\"push_latest\":$PUSH_LATEST}"doneMATRIX_JSON="$MATRIX_JSON]}"@@ -157,7 +234,7 @@ jobs:echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUTecho ""- echo "🎯 Matrix 配置:"+ echo "🎯 Matrix configuration:"echo "$MATRIX_JSON" | jq .build-and-push:@@ -201,21 +278,18 @@ jobs:- name: Build applicationworking-directory: ${{ env.MONOREPO_DIR }}run: |- echo "🔨 构建应用: ${{ matrix.app }}"+ echo "🔨 Building app: ${{ matrix.app }}"pnpm nx run ${{ matrix.app }}:build- name: Prepare Docker contextworking-directory: ${{ env.MONOREPO_DIR }}run: pnpm nx run ${{ matrix.app }}:docker-context- - name: Configure AWS credentials- uses: aws-actions/configure-aws-credentials@v4+ - name: Login to Docker Hub+ uses: docker/login-action@v3with:- role-to-assume: ${{ secrets.AWS_ROLE_ARN }}- aws-region: ${{ env.AWS_REGION }}-- - name: Login to Amazon ECR- uses: aws-actions/amazon-ecr-login@v2+ username: ${{ env.DOCKER_HUB_USERNAME }}+ password: ${{ secrets.DOCKER_HUB_TOKEN }}- name: Set up Docker Buildxuses: docker/setup-buildx-action@v3@@ -225,6 +299,17 @@ jobs:image=moby/buildkit:latestbuildkitd-flags: --debug+ - name: Prepare tags+ id: tags+ run: |+ TAGS="${{ matrix.image }}"+ if [ "${{ matrix.push_latest }}" = "true" ]; then+ TAGS="$TAGS"$'\n'"${{ env.DOCKER_HUB_USERNAME }}/${{ matrix.app }}:latest"+ fi+ echo "tags<<EOF" >> $GITHUB_OUTPUT+ echo "$TAGS" >> $GITHUB_OUTPUT+ echo "EOF" >> $GITHUB_OUTPUT+- name: Build and push Docker imageuses: docker/build-push-action@v6with:@@ -233,11 +318,11 @@ jobs:platforms: linux/amd64build-args: |APP_NAME=${{ matrix.app }}- tags: ${{ matrix.image }}+ tags: ${{ steps.tags.outputs.tags }}push: truecache-from: |type=gha,scope=${{ matrix.app }}- type=registry,ref=${{ env.ECR_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ matrix.app }}:buildcache+ type=registry,ref=${{ env.DOCKER_HUB_USERNAME }}/${{ matrix.app }}:buildcachecache-to: |type=gha,mode=max,scope=${{ matrix.app }}type=inline@@ -246,6 +331,9 @@ jobs:- name: Build summaryrun: |- echo "### ✅ 构建成功: ${{ matrix.app }}" >> $GITHUB_STEP_SUMMARY- echo "- **镜像**: \`${{ matrix.image }}\`" >> $GITHUB_STEP_SUMMARY+ echo "### ✅ Build successful: ${{ matrix.app }}" >> $GITHUB_STEP_SUMMARY+ echo "- **Image**: \`${{ matrix.image }}\`" >> $GITHUB_STEP_SUMMARY+ if [ "${{ matrix.push_latest }}" = "true" ]; then+ echo "- **Latest**: \`${{ env.DOCKER_HUB_USERNAME }}/${{ matrix.app }}:latest\`" >> $GITHUB_STEP_SUMMARY+ fidiff --git a/.github/workflows/web-build.yml b/.github/workflows/web-build.ymlindex b4b4cee4..e73964ba 100644--- a/.github/workflows/web-build.yml+++ b/.github/workflows/web-build.yml@@ -10,20 +10,24 @@ on:workflow_dispatch:inputs:version:- description: 镜像版本 (留空使用默认生成规则)+ description: Image version (leave empty to use default generation rule)required: falsetype: string+ push_latest:+ description: 'Push as latest tag'+ required: false+ type: boolean+ default: falsepermissions:id-token: writecontents: readenv:- AWS_REGION: ap-southeast-1- ECR_REGISTRY: 339388639667.dkr.ecr.ap-southeast-1.amazonaws.com- ROLE_TO_ASSUME: arn:aws:iam::339388639667:role/GithubActionsIMAGE_REPO: aitoearnAPP_NAME: aitoearn-web+ MONOREPO_DIR: project/web+ DOCKER_HUB_USERNAME: aitoearnjobs:build:@@ -39,13 +43,19 @@ jobs:- name: Configure AWS credentialsuses: aws-actions/configure-aws-credentials@v4with:- role-to-assume: ${{ env.ROLE_TO_ASSUME }}- aws-region: ${{ env.AWS_REGION }}+ role-to-assume: ${{ secrets.AWS_ROLE_ARN }}+ aws-region: ${{ secrets.AWS_REGION }}- name: Login to Amazon ECRid: login-ecruses: aws-actions/amazon-ecr-login@v2+ - name: Login to Docker Hub+ uses: docker/login-action@v3+ with:+ username: ${{ env.DOCKER_HUB_USERNAME }}+ password: ${{ secrets.DOCKER_HUB_TOKEN }}+- name: Generate versionid: versionrun: |@@ -56,29 +66,61 @@ jobs:fiecho "version=$VERSION" >> $GITHUB_OUTPUT+ - name: Determine push latest+ id: push-latest+ run: |+ PUSH_LATEST=false+ if [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref }}" = "refs/heads/main" ]; then+ PUSH_LATEST=true+ echo "📌 Main branch push: Will push latest tag"+ elif [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.push_latest }}" = "true" ]; then+ PUSH_LATEST=true+ echo "📌 Manual trigger with push_latest: Will push latest tag"+ fi+ echo "push_latest=$PUSH_LATEST" >> $GITHUB_OUTPUT++ - name: Prepare tags+ id: tags+ run: |+ TAGS="${{ secrets.ECR_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.APP_NAME }}:${{ steps.version.outputs.version }}"$'\n'"${{ env.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:${{ steps.version.outputs.version }}"+ if [ "${{ steps.push-latest.outputs.push_latest }}" = "true" ]; then+ TAGS="$TAGS"$'\n'"${{ secrets.ECR_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.APP_NAME }}:latest"$'\n'"${{ env.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:latest"+ fi+ echo "tags<<EOF" >> $GITHUB_OUTPUT+ echo "$TAGS" >> $GITHUB_OUTPUT+ echo "EOF" >> $GITHUB_OUTPUT+- name: Build and push applicationuses: docker/build-push-action@v5with:- context: ./project/web- file: ./project/web/Dockerfile+ context: ${{ env.MONOREPO_DIR }}/+ file: ${{ env.MONOREPO_DIR }}/Dockerfileplatforms: linux/amd64push: true- tags: |- ${{ env.ECR_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.APP_NAME }}:${{ steps.version.outputs.version }}- ${{ env.ECR_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.APP_NAME }}:latest+ tags: ${{ steps.tags.outputs.tags }}cache-from: type=ghacache-to: type=gha,mode=max- name: Summaryif: always()run: |- echo "## 📦 构建摘要" >> $GITHUB_STEP_SUMMARY- echo "- **应用**: ${{ env.APP_NAME }}" >> $GITHUB_STEP_SUMMARY- echo "- **版本**: ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY- echo "- **平台**: linux/amd64" >> $GITHUB_STEP_SUMMARY- echo "- **镜像**: \`${{ env.ECR_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.APP_NAME }}:${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY- echo "- **Latest**: \`${{ env.ECR_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.APP_NAME }}:latest\`" >> $GITHUB_STEP_SUMMARY+ echo "## 📦 Build Summary" >> $GITHUB_STEP_SUMMARY+ echo "- **App**: ${{ env.APP_NAME }}" >> $GITHUB_STEP_SUMMARY+ echo "- **Version**: ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY+ echo "- **Platform**: linux/amd64" >> $GITHUB_STEP_SUMMARY+ echo "" >> $GITHUB_STEP_SUMMARY+ echo "### 🐳 ECR Images" >> $GITHUB_STEP_SUMMARY+ echo "- **Version Image**: \`${{ secrets.ECR_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.APP_NAME }}:${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY+ if [ "${{ steps.push-latest.outputs.push_latest }}" = "true" ]; then+ echo "- **Latest**: \`${{ secrets.ECR_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.APP_NAME }}:latest\`" >> $GITHUB_STEP_SUMMARY+ fi+ echo "" >> $GITHUB_STEP_SUMMARY+ echo "### 🐋 Docker Hub Images" >> $GITHUB_STEP_SUMMARY+ echo "- **Version Image**: \`${{ env.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY+ if [ "${{ steps.push-latest.outputs.push_latest }}" = "true" ]; then+ echo "- **Latest**: \`${{ env.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:latest\`" >> $GITHUB_STEP_SUMMARY+ fiecho "" >> $GITHUB_STEP_SUMMARY- echo "### 🔗 快速链接" >> $GITHUB_STEP_SUMMARY- echo "- [源代码提交](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})" >> $GITHUB_STEP_SUMMARY- echo "- [构建日志](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY+ echo "### 🔗 Quick Links" >> $GITHUB_STEP_SUMMARY+ echo "- [Source Commit](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})" >> $GITHUB_STEP_SUMMARY+ echo "- [Build Log](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARYdiff --git a/project/backend/apps/aitoearn-server/config/config.js b/project/backend/apps/aitoearn-server/config/config.jsindex df6fd0fb..d8ba60cf 100644--- a/project/backend/apps/aitoearn-server/config/config.js+++ b/project/backend/apps/aitoearn-server/config/config.js@@ -21,7 +21,6 @@ const {const {CHANNEL_URL,- TASK_URL,PAYMENT_URL,} = process.envdiff --git a/project/backend/apps/aitoearn-server/src/account/account.service.ts b/project/backend/apps/aitoearn-server/src/account/account.service.tsindex 8d66acf9..8a9ef23c 100644--- a/project/backend/apps/aitoearn-server/src/account/account.service.ts+++ b/project/backend/apps/aitoearn-server/src/account/account.service.ts@@ -1,7 +1,7 @@import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common'import { QueueService } from '@yikart/aitoearn-queue'import { AccountType, AppException, ResponseCode, TableDto } from '@yikart/common'-import { Account, AccountGroup, AccountRepository, AccountStatus } from '@yikart/mongodb'+import { Account, AccountRepository, AccountStatus } from '@yikart/mongodb'import { ChannelService } from '../channel/channel.service'import { AccountPortraitReportData } from '../channel/common'import { NewAccountCrawlerData } from '../statistics/common'@@ -24,10 +24,10 @@ export class AccountService {/*** Account data reporting- * @param data+ * @param _data*/private async accountPortraitReport(- data: AccountPortraitReportData,+ _data: AccountPortraitReportData,) {}diff --git a/project/backend/apps/aitoearn-server/src/user/user.service.ts b/project/backend/apps/aitoearn-server/src/user/user.service.tsindex 59537985..5f39dd7b 100644--- a/project/backend/apps/aitoearn-server/src/user/user.service.ts+++ b/project/backend/apps/aitoearn-server/src/user/user.service.ts@@ -239,10 +239,10 @@ export class UserService {/*** Logic after login- * @param user+ * @param _user* @returns*/- async afterLogin(user: User) {+ async afterLogin(_user: User) {}diff --git a/project/backend/assets/.gitkeep b/project/backend/assets/.gitkeepnew file mode 100644index 00000000..e69de29b