Merge pull request #803 from codex-team/master #1250
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: Build and push docker image | |
| on: | |
| push: | |
| workflow_dispatch: | |
| env: | |
| DOCKER_REPO: ${{ secrets.DOCKER_USERNAME }}/hawk-garage | |
| jobs: | |
| build: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # Compute deploy tag | |
| - name: Prepare deploy tag | |
| id: deploy | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| case "${GITHUB_REF_NAME}" in | |
| stage|prod|prod-ru) | |
| echo "is_deploy=true" >> "$GITHUB_OUTPUT" | |
| echo "tag=${GITHUB_REF_NAME}-${GITHUB_SHA::7}-$(date +%s)" >> "$GITHUB_OUTPUT" | |
| ;; | |
| *) | |
| echo "is_deploy=false" >> "$GITHUB_OUTPUT" | |
| echo "tag=" >> "$GITHUB_OUTPUT" | |
| ;; | |
| esac | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: Make stage envfile | |
| if: github.ref_name == 'stage' | |
| uses: SpicyPizza/create-envfile@v1 | |
| with: | |
| envkey_VITE_HAWK_TOKEN: ${{ secrets.HAWK_TOKEN_PROD }} | |
| envkey_VITE_AMPLITUDE_TOKEN: ${{ secrets.AMPLITUDE_TOKEN_PROD }} | |
| envkey_VITE_CLOUDPAYMENTS_PUBLIC_ID: ${{ secrets.CP_PUBLIC_ID_STAGE }} | |
| envkey_VITE_API_ENDPOINT: "https://api-staging.hawk.so" | |
| envkey_VITE_FREE_PLAN_ID: ${{ secrets.FREE_PLAN_ID }} | |
| # envkey_VITE_HAWK_TOKEN: ${{ secrets.HAWK_TOKEN_STAGE }} | |
| # envkey_VITE_AMPLITUDE_TOKEN: ${{ secrets.AMPLITUDE_TOKEN_STAGE }} | |
| # envkey_VITE_CLOUDPAYMENTS_PUBLIC_ID: ${{ secrets.CP_PUBLIC_ID_STAGE }} | |
| # envkey_VITE_API_ENDPOINT: "https://api.stage.hawk.so" | |
| - name: Make prod envfile | |
| if: github.ref_name == 'prod' | |
| uses: SpicyPizza/create-envfile@v1 | |
| with: | |
| envkey_VITE_HAWK_TOKEN: ${{ secrets.HAWK_TOKEN_PROD }} | |
| envkey_VITE_AMPLITUDE_TOKEN: ${{ secrets.AMPLITUDE_TOKEN_PROD }} | |
| envkey_VITE_CLOUDPAYMENTS_PUBLIC_ID: ${{ secrets.CP_PUBLIC_ID_PROD }} | |
| envkey_VITE_API_ENDPOINT: "https://api.hawk.so" | |
| envkey_VITE_FREE_PLAN_ID: ${{ secrets.FREE_PLAN_ID }} | |
| - name: Make prod-ru envfile | |
| if: github.ref_name == 'prod-ru' | |
| uses: SpicyPizza/create-envfile@v1 | |
| with: | |
| envkey_VITE_HAWK_TOKEN: ${{ secrets.HAWK_TOKEN_PROD }} | |
| envkey_VITE_AMPLITUDE_TOKEN: ${{ secrets.AMPLITUDE_TOKEN_PROD }} | |
| envkey_VITE_CLOUDPAYMENTS_PUBLIC_ID: ${{ secrets.CP_PUBLIC_ID_PROD }} | |
| envkey_VITE_API_ENDPOINT: "https://api.hawk-tracker.ru" | |
| envkey_VITE_FREE_PLAN_ID: ${{ secrets.FREE_PLAN_ID }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| if: steps.deploy.outputs.is_deploy == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.DOCKER_REPO }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=raw,value=${{ steps.deploy.outputs.tag }},enable=${{ steps.deploy.outputs.is_deploy == 'true' }} | |
| - name: Build and push image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| tags: ${{ steps.meta.outputs.tags }} | |
| push: ${{ steps.deploy.outputs.is_deploy == 'true' }} | |
| - name: Send docker tag to chat | |
| if: ${{ success() && steps.deploy.outputs.is_deploy == 'true' }} | |
| uses: codex-team/action-codexbot-notify@v1 | |
| with: | |
| webhook: ${{ secrets.CODEXBOT_NOTIFY_WEBHOOK }} | |
| parse_mode: HTML | |
| disable_web_page_preview: true | |
| message: | | |
| <b>Docker tag</b>: <code>${{ steps.deploy.outputs.tag }}</code> | |
| <b>Image</b>: <code>${{ env.DOCKER_REPO }}:${{ steps.deploy.outputs.tag }}</code> |