2023-08-29 13:07:05 +03:00
|
|
|
name: Deploy
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
inputs:
|
|
|
|
flavor:
|
2023-12-21 10:58:16 +03:00
|
|
|
description: 'Select what enverionment to deploy to'
|
|
|
|
type: choice
|
2023-08-29 13:07:05 +03:00
|
|
|
default: canary
|
2023-12-21 10:58:16 +03:00
|
|
|
options:
|
|
|
|
- canary
|
|
|
|
- beta
|
|
|
|
- stable
|
|
|
|
- internal
|
2023-08-29 13:07:05 +03:00
|
|
|
env:
|
|
|
|
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
|
|
|
|
|
2024-03-28 07:02:13 +03:00
|
|
|
permissions:
|
|
|
|
contents: 'write'
|
|
|
|
id-token: 'write'
|
|
|
|
packages: 'write'
|
|
|
|
|
2023-08-29 13:07:05 +03:00
|
|
|
jobs:
|
2024-08-27 06:01:54 +03:00
|
|
|
output-prev-version:
|
|
|
|
name: Output previous version
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
environment: ${{ github.event.inputs.flavor }}
|
|
|
|
outputs:
|
|
|
|
prev: ${{ steps.print.outputs.version }}
|
|
|
|
namespace: ${{ steps.print.outputs.namespace }}
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Auth to Cluster
|
|
|
|
uses: './.github/actions/cluster-auth'
|
|
|
|
with:
|
|
|
|
gcp-project-number: ${{ secrets.GCP_PROJECT_NUMBER }}
|
|
|
|
gcp-project-id: ${{ secrets.GCP_PROJECT_ID }}
|
|
|
|
service-account: ${{ secrets.GCP_HELM_DEPLOY_SERVICE_ACCOUNT }}
|
|
|
|
cluster-name: ${{ secrets.GCP_CLUSTER_NAME }}
|
|
|
|
cluster-location: ${{ secrets.GCP_CLUSTER_LOCATION }}
|
|
|
|
- name: Output previous version
|
|
|
|
id: print
|
|
|
|
run: |
|
|
|
|
namespace=""
|
|
|
|
if [ "${{ github.event.inputs.flavor }}" = "canary" ]; then
|
|
|
|
namespace="dev"
|
|
|
|
elif [ "${{ github.event.inputs.flavor }}" = "beta" ]; then
|
|
|
|
namespace="beta"
|
|
|
|
elif [ "${{ github.event.inputs.flavor }}" = "stable" ]; then
|
|
|
|
namespace="production"
|
|
|
|
else
|
|
|
|
echo "Invalid flavor: ${{ github.event.inputs.flavor }}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Namespace set to: $namespace"
|
|
|
|
|
|
|
|
# Get the previous version from the deployment
|
|
|
|
prev_version=$(kubectl get deployment -n $namespace affine-graphql -o=jsonpath='{.spec.template.spec.containers[0].image}' | awk -F '-' '{print $3}')
|
|
|
|
|
|
|
|
echo "Previous version: $prev_version"
|
|
|
|
echo "version=$prev_version" >> $GITHUB_OUTPUT
|
|
|
|
echo "namesapce=$namespace" >> $GITHUB_OUTPUT
|
|
|
|
|
2024-09-10 07:03:58 +03:00
|
|
|
build-images:
|
|
|
|
name: Build Images
|
|
|
|
uses: ./.github/workflows/build-images.yml
|
|
|
|
secrets: inherit
|
2024-03-28 07:02:13 +03:00
|
|
|
with:
|
|
|
|
flavor: ${{ github.event.inputs.flavor }}
|
|
|
|
|
2023-08-29 13:07:05 +03:00
|
|
|
deploy:
|
|
|
|
name: Deploy to cluster
|
2023-11-01 10:38:15 +03:00
|
|
|
if: ${{ github.event_name == 'workflow_dispatch' }}
|
2023-08-29 13:07:05 +03:00
|
|
|
environment: ${{ github.event.inputs.flavor }}
|
|
|
|
needs:
|
2024-09-10 07:03:58 +03:00
|
|
|
- build-images
|
2023-08-29 13:07:05 +03:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2023-09-29 06:02:26 +03:00
|
|
|
- uses: actions/checkout@v4
|
2023-12-21 10:58:16 +03:00
|
|
|
- name: Setup Version
|
2023-12-21 13:00:12 +03:00
|
|
|
id: version
|
2023-12-21 10:58:16 +03:00
|
|
|
uses: ./.github/actions/setup-version
|
2023-11-28 09:59:48 +03:00
|
|
|
- name: Deploy to ${{ github.event.inputs.flavor }}
|
2023-08-29 13:07:05 +03:00
|
|
|
uses: ./.github/actions/deploy
|
|
|
|
with:
|
|
|
|
build-type: ${{ github.event.inputs.flavor }}
|
|
|
|
gcp-project-number: ${{ secrets.GCP_PROJECT_NUMBER }}
|
|
|
|
gcp-project-id: ${{ secrets.GCP_PROJECT_ID }}
|
|
|
|
service-account: ${{ secrets.GCP_HELM_DEPLOY_SERVICE_ACCOUNT }}
|
|
|
|
cluster-name: ${{ secrets.GCP_CLUSTER_NAME }}
|
|
|
|
cluster-location: ${{ secrets.GCP_CLUSTER_LOCATION }}
|
|
|
|
env:
|
2023-12-08 08:53:23 +03:00
|
|
|
APP_VERSION: ${{ steps.version.outputs.APP_VERSION }}
|
2023-08-29 13:07:05 +03:00
|
|
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
|
|
|
CANARY_DEPLOY_HOST: ${{ secrets.CANARY_DEPLOY_HOST }}
|
|
|
|
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
|
|
|
|
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
|
|
|
|
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
2023-10-18 11:06:07 +03:00
|
|
|
CAPTCHA_TURNSTILE_SECRET: ${{ secrets.CAPTCHA_TURNSTILE_SECRET }}
|
2024-04-10 14:15:31 +03:00
|
|
|
COPILOT_OPENAI_API_KEY: ${{ secrets.COPILOT_OPENAI_API_KEY }}
|
2024-04-10 15:13:39 +03:00
|
|
|
COPILOT_FAL_API_KEY: ${{ secrets.COPILOT_FAL_API_KEY }}
|
2024-04-16 16:33:07 +03:00
|
|
|
COPILOT_UNSPLASH_API_KEY: ${{ secrets.COPILOT_UNSPLASH_API_KEY }}
|
2024-05-24 11:40:33 +03:00
|
|
|
METRICS_CUSTOMER_IO_TOKEN: ${{ secrets.METRICS_CUSTOMER_IO_TOKEN }}
|
2024-02-19 17:37:08 +03:00
|
|
|
MAILER_SENDER: ${{ secrets.OAUTH_EMAIL_SENDER }}
|
|
|
|
MAILER_USER: ${{ secrets.OAUTH_EMAIL_LOGIN }}
|
|
|
|
MAILER_PASSWORD: ${{ secrets.OAUTH_EMAIL_PASSWORD }}
|
2023-08-29 13:07:05 +03:00
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
AFFINE_GOOGLE_CLIENT_ID: ${{ secrets.AFFINE_GOOGLE_CLIENT_ID }}
|
|
|
|
AFFINE_GOOGLE_CLIENT_SECRET: ${{ secrets.AFFINE_GOOGLE_CLIENT_SECRET }}
|
|
|
|
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
|
|
|
DATABASE_USERNAME: ${{ secrets.DATABASE_USERNAME }}
|
|
|
|
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
|
|
|
|
DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
|
|
|
|
GCLOUD_CONNECTION_NAME: ${{ secrets.GCLOUD_CONNECTION_NAME }}
|
|
|
|
GCLOUD_CLOUD_SQL_INTERNAL_ENDPOINT: ${{ secrets.GCLOUD_CLOUD_SQL_INTERNAL_ENDPOINT }}
|
|
|
|
REDIS_HOST: ${{ secrets.REDIS_HOST }}
|
|
|
|
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
|
|
|
|
CLOUD_SQL_IAM_ACCOUNT: ${{ secrets.CLOUD_SQL_IAM_ACCOUNT }}
|
2023-10-30 19:12:17 +03:00
|
|
|
STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
|
|
|
|
STRIPE_WEBHOOK_KEY: ${{ secrets.STRIPE_WEBHOOK_KEY }}
|
2023-12-15 16:28:12 +03:00
|
|
|
STATIC_IP_NAME: ${{ secrets.STATIC_IP_NAME }}
|
2024-08-27 06:01:54 +03:00
|
|
|
|
|
|
|
deploy-done:
|
|
|
|
needs:
|
|
|
|
- output-prev-version
|
2024-09-10 07:03:58 +03:00
|
|
|
- build-images
|
2024-08-27 06:01:54 +03:00
|
|
|
- deploy
|
|
|
|
if: always()
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
name: Post deploy message
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
with:
|
|
|
|
repository: toeverything/blocksuite
|
|
|
|
path: blocksuite
|
|
|
|
fetch-depth: 0
|
|
|
|
fetch-tags: true
|
|
|
|
- name: Setup Node.js
|
|
|
|
uses: ./.github/actions/setup-node
|
|
|
|
with:
|
|
|
|
extra-flags: 'workspaces focus @affine/changelog'
|
|
|
|
electron-install: false
|
|
|
|
- name: Output deployed info
|
|
|
|
if: ${{ always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
|
|
|
|
id: set_info
|
|
|
|
run: |
|
|
|
|
if [ "${{ github.event.inputs.flavor }}" = "canary" ]; then
|
|
|
|
echo "deployed_url=https://affine.fail" >> $GITHUB_OUTPUT
|
|
|
|
elif [ "${{ github.event.inputs.flavor }}" = "beta" ]; then
|
|
|
|
echo "deployed_url=https://insider.affine.pro" >> $GITHUB_OUTPUT
|
|
|
|
elif [ "${{ github.event.inputs.flavor }}" = "stable" ]; then
|
|
|
|
echo "deployed_url=https://app.affine.pro" >> $GITHUB_OUTPUT
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
|
|
|
- name: Post Success event to a Slack channel
|
|
|
|
if: ${{ always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
|
|
|
|
run: node ./tools/changelog/index.js
|
|
|
|
env:
|
|
|
|
CHANNEL_ID: ${{ secrets.RELEASE_SLACK_CHNNEL_ID }}
|
|
|
|
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
|
|
|
|
DEPLOYED_URL: ${{ steps.set_info.outputs.deployed_url }}
|
|
|
|
PREV_VERSION: ${{ needs.output-prev-version.outputs.prev }}
|
|
|
|
NAMESPACE: ${{ needs.output-prev-version.outputs.namespace }}
|
|
|
|
DEPLOYMENT: 'SERVER'
|
|
|
|
FLAVOR: ${{ github.event.inputs.flavor }}
|
|
|
|
BLOCKSUITE_REPO_PATH: ${{ github.workspace }}/blocksuite
|
|
|
|
- name: Post Failed event to a Slack channel
|
|
|
|
id: failed-slack
|
2024-09-03 09:55:34 +03:00
|
|
|
uses: slackapi/slack-github-action@v1.27.0
|
2024-08-27 06:01:54 +03:00
|
|
|
if: ${{ always() && contains(needs.*.result, 'failure') }}
|
|
|
|
with:
|
|
|
|
channel-id: ${{ secrets.RELEASE_SLACK_CHNNEL_ID }}
|
|
|
|
payload: |
|
|
|
|
{
|
|
|
|
"blocks": [
|
|
|
|
{
|
|
|
|
"type": "section",
|
|
|
|
"text": {
|
|
|
|
"text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Backend deploy failed `${{ github.event.inputs.flavor }}`>",
|
|
|
|
"type": "mrkdwn"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
env:
|
|
|
|
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
|
|
|
|
- name: Post Cancel event to a Slack channel
|
|
|
|
id: cancel-slack
|
2024-09-03 09:55:34 +03:00
|
|
|
uses: slackapi/slack-github-action@v1.27.0
|
2024-08-27 06:01:54 +03:00
|
|
|
if: ${{ always() && contains(needs.*.result, 'cancelled') && !contains(needs.*.result, 'failure') }}
|
|
|
|
with:
|
|
|
|
channel-id: ${{ secrets.RELEASE_SLACK_CHNNEL_ID }}
|
|
|
|
payload: |
|
|
|
|
{
|
|
|
|
"blocks": [
|
|
|
|
{
|
|
|
|
"type": "section",
|
|
|
|
"text": {
|
|
|
|
"text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Backend deploy cancelled `${{ github.event.inputs.flavor }}`>",
|
|
|
|
"type": "mrkdwn"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
env:
|
|
|
|
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
|