Merge pull request #174 from Femcoders-SleepUp/dev #14
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
| # Release workflow - Creates production releases when version tags are pushed | |
| # This workflow runs tests, builds production images, and creates releases | |
| name: Release | |
| # Trigger: Run when version tags (v*) are pushed to the repository | |
| # Example: git tag v1.0.0 && git push origin v1.0.0 | |
| on: | |
| push: | |
| tags: | |
| - "v*" # Matches tags starting with 'v' (e.g., v1.0.0, v2.1.3) | |
| jobs: | |
| build-and-release: | |
| # Use the latest Ubuntu runner for consistent build environment | |
| runs-on: ubuntu-latest | |
| env: | |
| # Cloudinary dummy variables for testing | |
| CLOUDINARY_CLOUD_NAME: ${{ secrets.CLOUDINARY_CLOUD_NAME }} | |
| CLOUDINARY_API_KEY: ${{ secrets.CLOUDINARY_API_KEY }} | |
| CLOUDINARY_API_SECRET: ${{ secrets.CLOUDINARY_API_SECRET }} | |
| steps: | |
| # Step 1: Check out the repository code at the tagged commit | |
| - uses: actions/checkout@v4 | |
| # Step 2: Set up Docker Buildx for advanced Docker builds | |
| # Required for building and pushing Docker images | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # Step 3: Run full test suite before creating release | |
| # Ensures the tagged version passes all tests | |
| - name: Run tests with docker-compose | |
| run: docker compose -f docker-compose-test.yml up --quiet-pull --abort-on-container-exit --exit-code-from sleepUp-test | |
| # This step will fail the release if any tests fail | |
| # Step 4: Authenticate with Docker Hub for image publishing | |
| # Uses secrets stored in GitHub repository settings | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| # Step 5: Generate Docker image metadata and release tags | |
| # Creates version-specific tags and updates 'latest' tag | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ secrets.DOCKER_USERNAME }}/sleepUp | |
| tags: | | |
| type=ref,event=tag # Tag with version number (e.g., v1.0.0) | |
| type=raw,value=latest # Also tag as 'latest' for easy access | |
| # Step 6: Build and push production Docker image | |
| # Creates the official release image with version tags | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . # Build context is the repository root | |
| file: ./Dockerfile # Dockerfile location | |
| push: true # Push to Docker Hub after building | |
| tags: ${{ steps.meta.outputs.tags }} # Use version and latest tags | |
| labels: ${{ steps.meta.outputs.labels }} # Add metadata labels | |
| cache-from: type=gha # Use GitHub Actions cache for layers | |
| cache-to: type=gha,mode=max # Save all layers to cache | |
| # Step 7: Create GitHub Release (Currently disabled) | |
| # Uncomment the section below to automatically create GitHub releases | |
| # - name: Create GitHub Release Draft | |
| # uses: actions/create-release@v1 | |
| # env: | |
| # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # with: | |
| # tag_name: ${{ github.ref_name }} # Use the pushed tag name | |
| # release_name: Release ${{ github.ref_name }} # Release title | |
| # draft: true # Create as draft for manual review | |
| # prerelease: false # Mark as stable release | |
| # body: | | |
| # ## Changes | |
| # | |
| # Docker image: `${{ secrets.DOCKER_USERNAME }}/sleepUp:${{ github.ref_name }}` | |
| # | |
| # ## Installation | |
| # | |
| # ```bash | |
| # docker pull ${{ secrets.DOCKER_USERNAME }}/sleepUp:${{ github.ref_name }} | |
| # ``` | |
| # Step 8: Clean up Docker resources | |
| # Always runs to prevent resource leaks, even if previous steps fail | |
| - name: Clean up | |
| if: always() # Run even if previous steps fail | |
| run: docker compose -f docker-compose-test.yml down -v | |
| # Remove test containers and associated volumes |