Merge pull request #661 from hanshino/fix/gacha-banner-datetime #488
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: redive linebot CI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| # Backend build and push job | |
| backend: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Backend build and push Docker image | |
| uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 | |
| with: | |
| context: ./app | |
| push: true | |
| tags: hanshino/redive_backend:latest | |
| cache-from: type=registry,ref=hanshino/redive_backend:buildcache | |
| cache-to: type=registry,ref=hanshino/redive_backend:buildcache,mode=max | |
| # Frontend build and push job, executed in parallel with backend | |
| frontend: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Frontend build and push Docker image | |
| uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 | |
| with: | |
| context: ./frontend | |
| push: true | |
| tags: hanshino/redive_frontend:latest | |
| cache-from: type=registry,ref=hanshino/redive_frontend:buildcache | |
| cache-to: type=registry,ref=hanshino/redive_frontend:buildcache,mode=max | |
| # Deployment via Portainer API | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: [backend, frontend] | |
| steps: | |
| - name: Redeploy stack via Portainer | |
| run: | | |
| # Get current stack file content | |
| STACK_FILE=$(curl -sf \ | |
| -H "X-API-Key: ${{ secrets.PORTAINER_API_KEY }}" \ | |
| "${{ secrets.PORTAINER_URL }}/api/stacks/${{ secrets.PORTAINER_STACK_ID }}/file" \ | |
| | jq -r '.StackFileContent') | |
| # Get current env vars | |
| STACK_ENV=$(curl -sf \ | |
| -H "X-API-Key: ${{ secrets.PORTAINER_API_KEY }}" \ | |
| "${{ secrets.PORTAINER_URL }}/api/stacks/${{ secrets.PORTAINER_STACK_ID }}" \ | |
| | jq '.Env') | |
| # Redeploy stack with pullImage to get latest images | |
| HTTP_STATUS=$(curl -sf -o /dev/null -w "%{http_code}" \ | |
| -X PUT \ | |
| -H "X-API-Key: ${{ secrets.PORTAINER_API_KEY }}" \ | |
| -H "Content-Type: application/json" \ | |
| "${{ secrets.PORTAINER_URL }}/api/stacks/${{ secrets.PORTAINER_STACK_ID }}?endpointId=${{ secrets.PORTAINER_ENDPOINT_ID }}" \ | |
| -d "$(jq -n \ | |
| --arg stackFile "$STACK_FILE" \ | |
| --argjson env "$STACK_ENV" \ | |
| '{stackFileContent: $stackFile, env: $env, prune: true, pullImage: true}')") | |
| if [ "$HTTP_STATUS" != "200" ]; then | |
| echo "::error::Stack redeploy failed with HTTP $HTTP_STATUS" | |
| exit 1 | |
| fi | |
| echo "Stack redeployed successfully" | |
| - name: Wait for containers to be ready | |
| run: sleep 15 | |
| - name: Run database migrations | |
| run: | | |
| # Create exec instance | |
| EXEC_ID=$(curl -sf \ | |
| -H "X-API-Key: ${{ secrets.PORTAINER_API_KEY }}" \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| "${{ secrets.PORTAINER_URL }}/api/endpoints/${{ secrets.PORTAINER_ENDPOINT_ID }}/docker/containers/${{ secrets.PORTAINER_BOT_CONTAINER }}/exec" \ | |
| -d '{"AttachStdout":true,"AttachStderr":true,"Cmd":["yarn","migrate"]}' \ | |
| | jq -r '.Id') | |
| if [ -z "$EXEC_ID" ] || [ "$EXEC_ID" = "null" ]; then | |
| echo "::error::Failed to create exec instance" | |
| exit 1 | |
| fi | |
| # Run exec | |
| RESULT=$(curl -sf \ | |
| -H "X-API-Key: ${{ secrets.PORTAINER_API_KEY }}" \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| "${{ secrets.PORTAINER_URL }}/api/endpoints/${{ secrets.PORTAINER_ENDPOINT_ID }}/docker/exec/$EXEC_ID/start" \ | |
| -d '{"Detach":false,"Tty":false}') | |
| echo "Migration output: $RESULT" | |
| # Check exec exit code | |
| EXIT_CODE=$(curl -sf \ | |
| -H "X-API-Key: ${{ secrets.PORTAINER_API_KEY }}" \ | |
| "${{ secrets.PORTAINER_URL }}/api/endpoints/${{ secrets.PORTAINER_ENDPOINT_ID }}/docker/exec/$EXEC_ID/json" \ | |
| | jq -r '.ExitCode') | |
| if [ "$EXIT_CODE" != "0" ]; then | |
| echo "::error::Migration failed with exit code $EXIT_CODE" | |
| exit 1 | |
| fi | |
| echo "Migration completed successfully" | |
| - name: Discord notification | |
| env: | |
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
| uses: Ilshidur/action-discord@master | |
| with: | |
| args: "{{ EVENT_PAYLOAD.repository.full_name }} 已完成部署" |