Based/new searchbar definition #214
Workflow file for this run
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: App Preview | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| - reopened | |
| branches: | |
| - trunk | |
| - main | |
| paths: | |
| - 'turbo-repo/apps/app/**' | |
| - 'turbo-repo/packages/ui/**' | |
| - 'turbo-repo/packages/db/**' | |
| - 'turbo-repo/packages/typescript-config/**' | |
| - 'turbo-repo/package-lock.json' | |
| - 'turbo-repo/docker/**' | |
| concurrency: | |
| group: app-preview-pr-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| packages: write | |
| pull-requests: write | |
| env: | |
| NODE_VERSION: "24" | |
| GHCR_REGISTRY: ghcr.io | |
| IMAGE_OWNER: microboxlabs | |
| IMAGE_NAME: miot-app | |
| NEXT_PUBLIC_INGEST_URL: ${{ vars.NEXT_PUBLIC_INGEST_URL }} | |
| NEXT_PUBLIC_MAPBOX_API_KEY: ${{ secrets.NEXT_PUBLIC_MAPBOX_API_KEY }} | |
| NEXT_PUBLIC_GOOGLE_MAPS_API_KEY: ${{ secrets.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY }} | |
| NEXT_PUBLIC_AUTENTIA_PATH: ${{ secrets.NEXT_PUBLIC_AUTENTIA_PATH }} | |
| jobs: | |
| build: | |
| name: Build and publish PR preview image | |
| runs-on: ubuntu-latest | |
| if: github.event.pull_request.head.repo.full_name == github.repository | |
| outputs: | |
| image: ${{ steps.image.outputs.image }} | |
| short_sha: ${{ steps.vars.outputs.short_sha }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: npm | |
| cache-dependency-path: turbo-repo/package-lock.json | |
| - name: Resolve image metadata | |
| id: vars | |
| env: | |
| PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| run: | | |
| sha="${PR_HEAD_SHA:-$GITHUB_SHA}" | |
| echo "short_sha=${sha::7}" >> "$GITHUB_OUTPUT" | |
| - name: Install dependencies | |
| run: npm ci | |
| working-directory: turbo-repo | |
| - name: Build app | |
| run: npx turbo run build --filter=@modulariot/app | |
| working-directory: turbo-repo | |
| - name: Prepare Docker context | |
| run: | | |
| mkdir -p /tmp/build-app/.next | |
| cp -r turbo-repo/apps/app/.next/standalone /tmp/build-app/.next/standalone | |
| cp -r turbo-repo/apps/app/.next/static /tmp/build-app/.next/static | |
| cp -r turbo-repo/apps/app/public /tmp/build-app/public | |
| cp turbo-repo/docker/nextjs.standalone.Dockerfile /tmp/build-app/ | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.GHCR_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| id: docker | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: /tmp/build-app/ | |
| file: /tmp/build-app/nextjs.standalone.Dockerfile | |
| platforms: linux/amd64 | |
| push: true | |
| tags: | | |
| ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }} | |
| ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }}-sha-${{ steps.vars.outputs.short_sha }} | |
| labels: | | |
| org.opencontainers.image.title=${{ env.IMAGE_NAME }} | |
| org.opencontainers.image.description=ModularIoT app PR preview build | |
| org.opencontainers.image.vendor=MicroboxLabs | |
| org.opencontainers.image.revision=${{ github.event.pull_request.head.sha }} | |
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
| build-args: | | |
| APP_NAME=app | |
| provenance: true | |
| sbom: true | |
| - name: Resolve immutable image reference | |
| id: image | |
| run: echo "image=${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}@${{ steps.docker.outputs.digest }}" >> "$GITHUB_OUTPUT" | |
| - name: Preview summary | |
| run: | | |
| echo "# App Preview" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- PR: #${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Image: \`${{ steps.image.outputs.image }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- Tags: \`pr-${{ github.event.pull_request.number }}\`, \`pr-${{ github.event.pull_request.number }}-sha-${{ steps.vars.outputs.short_sha }}\`" >> $GITHUB_STEP_SUMMARY | |
| - name: Upsert PR preview comment | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| IMAGE_REF: ${{ steps.image.outputs.image }} | |
| SHORT_SHA: ${{ steps.vars.outputs.short_sha }} | |
| run: | | |
| marker="<!-- app-preview-image -->" | |
| body="$(cat <<EOF | |
| $marker | |
| ## App preview image | |
| The latest app preview image for this PR is ready. | |
| - Immutable image: \`$IMAGE_REF\` | |
| - Moving tag: \`${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:pr-$PR_NUMBER\` | |
| - SHA tag: \`${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:pr-$PR_NUMBER-sha-$SHORT_SHA\` | |
| EOF | |
| )" | |
| comment_id="$(gh api --paginate "repos/${{ github.repository }}/issues/$PR_NUMBER/comments" \ | |
| --jq ".[] | select(.body | contains(\"$marker\")) | .id" | tail -1)" | |
| if [[ -n "$comment_id" ]]; then | |
| gh api \ | |
| --method PATCH \ | |
| "repos/${{ github.repository }}/issues/comments/$comment_id" \ | |
| -f body="$body" >/dev/null | |
| else | |
| gh pr comment "$PR_NUMBER" --body "$body" | |
| fi |