Merge pull request #62 from mafirs/fix/user-unread #90
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 & Deploy | |
| on: | |
| push: | |
| branches: [ main ] | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }} | |
| DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
| DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
| IMAGE_NAME: ${{ secrets.IMAGE_NAME || 'tentix' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Run tests | |
| run: bun run test || echo "Tests not configured" | |
| - name: Build application | |
| run: bun run build | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Set repo owner lower | |
| id: repo_owner | |
| run: echo "owner=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT" | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to Aliyun Docker Registry | |
| if: ${{ env.DOCKER_REGISTRY != '' && env.DOCKER_USERNAME != '' && env.DOCKER_PASSWORD != '' }} | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.DOCKER_REGISTRY }} | |
| username: ${{ env.DOCKER_USERNAME }} | |
| password: ${{ env.DOCKER_PASSWORD }} | |
| - name: Generate version tag | |
| id: version | |
| run: echo "tag=$(date +%Y%m%d)-${{ github.sha }}" >> "$GITHUB_OUTPUT" | |
| - name: Build and push to GHCR | |
| run: | | |
| docker build --platform linux/amd64 \ | |
| -t ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:${{ steps.version.outputs.tag }} \ | |
| -t ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:latest \ | |
| . | |
| docker push ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:${{ steps.version.outputs.tag }} | |
| docker push ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:latest | |
| - name: Build and push to Aliyun Registry | |
| if: ${{ env.DOCKER_REGISTRY != '' && env.DOCKER_USERNAME != '' && env.DOCKER_PASSWORD != '' }} | |
| run: | | |
| docker tag ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:${{ steps.version.outputs.tag }} \ | |
| ${DOCKER_REGISTRY}/${IMAGE_NAME}:${{ steps.version.outputs.tag }} | |
| docker tag ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:latest \ | |
| ${DOCKER_REGISTRY}/${IMAGE_NAME}:latest | |
| docker push ${DOCKER_REGISTRY}/${IMAGE_NAME}:${{ steps.version.outputs.tag }} | |
| docker push ${DOCKER_REGISTRY}/${IMAGE_NAME}:latest | |
| - name: Output image tags | |
| run: | | |
| echo "Images published:" | |
| echo "- ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:${{ steps.version.outputs.tag }}" | |
| echo "- ghcr.io/${{ steps.repo_owner.outputs.owner }}/tentix:latest" | |
| if [ -n "${DOCKER_REGISTRY}" ]; then | |
| echo "- ${DOCKER_REGISTRY}/${IMAGE_NAME}:${{ steps.version.outputs.tag }}" | |
| echo "- ${DOCKER_REGISTRY}/${IMAGE_NAME}:latest" | |
| fi |