Preview Admin Image - Push #1638
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: Preview Admin Image - Push | |
| on: | |
| workflow_run: | |
| workflows: ['Preview Admin Image - Build'] | |
| types: [completed] | |
| concurrency: | |
| group: 'preview-admin-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 | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Download build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: preview-admin-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/fastgpt-pro-image.tar | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Tag and push Docker image | |
| run: | | |
| SHA="${{ steps.pr.outputs.sha }}" | |
| docker tag fastgpt-pro-pr:${SHA} \ | |
| ghcr.io/${{ github.repository_owner }}/fastgpt-pr:admin_${SHA} | |
| docker push ghcr.io/${{ github.repository_owner }}/fastgpt-pr:admin_${SHA} | |
| - name: Format preview timestamp | |
| id: preview_time | |
| run: | | |
| echo "value=$(TZ='Asia/Shanghai' date '+%Y-%m-%d %H:%M:%S (UTC+8)')" >> "$GITHUB_OUTPUT" | |
| - 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-admin-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} | |
| ✅ **Admin Preview Image Ready!** | |
| \`\`\` | |
| ghcr.io/${{ github.repository_owner }}/fastgpt-pr:admin_${{ steps.pr.outputs.sha }} | |
| \`\`\` | |
| 🕒 Time: ${{ steps.preview_time.outputs.value }} | |
| `; | |
| 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 | |
| }); | |
| } |