name: Build & Release on: push: branches: [main] workflow_dispatch: concurrency: group: build cancel-in-progress: false jobs: build: runs-on: ubuntu-latest if: "!startsWith(github.event.head_commit.message, 'chore: bump version')" env: REGISTRY: registry.digitalocean.com/lunarfront GIT_REMOTE: git2.lunarfront.tech DOCKER_HOST: tcp://localhost:2375 steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.BOT_TOKEN }} - name: Determine version bump id: bump run: | COMMIT_MSG=$(git log -1 --pretty=%s) if echo "$COMMIT_MSG" | grep -qiE "^breaking(\(.+\))?:|^.+!:"; then echo "type=major" >> $GITHUB_OUTPUT elif echo "$COMMIT_MSG" | grep -qiE "^feat(\(.+\))?:"; then echo "type=minor" >> $GITHUB_OUTPUT else echo "type=patch" >> $GITHUB_OUTPUT fi - name: Bump version in package.json id: version run: | VERSION=$(node -e " const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('packages/backend/package.json', 'utf8')); const [major, minor, patch] = pkg.version.split('.').map(Number); const type = '${{ steps.bump.outputs.type }}'; if (type === 'major') pkg.version = \`\${major + 1}.0.0\`; else if (type === 'minor') pkg.version = \`\${major}.\${minor + 1}.0\`; else pkg.version = \`\${major}.\${minor}.\${patch + 1}\`; fs.writeFileSync('packages/backend/package.json', JSON.stringify(pkg, null, 2) + '\n'); console.log(pkg.version); ") echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Login to DOCR run: echo "${{ secrets.DOCR_TOKEN }}" | docker login registry.digitalocean.com -u token --password-stdin - name: Build and push backend run: | VERSION=${{ steps.version.outputs.version }} SHA=$(git rev-parse --short HEAD) docker build \ --build-arg APP_VERSION=$VERSION \ -t $REGISTRY/lunarfront-app:$VERSION \ -t $REGISTRY/lunarfront-app:$SHA \ -t $REGISTRY/lunarfront-app:latest \ -f Dockerfile . docker push $REGISTRY/lunarfront-app:$VERSION docker push $REGISTRY/lunarfront-app:$SHA docker push $REGISTRY/lunarfront-app:latest - name: Build and push frontend run: | VERSION=${{ steps.version.outputs.version }} SHA=$(git rev-parse --short HEAD) docker build \ -t $REGISTRY/lunarfront-frontend:$VERSION \ -t $REGISTRY/lunarfront-frontend:$SHA \ -t $REGISTRY/lunarfront-frontend:latest \ -f Dockerfile.frontend . docker push $REGISTRY/lunarfront-frontend:$VERSION docker push $REGISTRY/lunarfront-frontend:$SHA docker push $REGISTRY/lunarfront-frontend:latest - name: Install Helm run: | curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash - name: Package and push Helm chart run: | VERSION=${{ steps.version.outputs.version }} # Update chart version to match app version sed -i "s/^version:.*/version: $VERSION/" chart/Chart.yaml sed -i "s/^appVersion:.*/appVersion: \"$VERSION\"/" chart/Chart.yaml # Update default image tags in values.yaml to this version sed -i "s|tag: latest|tag: $VERSION|g" chart/values.yaml helm registry login registry.digitalocean.com -u token --password "${{ secrets.DOCR_TOKEN }}" helm package chart/ helm push lunarfront-$VERSION.tgz oci://registry.digitalocean.com/lunarfront - name: Commit version bump run: | git config user.name "lunarfront-bot" git config user.email "bot@lunarfront.tech" git remote set-url origin https://lunarfront-bot:${{ secrets.BOT_TOKEN }}@$GIT_REMOTE/ryan/lunarfront-app.git git add packages/backend/package.json chart/Chart.yaml chart/values.yaml git commit -m "chore: bump version to v${{ steps.version.outputs.version }}" git pull --rebase origin main git push origin main - name: Logout if: always() run: docker logout registry.digitalocean.com