GitHub Actions Deploy
A Python library for automating Google Cloud Run deployments in GitHub Actions with VPC Service Controls support and automatic PR commenting.
Features
- 🚀 VPC-SC Support: Handles VPC Service Controls constraints with async builds
- 💬 Auto PR Comments: Posts build started and completion comments with service URLs
- 🐳 Docker Integration: Seamless container building and deployment
- ⚡ Fast & Reliable: Optimized for CI/CD environments
- 🔧 Highly Configurable: Support for custom timeouts, secrets, and environments
Quick Start
Installation
pip install github-actions-deploy
GitHub Actions Workflow
Copy the template from templates/pr-preview.yml and customize:
- name: Deploy using github-actions-deploy
env:
GCP_PROJECT: your-project-id
GCP_REGION: us-central1
SERVICE_NAME: "your-service-pr-${{ steps.pr_number.outputs.number }}"
IMAGE_TAG: "gcr.io/your-project/your-service:pr-${{ steps.pr_number.outputs.number }}-${{ github.sha }}"
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
PR_NUMBER: ${{ steps.pr_number.outputs.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gha-deploy \
--project-id "$GCP_PROJECT" \
--region "$GCP_REGION" \
--service-name "$SERVICE_NAME" \
--image-tag "$IMAGE_TAG" \
--repository "$GITHUB_REPOSITORY" \
--pr-number "$PR_NUMBER" \
--branch-name "$GITHUB_HEAD_REF" \
--secrets "API_KEY=api-key-secret:latest"
Key Components
VPC Service Controls (VPC-SC) Support
The library automatically detects CI environments and uses async builds to avoid VPC-SC log streaming restrictions:
from github_actions_deploy import CloudRunDeployer, DeploymentConfig
config = DeploymentConfig.from_environment()
deployer = CloudRunDeployer(config)
# Automatically handles VPC-SC async builds in CI
service_url = deployer.deploy(branch_name="main")
PR Status Comments
Automatically posts comments showing:
- Build Started: Progress indicators and estimated time
- Deployment Complete: Service URLs and quick access links
- Deployment Failed: Error details and troubleshooting steps
Configuration
The library uses environment variables or can be configured programmatically:
config = DeploymentConfig(
project_id="your-project",
region="us-central1",
service_name="your-service",
repository="owner/repo",
pr_number=123,
use_vpc_sc_async=True # Enables VPC-SC async build mode
)
Environment Variables
| Variable | Description | Required |
|---|---|---|
GCP_PROJECT |
Google Cloud Project ID | Yes |
GCP_REGION |
Google Cloud Region | No (default: us-central1) |
SERVICE_NAME |
Cloud Run service name | Yes |
GITHUB_REPOSITORY |
GitHub repository (owner/repo) | Yes |
GITHUB_HEAD_REF |
Git branch name | Yes |
PR_NUMBER |
Pull request number | For PR deployments |
GITHUB_TOKEN |
GitHub token for API access | For PR comments |
Templates
The package includes ready-to-use GitHub Actions templates:
templates/pr-preview.yml: PR preview deployments with commentstemplates/production-deploy.yml: Production deployments
Prerequisites
-
Google Cloud Setup:
- Service account with Cloud Run and Cloud Build permissions
- VPC Service Controls configured (if applicable)
- Secret Manager for API keys
-
GitHub Setup:
- Repository secrets for
GCP_SA_KEY pull-requests: writepermission for PR comments
- Repository secrets for
Advanced Usage
Custom Secrets
gha-deploy --secrets "API_KEY=api-key:latest,DB_PASSWORD=db-pass:latest"
Skip PR Comments
gha-deploy --no-comments
Custom Timeout
gha-deploy --timeout-minutes 20
Development
git clone https://github.com/jleechanorg/ai_universe
cd packages/github-actions-deploy
pip install -e ".[dev]"
pytest
License
MIT License - see LICENSE file for details.
Metadata
Release files for github-actions-deploy 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| github_actions_deploy-0.1.0.tar.gz | 13.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| github_actions_deploy-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.3 kB
Release files / github_actions_deploy-0.1.0.tar.gz
| Download URL | github_actions_deploy-0.1.0.tar.gz |
|---|---|
| Size | 13.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2077b47e9906eeba560b5db68d4768db89da64e02954d0278e1f00b0de382620
|
|
BLAKE2b-256 checksum How to use checksums |
a50bfdca06f832cf9cc5bb1e71745ac329833e9554ec9db2b34a08ea483e0285
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.10
|
Release files / github_actions_deploy-0.1.0-py3-none-any.whl
| Download URL | github_actions_deploy-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37e08891df92419f837701057807c94b82a3a46632dacc72670ade066c9880bf
|
|
BLAKE2b-256 checksum How to use checksums |
0b454ebf7b2de8b91b16f053e804727c783632072168ee40e27fc682750a7690
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.10
|