Commit a8d09818 by Archer Committed by GitHub

update action (#6569)

* action

* action

* action
parent d6db937a
name: Build Docs Preview (Unprivileged) name: Preview docs build
on: on:
pull_request: pull_request:
...@@ -34,6 +34,12 @@ jobs: ...@@ -34,6 +34,12 @@ jobs:
id: datetime id: datetime
run: echo "datetime=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT run: echo "datetime=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
- name: Save PR metadata
run: |
mkdir -p /tmp/pr-metadata
echo "${{ github.event.pull_request.number }}" > /tmp/pr-metadata/pr-number.txt
echo "${{ github.event.pull_request.head.sha }}" > /tmp/pr-metadata/pr-sha.txt
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
...@@ -58,5 +64,21 @@ jobs: ...@@ -58,5 +64,21 @@ jobs:
path: /tmp/fastgpt-docs-${{ steps.datetime.outputs.datetime }}.tar path: /tmp/fastgpt-docs-${{ steps.datetime.outputs.datetime }}.tar
retention-days: 1 retention-days: 1
- name: Upload PR metadata
uses: actions/upload-artifact@v4
with:
name: pr-metadata-docs-${{ steps.datetime.outputs.datetime }}
path: /tmp/pr-metadata/
retention-days: 1
call-push-workflow:
needs: build-docs-image
uses: ./.github/workflows/preview-docs-push.yml
secrets: inherit
with:
pr_number: ${{ github.event.pull_request.number }}
datetime: ${{ needs.build-docs-image.outputs.datetime }}
run_id: ${{ github.run_id }}
outputs: outputs:
datetime: ${{ steps.datetime.outputs.datetime }} datetime: ${{ steps.datetime.outputs.datetime }}
name: Deploy Docs Preview (Privileged) name: Preview docs push
on: on:
workflow_run: workflow_call:
workflows: ["Build Docs Preview (Unprivileged)"] inputs:
types: [completed] pr_number:
branches: required: true
- '**' # 监听所有分支 type: string
datetime:
required: true
type: string
run_id:
required: true
type: string
permissions: permissions:
contents: read contents: read
...@@ -13,67 +19,40 @@ permissions: ...@@ -13,67 +19,40 @@ permissions:
attestations: write attestations: write
id-token: write id-token: write
pull-requests: write pull-requests: write
issues: write # Required for issue-comment (PR comments use Issues API) issues: write # Required for issue-comment (PR comments use Issues API)
jobs: jobs:
push-and-deploy: push-and-deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
steps: steps:
- name: Get PR information - name: Download PR metadata
id: pr uses: actions/download-artifact@v4
uses: actions/github-script@v7
with: with:
script: | name: pr-metadata-docs-${{ inputs.datetime }}
// 获取触发工作流的 PR 信息 path: /tmp/pr-metadata/
const { data: pullRequests } = await github.rest.pulls.list({ run-id: ${{ inputs.run_id }}
owner: context.repo.owner, github-token: ${{ secrets.GITHUB_TOKEN }}
repo: context.repo.repo,
state: 'open', - name: Read PR information
}); id: pr
run: |
// 查找匹配的 PR(支持 fork 仓库) PR_NUMBER="${{ inputs.pr_number }}"
const pr = pullRequests.find(pr => echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT
pr.head.ref === context.payload.workflow_run.head_branch && echo "Found PR #$PR_NUMBER"
pr.head.sha === context.payload.workflow_run.head_sha
); - name: Get artifact name
if (!pr) {
core.setFailed('No open PR found for this branch and commit');
return;
}
core.setOutput('number', pr.number);
- name: Get workflow artifacts
uses: actions/github-script@v7
id: artifacts id: artifacts
with: run: |
script: | echo "datetime=${{ inputs.datetime }}" >> $GITHUB_OUTPUT
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ echo "artifact_name=fastgpt-docs-${{ inputs.datetime }}" >> $GITHUB_OUTPUT
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const artifact = artifacts.data.artifacts[0];
if (!artifact) {
core.setFailed('No artifact found');
return;
}
// Extract datetime from artifact name
const datetime = artifact.name.replace('fastgpt-docs-', '');
core.setOutput('datetime', datetime);
core.setOutput('artifact_name', artifact.name);
- name: Download image artifact - name: Download image artifact
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: ${{ steps.artifacts.outputs.artifact_name }} name: ${{ steps.artifacts.outputs.artifact_name }}
path: /tmp/ path: /tmp/
run-id: ${{ github.event.workflow_run.id }} run-id: ${{ inputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Load Docker image - name: Load Docker image
......
name: FastGPT Build (Unprivileged) name: Preview fastgpt build
on: on:
pull_request: pull_request:
...@@ -33,6 +33,12 @@ jobs: ...@@ -33,6 +33,12 @@ jobs:
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }} ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0 fetch-depth: 0
- name: Save PR metadata
run: |
mkdir -p /tmp/pr-metadata
echo "${{ github.event.pull_request.number }}" > /tmp/pr-metadata/pr-number.txt
echo "${{ github.event.pull_request.head.sha }}" > /tmp/pr-metadata/pr-sha.txt
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
with: with:
...@@ -88,3 +94,24 @@ jobs: ...@@ -88,3 +94,24 @@ jobs:
name: ${{ steps.config.outputs.IMAGE_NAME }}-${{ github.sha }} name: ${{ steps.config.outputs.IMAGE_NAME }}-${{ github.sha }}
path: /tmp/${{ steps.config.outputs.IMAGE_NAME }}-${{ github.sha }}.tar path: /tmp/${{ steps.config.outputs.IMAGE_NAME }}-${{ github.sha }}.tar
retention-days: 1 retention-days: 1
- name: Upload PR metadata
uses: actions/upload-artifact@v4
with:
name: pr-metadata-${{ matrix.image }}-${{ github.sha }}
path: /tmp/pr-metadata/
retention-days: 1
call-push-workflow:
needs: build-preview-images
strategy:
matrix:
image: [fastgpt, sandbox, mcp_server]
fail-fast: false
uses: ./.github/workflows/preview-fastgpt-push.yml
secrets: inherit
with:
pr_number: ${{ github.event.pull_request.number }}
pr_sha: ${{ github.sha }}
run_id: ${{ github.run_id }}
image: ${{ matrix.image }}
name: FastGPT Push (Privileged) name: Preview fastgpt push
on: on:
workflow_run: workflow_call:
workflows: ["FastGPT Build (Unprivileged)"] inputs:
types: [completed] pr_number:
branches: required: true
- '**' # 监听所有分支 type: string
pr_sha:
required: true
type: string
run_id:
required: true
type: string
image:
required: true
type: string
jobs: jobs:
push-preview-images: push-preview-images:
# 只在构建成功时运行
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions: permissions:
contents: read contents: read
packages: write packages: write
attestations: write attestations: write
id-token: write id-token: write
pull-requests: write pull-requests: write
issues: write # Required for issue-comment (PR comments use Issues API) issues: write # Required for issue-comment (PR comments use Issues API)
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
strategy:
matrix:
image: [fastgpt, sandbox, mcp_server]
fail-fast: false
steps: steps:
- name: Get PR information - name: Read PR information
id: pr id: pr
uses: actions/github-script@v7 run: |
with: echo "number=${{ inputs.pr_number }}" >> $GITHUB_OUTPUT
script: | echo "sha=${{ inputs.pr_sha }}" >> $GITHUB_OUTPUT
// 获取触发工作流的 PR 信息 echo "Found PR #${{ inputs.pr_number }} (SHA: ${{ inputs.pr_sha }})"
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
});
// 查找匹配的 PR(支持 fork 仓库)
const pr = pullRequests.find(pr =>
pr.head.ref === context.payload.workflow_run.head_branch &&
pr.head.sha === context.payload.workflow_run.head_sha
);
if (!pr) {
core.setFailed('No open PR found for this branch and commit');
return;
}
core.setOutput('number', pr.number);
core.setOutput('sha', context.payload.workflow_run.head_sha);
- name: Set image config - name: Set image config
id: config id: config
run: | run: |
SHA="${{ steps.pr.outputs.sha }}" SHA="${{ steps.pr.outputs.sha }}"
if [[ "${{ matrix.image }}" == "fastgpt" ]]; then if [[ "${{ inputs.image }}" == "fastgpt" ]]; then
echo "IMAGE_NAME=fastgpt" >> $GITHUB_OUTPUT echo "IMAGE_NAME=fastgpt" >> $GITHUB_OUTPUT
echo "DESCRIPTION=fastgpt-pr image" >> $GITHUB_OUTPUT echo "DESCRIPTION=fastgpt-pr image" >> $GITHUB_OUTPUT
echo "DOCKER_REPO_TAGGED=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-pr:fastgpt_${SHA}" >> $GITHUB_OUTPUT echo "DOCKER_REPO_TAGGED=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-pr:fastgpt_${SHA}" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.image }}" == "sandbox" ]]; then elif [[ "${{ inputs.image }}" == "sandbox" ]]; then
echo "IMAGE_NAME=fastgpt-sandbox" >> $GITHUB_OUTPUT echo "IMAGE_NAME=fastgpt-sandbox" >> $GITHUB_OUTPUT
echo "DESCRIPTION=fastgpt-sandbox-pr image" >> $GITHUB_OUTPUT echo "DESCRIPTION=fastgpt-sandbox-pr image" >> $GITHUB_OUTPUT
echo "DOCKER_REPO_TAGGED=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-pr:fastgpt_sandbox_${SHA}" >> $GITHUB_OUTPUT echo "DOCKER_REPO_TAGGED=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-pr:fastgpt_sandbox_${SHA}" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.image }}" == "mcp_server" ]]; then elif [[ "${{ inputs.image }}" == "mcp_server" ]]; then
echo "IMAGE_NAME=fastgpt-mcp-server" >> $GITHUB_OUTPUT echo "IMAGE_NAME=fastgpt-mcp-server" >> $GITHUB_OUTPUT
echo "DESCRIPTION=fastgpt-mcp_server-pr image" >> $GITHUB_OUTPUT echo "DESCRIPTION=fastgpt-mcp_server-pr image" >> $GITHUB_OUTPUT
echo "DOCKER_REPO_TAGGED=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-pr:fastgpt_mcp_server_${SHA}" >> $GITHUB_OUTPUT echo "DOCKER_REPO_TAGGED=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-pr:fastgpt_mcp_server_${SHA}" >> $GITHUB_OUTPUT
...@@ -77,7 +60,7 @@ jobs: ...@@ -77,7 +60,7 @@ jobs:
with: with:
name: ${{ steps.config.outputs.IMAGE_NAME }}-${{ steps.pr.outputs.sha }} name: ${{ steps.config.outputs.IMAGE_NAME }}-${{ steps.pr.outputs.sha }}
path: /tmp/ path: /tmp/
run-id: ${{ github.event.workflow_run.id }} run-id: ${{ inputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Load Docker image - name: Load Docker image
...@@ -115,7 +98,7 @@ jobs: ...@@ -115,7 +98,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
tool: issue-comment tool: issue-comment
issue-number: ${{ steps.pr.outputs.number }} issue-number: ${{ steps.pr.outputs.number }}
title: 'Preview ${{ matrix.image }} Image:' title: 'Preview ${{ inputs.image }} Image:'
body: | body: |
``` ```
${{ steps.config.outputs.DOCKER_REPO_TAGGED }} ${{ steps.config.outputs.DOCKER_REPO_TAGGED }}
...@@ -128,6 +111,6 @@ jobs: ...@@ -128,6 +111,6 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
tool: issue-comment tool: issue-comment
issue-number: ${{ steps.pr.outputs.number }} issue-number: ${{ steps.pr.outputs.number }}
title: 'Preview ${{ matrix.image }} Image Push Failed' title: 'Preview ${{ inputs.image }} Image Push Failed'
body: | body: |
Failed to push preview image. Please check workflow logs. Failed to push preview image. Please check workflow logs.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment