Add release (#22) #69
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: Docker | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Build and start services with docker compose | |
| run: | | |
| docker compose up --build -d | |
| sleep 5 # Wait for services to start | |
| - name: Show server logs | |
| run: docker compose logs python-template-server | |
| - uses: ./.github/actions/docker-check-containers | |
| with: | |
| port: 443 | |
| - name: Stop services | |
| run: docker compose --profile cpu down --volumes --remove-orphans | |
| publish-release: | |
| runs-on: ubuntu-latest | |
| needs: [build] | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: ./.github/actions/setup-python-core | |
| - name: Get version from pyproject.toml | |
| id: get_version | |
| run: | | |
| uv sync --extra dev | |
| VERSION=$(uv run python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=v$VERSION" >> $GITHUB_OUTPUT | |
| - name: Check if tag exists | |
| id: check_tag | |
| run: | | |
| if git rev-parse "v${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then | |
| echo "Tag v${{ steps.get_version.outputs.version }} already exists, skipping release creation" | |
| echo "tag_exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "tag_exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set up Docker Buildx | |
| if: steps.check_tag.outputs.tag_exists == 'false' | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| if: steps.check_tag.outputs.tag_exists == 'false' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata for Docker | |
| if: steps.check_tag.outputs.tag_exists == 'false' | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=semver,pattern={{version}},value=v${{ steps.get_version.outputs.version }} | |
| type=semver,pattern={{major}}.{{minor}},value=v${{ steps.get_version.outputs.version }} | |
| type=semver,pattern={{major}},value=v${{ steps.get_version.outputs.version }} | |
| type=raw,value=latest | |
| - name: Build and push Docker image | |
| if: steps.check_tag.outputs.tag_exists == 'false' | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| platforms: linux/amd64,linux/arm64 | |
| - name: Generate release notes | |
| if: steps.check_tag.outputs.tag_exists == 'false' | |
| id: release_notes | |
| run: | | |
| cat > release_notes.md << 'EOF' | |
| ## Python Template Server v${{ steps.get_version.outputs.version }} | |
| **A template FastAPI server with production-ready configuration.** | |
| ### Quick Start with Docker | |
| ```bash | |
| # Download docker-compose.yml | |
| curl -O https://raw.githubusercontent.com/${{ github.repository }}/main/docker-compose.yml | |
| # Run | |
| docker compose up -d | |
| ``` | |
| Access the application at `https://localhost:443` | |
| - [README](https://github.com/${{ github.repository }}/blob/main/README.md) | |
| - [API Documentation](https://github.com/${{ github.repository }}/blob/main/docs/API.md) | |
| - [Docker Deployment](https://github.com/${{ github.repository }}/blob/main/docs/DOCKER_DEPLOYMENT.md) | |
| EOF | |
| echo "release_notes_file=release_notes.md" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| if: steps.check_tag.outputs.tag_exists == 'false' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.get_version.outputs.tag }} | |
| name: "Python Template Server ${{ steps.get_version.outputs.version }}" | |
| body_path: ${{ steps.release_notes.outputs.release_notes_file }} | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: false |