fix: use cache for github actions #30
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
| ## This workflow is triggered on pull requests to the 'next' branch. | |
| ## It calculates a unique temporary version for the PR and builds a Docker images | |
| name: PR Build Next | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME_BACKEND: ${{ github.repository }}-backend | |
| IMAGE_NAME_FRONTEND: ${{ github.repository }}-frontend | |
| on: | |
| pull_request: | |
| branches: [next] | |
| workflow_dispatch: # optional manual trigger | |
| jobs: | |
| build-pr-next: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.head_ref || github.ref_name }} | |
| - name: Lowercase repository in image names | |
| run: | | |
| echo "IMAGE_NAME_BACKEND=$(echo '${{ env.IMAGE_NAME_BACKEND }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
| echo "IMAGE_NAME_FRONTEND=$(echo '${{ env.IMAGE_NAME_FRONTEND }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
| - name: Compute PR-next version | |
| run: | | |
| BASE_VERSION=$(cat VERSION 2>/dev/null || echo "0.0") | |
| PR_VERSION="${BASE_VERSION}-pr${{ github.event.pull_request.number }}.${{ github.run_number }}" | |
| echo "VERSION=$PR_VERSION" >> $GITHUB_ENV | |
| - name: Set up Docker Buildx (to enable caching) | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build & Push Backend | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./docker/backend/Dockerfile.backend | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BACKEND }}:${{ env.VERSION }} | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BACKEND }}:pr-next-${{ github.event.pull_request.number }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Build & Push Frontend | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./docker/frontend/Dockerfile.frontend | |
| push: true | |
| build-args: | | |
| APP_VERSION=${{ env.VERSION }} | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_FRONTEND }}:${{ env.VERSION }} | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_FRONTEND }}:pr-next-${{ github.event.pull_request.number }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |