-
Notifications
You must be signed in to change notification settings - Fork 11.6k
fix: make cookie SameSite configurable for cross-origin deployments #4280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
forecho
wants to merge
10
commits into
QuantumNous:main
from
richcalls:fix/cookie-samesite-cross-origin
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8335cb8
feat: add deployment automation (#1)
forecho 9198c64
fix: address code review feedback and CI Slack notification failure
forecho 77a279d
fix: use bun instead of npm for frontend CI/CD
forecho 879006f
fix: build frontend before Go compile (go:embed requires web/dist)
forecho f1b2a11
fix: ensure correct file ownership for new-api service user
forecho a1dbad7
docs: add PORT config to .env.example
forecho 44d97fd
fix: correct env var name VITE_REACT_APP_SERVER_URL
forecho 185aaf7
fix: add CORS headers for Cloudflare Pages frontend
forecho 1a1de13
fix: allow all request headers in CORS config
forecho b25ab49
fix: make cookie SameSite configurable for cross-origin deployments
forecho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| name: Backend CI/CD | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - '**.go' | ||
| - 'go.mod' | ||
| - 'go.sum' | ||
| - 'VERSION' | ||
| - 'deploy/**' | ||
| - '.github/workflows/deploy-backend.yml' | ||
| workflow_dispatch: | ||
|
|
||
| # 防止同时部署 | ||
| concurrency: | ||
| group: backend-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| env: | ||
| GO_VERSION: '1.23' | ||
| API_DOMAIN: 'api.4aicode.com' | ||
| BACKEND_PORT: '3002' | ||
| BACKEND_HOST: '127.0.0.1' | ||
| SSL_EMAIL: 'ceo@richcalls.xyz' | ||
| VITE_REACT_APP_SERVER_URL: 'https://api.4aicode.com' | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Bun | ||
| uses: oven-sh/setup-bun@v2 | ||
|
|
||
| - name: 构建前端(Go embed 依赖) | ||
| working-directory: ./web | ||
| run: bun install --frozen-lockfile && bun run build | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
|
|
||
| - name: Run tests | ||
| run: go test ./... -v | ||
| continue-on-error: true | ||
|
|
||
| - name: Slack 通知 | ||
| if: always() | ||
| continue-on-error: true | ||
| uses: forecho/slack-deploy-action@v1 | ||
| with: | ||
| slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }} | ||
| slack_channel_id: ${{ secrets.SLACK_CHANNEL_ID }} | ||
| language: zh | ||
| service_name: 后端测试 | ||
|
|
||
| build-and-deploy: | ||
| needs: test | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Bun | ||
| uses: oven-sh/setup-bun@v2 | ||
|
|
||
| - name: 构建前端(Go embed 依赖) | ||
| working-directory: ./web | ||
| run: bun install --frozen-lockfile && bun run build | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
|
|
||
| - name: 编译 | ||
| run: | | ||
| VERSION=$(cat VERSION 2>/dev/null || echo "dev") | ||
| CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ | ||
| -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=${VERSION}'" \ | ||
| -o new-api | ||
|
|
||
| - name: 上传到服务器 | ||
| uses: appleboy/scp-action@v0.1.7 | ||
| with: | ||
| host: ${{ secrets.DEPLOY_HOST }} | ||
| username: ${{ secrets.DEPLOY_USER }} | ||
| key: ${{ secrets.DEPLOY_SSH_KEY }} | ||
| source: "new-api,deploy/" | ||
| target: "/tmp/new-api-deploy/" | ||
| strip_components: 0 | ||
|
|
||
| - name: 执行部署 | ||
| uses: appleboy/ssh-action@v1 | ||
| with: | ||
| host: ${{ secrets.DEPLOY_HOST }} | ||
| username: ${{ secrets.DEPLOY_USER }} | ||
| key: ${{ secrets.DEPLOY_SSH_KEY }} | ||
| script: | | ||
| cd /tmp/new-api-deploy | ||
| chmod +x deploy/deploy.sh | ||
| sudo ./deploy/deploy.sh "/tmp/new-api-deploy" "${{ env.API_DOMAIN }}" "${{ env.BACKEND_PORT }}" "${{ env.BACKEND_HOST }}" "${{ env.SSL_EMAIL }}" | ||
|
|
||
| - name: Slack 通知 | ||
| if: always() | ||
| continue-on-error: true | ||
| uses: forecho/slack-deploy-action@v1 | ||
| with: | ||
| slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }} | ||
| slack_channel_id: ${{ secrets.SLACK_CHANNEL_ID }} | ||
| language: zh | ||
| service_name: 后端部署 | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| name: Frontend CI/CD | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - 'web/**' | ||
| - '.github/workflows/deploy-web.yml' | ||
| pull_request: | ||
| branches: [main] | ||
| paths: | ||
| - 'web/**' | ||
|
|
||
| permissions: | ||
| contents: read | ||
| deployments: write | ||
| pull-requests: write | ||
|
|
||
| env: | ||
| VITE_REACT_APP_SERVER_URL: 'https://api.4aicode.com' | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Bun | ||
| uses: oven-sh/setup-bun@v2 | ||
|
|
||
| - name: 安装依赖 | ||
| working-directory: ./web | ||
| run: bun install --frozen-lockfile | ||
|
|
||
| - name: 构建 | ||
| working-directory: ./web | ||
| run: bun run build | ||
|
|
||
| - name: 保存构建产物 | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: web-dist | ||
| path: web/dist | ||
|
|
||
| - name: Slack 通知 | ||
| if: always() | ||
| continue-on-error: true | ||
| uses: forecho/slack-deploy-action@v1 | ||
| with: | ||
| slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }} | ||
| slack_channel_id: ${{ secrets.SLACK_CHANNEL_ID }} | ||
| language: zh | ||
| service_name: 前端构建 | ||
|
|
||
| deploy: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Bun | ||
| uses: oven-sh/setup-bun@v2 | ||
|
|
||
| - name: 安装依赖 | ||
| working-directory: ./web | ||
| run: bun install --frozen-lockfile | ||
|
|
||
| - name: 构建 | ||
| working-directory: ./web | ||
| run: bun run build | ||
|
|
||
| - name: 部署到 Cloudflare Pages | ||
| uses: cloudflare/pages-action@v1 | ||
| with: | ||
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
| projectName: 4aicode | ||
| directory: web/dist | ||
| gitHubToken: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Slack 通知 | ||
| if: always() | ||
| continue-on-error: true | ||
| uses: forecho/slack-deploy-action@v1 | ||
| with: | ||
| slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }} | ||
| slack_channel_id: ${{ secrets.SLACK_CHANNEL_ID }} | ||
| language: zh | ||
| service_name: 前端部署 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 101
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 3993
Don't let failed tests still deploy to
main.Line 48 turns the test step into a soft failure, so the
build-and-deployjob at line 61 can still publish a backend aftergo testfails. That removes the only deployment gate in this workflow.Suggested fix
- name: Run tests run: go test ./... -v - continue-on-error: true📝 Committable suggestion
🤖 Prompt for AI Agents