Fix cache issue in version update indicator #69
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: Docker Build & Publish | |
| on: | |
| push: | |
| branches: [develop] | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: "Branch to build from" | |
| required: false | |
| default: develop | |
| env: | |
| REGISTRY: ghcr.io | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| service: | |
| - name: frontend | |
| image: librislog | |
| dockerfile: ./frontend/Dockerfile | |
| context: ./frontend | |
| - name: backend | |
| image: librislog-api | |
| dockerfile: ./backend/Dockerfile | |
| context: ./backend | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.inputs.branch || github.ref }} | |
| - name: Derive version | |
| id: version | |
| run: | | |
| if [ "${{ github.event_name }}" = "release" ]; then | |
| VERSION="${{ github.event.release.tag_name }}" | |
| else | |
| VERSION="$(git describe --tags --always 2>/dev/null || echo 'v0.0.0-dev')" | |
| fi | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "sha_short=$(echo '${{ github.sha }}' | cut -c1-7)" >> "$GITHUB_OUTPUT" | |
| - name: Sanitize version for Docker tag | |
| id: sanitize | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| SANITIZED="$(echo "$VERSION" | sed 's/[^a-zA-Z0-9_.-]/-/g')" | |
| SANITIZED="$(echo "$SANITIZED" | sed 's/^[^a-zA-Z0-9_]\+//')" | |
| echo "sanitized_tag=${SANITIZED:0:128}" >> "$GITHUB_OUTPUT" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate image tags | |
| id: tags | |
| run: | | |
| IMAGE="${{ env.REGISTRY }}/${{ github.repository }}/${{ matrix.service.image }}" | |
| SHA_SHORT="${{ steps.version.outputs.sha_short }}" | |
| if [ "${{ github.event_name }}" = "release" ]; then | |
| SANITIZED="${{ steps.sanitize.outputs.sanitized_tag }}" | |
| TAGS="${IMAGE}:${SANITIZED},${IMAGE}:latest" | |
| else | |
| TAGS="${IMAGE}:develop,${IMAGE}:${SHA_SHORT}" | |
| fi | |
| echo "tags=${TAGS}" >> "$GITHUB_OUTPUT" | |
| - name: Build and push | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: ${{ matrix.service.context }} | |
| file: ${{ matrix.service.dockerfile }} | |
| push: true | |
| platforms: linux/amd64 | |
| tags: ${{ steps.tags.outputs.tags }} | |
| build-args: | | |
| APP_VERSION=${{ steps.version.outputs.version }} | |
| GIT_SHA=${{ github.sha }} | |
| ${{ matrix.service.name == 'frontend' && 'PUBLIC_DEFAULT_LOCALE=en' || '' }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |