feat: soft delete project #7
This file contains 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 and Push | |
on: | |
push: | |
branches: ['main'] | |
paths: | |
- 'firefetch/**' | |
- 'executor/**' | |
- 'server/**' | |
- 'background/**' | |
jobs: | |
check-changes: | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Check modified directories and set matrix | |
id: set-matrix | |
run: | | |
matrix="{\"include\":[" | |
if git diff --name-only HEAD^ HEAD | grep -q "^firefetch/"; then | |
matrix="$matrix{\"directory\":\"firefetch\",\"image\":\"firefetch\"}" | |
fi | |
if git diff --name-only HEAD^ HEAD | grep -q "^executor/"; then | |
if [[ "$matrix" != "{\"include\":[" ]]; then | |
matrix="$matrix," | |
fi | |
matrix="$matrix{\"directory\":\"executor\",\"image\":\"cloud-ide-executor\"}" | |
fi | |
if git diff --name-only HEAD^ HEAD | grep -q "^server/"; then | |
if [[ "$matrix" != "{\"include\":[" ]]; then | |
matrix="$matrix," | |
fi | |
matrix="$matrix{\"directory\":\"server\",\"image\":\"cloud-ide-server\"}" | |
fi | |
if git diff --name-only HEAD^ HEAD | grep -q "^background/"; then | |
if [[ "$matrix" != "{\"include\":[" ]]; then | |
matrix="$matrix," | |
fi | |
matrix="$matrix{\"directory\":\"background\",\"image\":\"cloud-ide-background\"}" | |
fi | |
matrix="$matrix]}" | |
echo "matrix=$matrix" >> "$GITHUB_OUTPUT" | |
build: | |
needs: check-changes | |
if: fromJson(needs.check-changes.outputs.matrix).include[0] | |
strategy: | |
matrix: ${{ fromJson(needs.check-changes.outputs.matrix) }} | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Get short SHA | |
id: short_sha | |
run: echo "short_sha=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" | |
- name: Generate Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: jaypatel1210/${{ matrix.image }} | |
tags: | | |
type=raw,value=${{ steps.short_sha.outputs.short_sha }} | |
type=raw,value=latest | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: ${{ matrix.directory }} | |
file: ${{ matrix.directory }}/Dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |