Deploy Workspace #10
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: Deploy Workspace | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_tag: | |
| description: Optional existing stable Workspace release tag in vX.Y.Z form | |
| type: string | |
| required: false | |
| environment: | |
| description: 'Environment to run deploy' | |
| type: environment | |
| required: true | |
| default: staging | |
| runner-name: | |
| description: Runner | |
| type: choice | |
| default: 'github-runner' | |
| options: | |
| - 'github-runner' | |
| - 'shenzhen' | |
| acr-region: | |
| description: ACR registry | |
| type: choice | |
| default: 'cn-shenzhen' | |
| options: | |
| - 'cn-shenzhen' | |
| - 'us-east-1' | |
| permissions: | |
| contents: read | |
| jobs: | |
| build-docker-image: | |
| name: BuildDockerImage | |
| runs-on: ${{ inputs.runner-name == 'github-runner' && 'ubuntu-latest' || inputs.runner-name }} | |
| environment: ${{ inputs.environment }} | |
| outputs: | |
| image_tag: ${{ steps.release.outputs.image_tag }} | |
| env: | |
| GH_ACCESS_TOKEN: ${{ secrets.GH_TOKEN }} | |
| CR: univer-acr-registry.cn-shenzhen.cr.aliyuncs.com | |
| ACR_REGION: ${{ inputs.acr-region }} | |
| REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} | |
| REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| ref: ${{ inputs.release_tag == '' && github.sha || format('refs/tags/{0}', inputs.release_tag) }} | |
| - name: Resolve deployment source | |
| id: release | |
| shell: bash | |
| env: | |
| BASE_BRANCH: ${{ github.event.repository.default_branch }} | |
| DISPATCH_SHA: ${{ github.sha }} | |
| RELEASE_TAG: ${{ inputs.release_tag }} | |
| run: | | |
| set -euo pipefail | |
| if [[ -n "$RELEASE_TAG" ]]; then | |
| if [[ ! "$RELEASE_TAG" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then | |
| echo "release_tag must use stable vX.Y.Z form" >&2 | |
| exit 1 | |
| fi | |
| if [[ "$(git rev-parse "refs/tags/$RELEASE_TAG^{commit}")" != "$(git rev-parse HEAD)" ]]; then | |
| echo "Checkout does not match release tag $RELEASE_TAG" >&2 | |
| exit 1 | |
| fi | |
| if ! git merge-base --is-ancestor HEAD "refs/remotes/origin/$BASE_BRANCH"; then | |
| echo "Release tag commit must be contained in origin/$BASE_BRANCH" >&2 | |
| exit 1 | |
| fi | |
| IMAGE_TAG="$RELEASE_TAG" | |
| else | |
| IMAGE_TAG="sha-$DISPATCH_SHA" | |
| fi | |
| echo "image_tag=$IMAGE_TAG" >> "$GITHUB_OUTPUT" | |
| - uses: ./.github/actions/setup | |
| id: setup | |
| with: | |
| runner-name: ${{ inputs.runner-name }} | |
| environment: ${{ inputs.environment }} | |
| - name: Build and Push Image | |
| env: | |
| IMAGE_TAG: ${{ steps.release.outputs.image_tag }} | |
| UNIVER_WORKSPACE_BROWSER_LICENSE: ${{ secrets.UNIVER_WORKSPACE_BROWSER_LICENSE }} | |
| run: | | |
| make push_image "IMAGE_TAG=$IMAGE_TAG" "CR=$CR" | |
| deploy-k8s: | |
| name: DeployK8s | |
| runs-on: arc-runner-set | |
| needs: build-docker-image | |
| environment: ${{ inputs.environment }} | |
| env: | |
| CR: univer-acr-registry.cn-shenzhen.cr.aliyuncs.com | |
| IMAGE_TAG: ${{ needs.build-docker-image.outputs.image_tag }} | |
| steps: | |
| - name: Set FEATURE environment variable | |
| if: ${{ startsWith(inputs.environment, 'feature') }} | |
| run: echo "FEATURE=$(echo ${GITHUB_REF#refs/heads/feat/})" >> "$GITHUB_ENV" | |
| - name: Set US ACR region | |
| if: ${{ inputs.acr-region == 'us-east-1' || inputs.environment == 'prod' || inputs.environment == 'feature prod' }} | |
| run: | | |
| echo "CR=univer-acr-eastus-registry.us-east-1.cr.aliyuncs.com" >> "$GITHUB_ENV" | |
| - uses: peter-evans/repository-dispatch@v2 | |
| with: | |
| token: ${{ secrets.GH_TOKEN }} | |
| repository: dream-num/helm-chart-private | |
| event-type: ${{ vars.DISPATCH_EVENT_TYPE }} | |
| client-payload: '{"service":"colla-workspace","tag":"${{ env.IMAGE_TAG }}","feature":"${{ env.FEATURE }}","registry":"${{ env.CR }}"}' |