mirror of
https://github.com/labring/FastGPT.git
synced 2026-04-19 01:01:39 +08:00
b29e10cf65
* update doc * update pnpm version * update lock * update model config doc * time * update dockerfile
120 lines
3.9 KiB
YAML
120 lines
3.9 KiB
YAML
name: Preview Docs Image — Push
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: ['Preview Docs Image — Build']
|
|
types: [completed]
|
|
|
|
# Only one push at a time
|
|
concurrency:
|
|
group: 'preview-docs-push'
|
|
cancel-in-progress: false
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
attestations: write
|
|
id-token: write
|
|
pull-requests: write
|
|
issues: write
|
|
actions: read
|
|
|
|
jobs:
|
|
push:
|
|
runs-on: ubuntu-24.04
|
|
# Only push when the build succeeded
|
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
|
|
steps:
|
|
- name: Download build artifact
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: preview-docs-image
|
|
path: /tmp
|
|
run-id: ${{ github.event.workflow_run.id }}
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Read PR metadata
|
|
id: pr
|
|
run: |
|
|
echo "number=$(cat /tmp/pr-number.txt)" >> "$GITHUB_OUTPUT"
|
|
echo "sha=$(cat /tmp/pr-sha.txt)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Load Docker image
|
|
run: docker load --input /tmp/docs-image.tar
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Aliyun Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: registry.cn-hangzhou.aliyuncs.com
|
|
username: ${{ secrets.FASTGPT_ALI_IMAGE_USER }}
|
|
password: ${{ secrets.FASTGPT_ALI_IMAGE_PSW }}
|
|
|
|
- name: Tag and push Docker image
|
|
run: |
|
|
docker tag fastgpt-docs-pr:${{ steps.pr.outputs.sha }} \
|
|
${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-docs-pr:${{ steps.pr.outputs.sha }}
|
|
docker push ${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-docs-pr:${{ steps.pr.outputs.sha }}
|
|
|
|
- name: Update deployment image
|
|
env:
|
|
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG_CN }}
|
|
run: |
|
|
KUBECONFIG_FILE=$(mktemp)
|
|
trap "rm -f $KUBECONFIG_FILE" EXIT
|
|
echo "$KUBE_CONFIG" > "$KUBECONFIG_FILE"
|
|
chmod 600 "$KUBECONFIG_FILE"
|
|
|
|
kubectl --kubeconfig "$KUBECONFIG_FILE" set image deployment/fastgpt-docs-preview \
|
|
fastgpt-docs-preview=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-docs-pr:${{ steps.pr.outputs.sha }}
|
|
|
|
kubectl --kubeconfig "$KUBECONFIG_FILE" annotate deployment/fastgpt-docs-preview \
|
|
originImageName="${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-docs-pr:${{ steps.pr.outputs.sha }}" --overwrite
|
|
|
|
- name: Add PR comment on success
|
|
if: success() && steps.pr.outputs.number != ''
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
const prNumber = parseInt('${{ steps.pr.outputs.number }}');
|
|
const marker = '<!-- fastgpt-docs-preview -->';
|
|
|
|
const { data: comments } = await github.rest.issues.listComments({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: prNumber,
|
|
});
|
|
|
|
const existingComment = comments.find(comment =>
|
|
comment.body.includes(marker)
|
|
);
|
|
|
|
const commentBody = `${marker}
|
|
✅ **Docs Preview Deployed!**
|
|
|
|
🔗 [👀 Click here to visit preview](https://pueuoharpgcl.sealoshzh.site)
|
|
|
|
\`\`\`
|
|
${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-docs-pr:${{ steps.pr.outputs.sha }}
|
|
\`\`\`
|
|
`;
|
|
|
|
if (existingComment) {
|
|
await github.rest.issues.updateComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
comment_id: existingComment.id,
|
|
body: commentBody
|
|
});
|
|
} else {
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: prNumber,
|
|
body: commentBody
|
|
});
|
|
}
|