|
| 1 | +name: Deploy to Google Cloud Storage |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*.*.*' |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write # Required for updating GitHub releases on tagged deployments |
| 12 | + |
| 13 | +jobs: |
| 14 | + deploy: |
| 15 | + name: Deploy to GCS |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Determine deployment path |
| 23 | + id: deploy-path |
| 24 | + run: | |
| 25 | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then |
| 26 | + # Extract version from tag (e.g., refs/tags/v1.0.0 -> v1.0.0) |
| 27 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 28 | + echo "path=$VERSION" >> $GITHUB_OUTPUT |
| 29 | + echo "is_tag=true" >> $GITHUB_OUTPUT |
| 30 | + echo "Deploying tagged release: $VERSION" |
| 31 | + else |
| 32 | + # Main branch deployment |
| 33 | + echo "path=main" >> $GITHUB_OUTPUT |
| 34 | + echo "is_tag=false" >> $GITHUB_OUTPUT |
| 35 | + echo "Deploying main branch" |
| 36 | + fi |
| 37 | +
|
| 38 | + - name: Authenticate to Google Cloud |
| 39 | + uses: google-github-actions/auth@v2 |
| 40 | + with: |
| 41 | + credentials_json: ${{ secrets.GCS_DEPLOY_SA_KEY }} |
| 42 | + |
| 43 | + - name: Setup gcloud CLI |
| 44 | + uses: google-github-actions/setup-gcloud@v2 |
| 45 | + |
| 46 | + - name: Deploy to GCS |
| 47 | + env: |
| 48 | + GCS_BUCKET: viral-references |
| 49 | + DEPLOY_PATH: ${{ steps.deploy-path.outputs.path }} |
| 50 | + run: | |
| 51 | + echo "Syncing to gs://$GCS_BUCKET/$DEPLOY_PATH/" |
| 52 | + gcloud storage rsync . "gs://$GCS_BUCKET/$DEPLOY_PATH/" \ |
| 53 | + --recursive \ |
| 54 | + --delete-unmatched-destination-objects \ |
| 55 | + --exclude=".??*" |
| 56 | + echo "Deployment complete!" |
| 57 | +
|
| 58 | + - name: Verify deployment |
| 59 | + env: |
| 60 | + GCS_BUCKET: viral-references |
| 61 | + DEPLOY_PATH: ${{ steps.deploy-path.outputs.path }} |
| 62 | + run: | |
| 63 | + echo "Deployed files:" |
| 64 | + gcloud storage ls -r "gs://$GCS_BUCKET/$DEPLOY_PATH/" | head -20 |
| 65 | + echo "" |
| 66 | + echo "Deployment URL: gs://$GCS_BUCKET/$DEPLOY_PATH/" |
| 67 | +
|
| 68 | + - name: Update GitHub release notes |
| 69 | + if: steps.deploy-path.outputs.is_tag == 'true' |
| 70 | + env: |
| 71 | + GH_TOKEN: ${{ github.token }} |
| 72 | + TAG_NAME: ${{ github.ref_name }} |
| 73 | + GCS_BUCKET: viral-references |
| 74 | + DEPLOY_PATH: ${{ steps.deploy-path.outputs.path }} |
| 75 | + run: | |
| 76 | + # Check if release exists for this tag |
| 77 | + if gh release view "$TAG_NAME" &>/dev/null; then |
| 78 | + echo "Release exists for $TAG_NAME, updating with deployment URL" |
| 79 | +
|
| 80 | + # Get existing release notes |
| 81 | + EXISTING_NOTES=$(gh release view "$TAG_NAME" --json body --jq .body) |
| 82 | +
|
| 83 | + # Append deployment info if not already present |
| 84 | + if [[ "$EXISTING_NOTES" != *"gs://$GCS_BUCKET/$DEPLOY_PATH/"* ]]; then |
| 85 | + DEPLOYMENT_NOTE="\n\n---\n\n**Deployment**: Available at \`gs://$GCS_BUCKET/$DEPLOY_PATH/\`" |
| 86 | + gh release edit "$TAG_NAME" --notes "${EXISTING_NOTES}${DEPLOYMENT_NOTE}" |
| 87 | + echo "Release notes updated with deployment URL" |
| 88 | + else |
| 89 | + echo "Deployment URL already present in release notes" |
| 90 | + fi |
| 91 | + else |
| 92 | + echo "No release found for $TAG_NAME, skipping release update" |
| 93 | + fi |
0 commit comments