ci: drop unneeded npm@latest update step #76
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: Build and Publish Docker Images | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: docker.io | |
| IMAGE_NAME: linkforty/core | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| attestations: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| type=sha | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build TypeScript | |
| run: npm run build | |
| - name: Build and push Docker image | |
| id: build-and-push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./examples/Dockerfile | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| platforms: linux/amd64 | |
| # TODO: Re-enable ARM64 once QEMU native module issues are resolved | |
| # platforms: linux/amd64,linux/arm64 | |
| sbom: true | |
| provenance: true | |
| - name: Image digest | |
| run: echo ${{ steps.meta.outputs.digest }} | |
| test-docker-image: | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'pull_request' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Test docker-compose setup | |
| run: | | |
| cd examples | |
| # Create a test docker-compose.yml using the published image | |
| cat > docker-compose.test.yml <<EOF | |
| services: | |
| postgres: | |
| image: postgres:15-alpine | |
| environment: | |
| POSTGRES_DB: linkforty | |
| POSTGRES_USER: linkforty | |
| POSTGRES_PASSWORD: changeme | |
| healthcheck: | |
| test: ["CMD-SHELL", "pg_isready -U linkforty"] | |
| interval: 5s | |
| timeout: 5s | |
| retries: 5 | |
| redis: | |
| image: redis:7-alpine | |
| healthcheck: | |
| test: ["CMD", "redis-cli", "ping"] | |
| interval: 5s | |
| timeout: 5s | |
| retries: 5 | |
| linkforty: | |
| image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sha-${GITHUB_SHA::7} | |
| depends_on: | |
| postgres: | |
| condition: service_healthy | |
| redis: | |
| condition: service_healthy | |
| environment: | |
| DATABASE_URL: postgresql://linkforty:changeme@postgres:5432/linkforty?sslmode=disable | |
| REDIS_URL: redis://redis:6379 | |
| NODE_ENV: production | |
| PORT: 3000 | |
| ports: | |
| - "3000:3000" | |
| healthcheck: | |
| test: ["CMD", "curl", "-f", "http://localhost:3000/api/sdk/v1/health"] | |
| interval: 5s | |
| timeout: 5s | |
| retries: 10 | |
| start_period: 10s | |
| EOF | |
| # Start services | |
| docker compose -f docker-compose.test.yml up -d | |
| # Wait for linkforty to be healthy | |
| echo "Waiting for linkforty service to be healthy..." | |
| timeout=60 | |
| elapsed=0 | |
| while [ $elapsed -lt $timeout ]; do | |
| if docker compose -f docker-compose.test.yml ps | grep linkforty | grep -q "healthy"; then | |
| echo "Service is healthy!" | |
| break | |
| fi | |
| echo "Waiting... ($elapsed seconds elapsed)" | |
| sleep 5 | |
| elapsed=$((elapsed + 5)) | |
| done | |
| if [ $elapsed -ge $timeout ]; then | |
| echo "Service failed to become healthy within $timeout seconds" | |
| echo "Container logs:" | |
| docker compose -f docker-compose.test.yml logs linkforty | |
| exit 1 | |
| fi | |
| # Test API endpoint | |
| echo "Testing API endpoint..." | |
| curl -f http://localhost:3000/api/sdk/v1/health || exit 1 | |
| # Cleanup | |
| docker compose -f docker-compose.test.yml down -v | |
| create-release: | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Extract version from tag | |
| id: version | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: Release v${{ steps.version.outputs.VERSION }} | |
| body: | | |
| ## Docker Image | |
| Pull the image: | |
| ```bash | |
| docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} | |
| ``` | |
| Run with Docker Compose: | |
| ```bash | |
| curl -o docker-compose.yml https://raw.githubusercontent.com/linkforty/core/v${{ steps.version.outputs.VERSION }}/examples/docker-compose.yml | |
| docker compose up -d | |
| ``` | |
| See [CHANGELOG.md](https://github.com/linkforty/core/blob/main/CHANGELOG.md) for details. | |
| draft: false | |
| prerelease: ${{ contains(steps.version.outputs.VERSION, '-') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |