feat: lookup filter #5
Workflow file for this run
This file contains 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: Preivew PR | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
workflow_dispatch: | |
inputs: | |
pr_number: | |
description: 'PR number to build' | |
required: false | |
type: string | |
permissions: | |
pull-requests: write | |
contents: read | |
env: | |
INSTANCE_NAME: pr-${{ github.event.pull_request.number || github.event.inputs.pr_number }} | |
INSTANCE_DOMAIN: pr-${{ github.event.pull_request.number || github.event.inputs.pr_number }} | |
DISPLAY_NAME: "teable-pr-${{ github.event.pull_request.number || github.event.inputs.pr_number }}" | |
MAIN_IMAGE_REPOSITORY: registry.cn-shenzhen.aliyuncs.com/teable/teable | |
DB_MIGRATE_IMAGE_REPOSITORY: registry.cn-shenzhen.aliyuncs.com/teable/teable-db-migrate | |
IMAGE_TAG: alpha-pr-${{ github.event.pull_request.number || github.event.inputs.pr_number }} | |
jobs: | |
create-deployment-button: | |
if: github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create deployment comment | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const prNumber = context.payload.pull_request.number; | |
const workflowFileName = 'docker-alpha-push.yml'; | |
const repoName = context.payload.repository.name; | |
const repoOwner = context.payload.repository.owner.login; | |
const deployUrl = `${process.env.GITHUB_SERVER_URL}/${repoOwner}/${repoName}/actions/workflows/${workflowFileName}/trigger?ref=${context.ref}`; | |
console.log('Debug info:'); | |
console.log('Repository:', repoName); | |
console.log('Owner:', repoOwner); | |
console.log('Deploy URL:', deployUrl); | |
const commentBody = `## 🚀 Deploy Preview Environment | |
Click the button below to deploy a preview environment for this PR: | |
[![Deploy Preview](https://img.shields.io/badge/Deploy-Preview-blue?style=for-the-badge)](${deployUrl}) | |
`; | |
const comments = await github.rest.issues.listComments({ | |
...context.repo, | |
issue_number: prNumber | |
}); | |
const existingComment = comments.data.find(comment => | |
comment.body.includes('Deploy Preview Environment') | |
); | |
if (existingComment) { | |
await github.rest.issues.updateComment({ | |
...context.repo, | |
comment_id: existingComment.id, | |
body: commentBody | |
}); | |
} else { | |
await github.rest.issues.createComment({ | |
...context.repo, | |
issue_number: prNumber, | |
body: commentBody | |
}); | |
} | |
build-push: | |
if: github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- image: teable | |
file: Dockerfile | |
- image: teable-db-migrate | |
file: Dockerfile.migrate | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Login to Ali container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: registry.cn-shenzhen.aliyuncs.com | |
username: ${{ secrets.ALI_DOCKER_USERNAME }} | |
password: ${{ secrets.ALI_DOCKER_PASSWORD }} | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20.9.0 | |
- name: ⚙️ Install zx | |
run: npm install -g zx | |
- name: ⚙️ Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
registry.cn-shenzhen.aliyuncs.com/teable/${{ matrix.image }} | |
tags: | | |
type=raw,value=alpha-pr-${{ github.event.inputs.pr_number }} | |
type=sha,format=long | |
- name: 📦 Build and push | |
run: | | |
zx scripts/build-image.mjs --file=dockers/teable/${{ matrix.file }} \ | |
--build-arg="ENABLE_CSP=false" \ | |
--tag="${{ steps.meta.outputs.tags }}" \ | |
--platform="linux/amd64" \ | |
--push | |
deploy: | |
needs: build-push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Create deployment YAML | |
run: | | |
cp .github/workflows/templates/preview-template.yaml deploy.yaml | |
sed -i "s/__INSTANCE_NAME__/${{ env.INSTANCE_NAME }}/g" deploy.yaml | |
sed -i "s/__INSTANCE_DOMAIN__/${{ env.INSTANCE_DOMAIN }}/g" deploy.yaml | |
sed -i "s/__MAIN_IMAGE_REPOSITORY__/${{ env.MAIN_IMAGE_REPOSITORY }}/g" deploy.yaml | |
sed -i "s/__IMAGE_TAG__/${{ env.IMAGE_TAG }}/g" deploy.yaml | |
sed -i "s/__DISPLAY_NAME__/${{ env.DISPLAY_NAME }}/g" deploy.yaml | |
- name: Apply deploy job | |
uses: actions-hub/kubectl@master | |
env: | |
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} | |
with: | |
args: apply -f deploy.yaml | |
- name: Rollout status | |
uses: actions-hub/kubectl@master | |
env: | |
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} | |
with: | |
args: rollout status deployment/teable-${{ env.INSTANCE_NAME }} --timeout=300s | |
- name: Create deployment status comment | |
if: always() | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const success = ${{ job.status == 'success' }}; | |
const deploymentUrl = 'https://${{ env.INSTANCE_DOMAIN }}.sealosgzg.site'; | |
const status = success ? '✅ Success' : '❌ Failed'; | |
const commentBody = ` | |
## Deployment Status: ${status} | |
${success ? `🔗 Preview URL: ${deploymentUrl}` : ''} | |
`; | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.name, | |
issue_number: ${{ github.event.inputs.pr_number }}, | |
body: commentBody | |
}); |