cleanup #61
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: Cleanup Cloud PR | |
on: | |
repository_dispatch: | |
types: [cleanup] | |
jobs: | |
cleanup: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout private repository | |
uses: actions/checkout@v4 | |
with: | |
repository: teableio/teable-ee | |
token: ${{ secrets.PACKAGES_KEY }} | |
submodules: 'true' | |
- name: Get teable-ee SHA | |
id: get_sha | |
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
- name: Create deployment YAML | |
env: | |
NAMESPACE: 38puz7wo | |
INSTANCE_NAME: pr-cloud-${{ github.event.client_payload.pr_number }} | |
INSTANCE_DOMAIN: pr-cloud-${{ github.event.client_payload.pr_number }} | |
DISPLAY_NAME: "teable-pr-cloud-${{ github.event.client_payload.pr_number }}" | |
MAIN_IMAGE_REPOSITORY: registry.cn-shenzhen.aliyuncs.com/teable/teable-cloud | |
DB_MIGRATE_IMAGE_REPOSITORY: registry.cn-shenzhen.aliyuncs.com/teable/teable-db-migrate-cloud | |
IMAGE_TAG: ${{ steps.get_sha.outputs.sha }}-amd64 | |
run: | | |
cp .github/workflows/templates/preview-template.yaml deploy.yaml | |
sed -i "s#__NAMESPACE__#${{ env.NAMESPACE }}#g" 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#__DB_MIGRATE_IMAGE_REPOSITORY__#${{ env.DB_MIGRATE_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: Delete deployment | |
uses: actions-hub/kubectl@master | |
env: | |
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} | |
with: | |
args: delete -f deploy.yaml --ignore-not-found=true | |
- name: Create cleanup status comment | |
run: | | |
PR_NUMBER="${{ github.event.client_payload.pr_number }}" | |
MERGE_STATUS="${{ github.event.client_payload.merged && 'Merged' || 'Closed' }}" | |
BODY="** 🧹 Preview Environment Cleanup ** * PR #${PR_NUMBER} has been ${MERGE_STATUS} * Cloud preview environment has been deleted * Cleanup time: $(date -u '+%Y-%m-%dT%H:%M:%SZ')" | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.PACKAGES_KEY }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/teableio/teable-ee/issues/${PR_NUMBER}/comments" \ | |
-d "{\"body\":\"${BODY}\"}" |