Deploy app to gae #5
This file contains 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: Deploy redirect to cloudrun | |
on: | |
pull_request: | |
paths: | |
- "redirect/**" | |
- ".github/workflows/deploy_redirect.yml" | |
push: | |
branches: | |
- main | |
paths: | |
- "redirect/**" | |
- ".github/workflows/deploy_redirect.yml" | |
tags: | |
- "release-*" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
CI: true | |
PROJECT_ID: ${{ secrets.PROJECT_ID }} | |
SERVICE: audiora | |
jobs: | |
prepare: | |
runs-on: ubuntu-latest | |
outputs: | |
SHORT_SHA: ${{ steps.prepare_env.outputs.SHORT_SHA }} | |
VERSION: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || format('main-{0}', steps.prepare_env.outputs.SHORT_SHA) }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- id: prepare_env | |
run: | | |
echo "TAGGED=${{ startsWith(github.ref, 'refs/tags/api') }}" >> $GITHUB_OUTPUT | |
SHORT_SHA=$(git rev-parse --short HEAD) | |
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_OUTPUT | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [prepare] | |
timeout-minutes: 10 | |
permissions: | |
pull-requests: write | |
env: | |
VERSION: ${{ needs.prepare.outputs.VERSION }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12" | |
cache: "pip" # caching pip dependencies | |
check-latest: true | |
- uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: "${{ secrets.GCP_SA_KEY }}" | |
- id: deploy | |
uses: google-github-actions/deploy-cloudrun@v2 | |
with: | |
service: ${{ env.SERVICE }} | |
source: ./redirect | |
tag: ${{ env.VERSION }} | |
no_traffic: true | |
timeout: "5m" | |
gcloud_version: "482.0.0" | |
flags: "--allow-unauthenticated --memory=1Gi" | |
env_vars: | | |
ENV=prod | |
- run: curl -f "${{ steps.deploy.outputs.url }}" | |
- uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
header: redirect | |
message: | | |
redirect: ${{ steps.deploy.outputs.url }} (${{ github.event.pull_request.head.sha }}) | |
promote: | |
runs-on: ubuntu-latest | |
if: ${{ github.ref == 'refs/heads/main' }} | |
needs: [prepare, deploy] | |
timeout-minutes: 3 | |
steps: | |
- uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: "${{ secrets.GCP_SA_KEY }}" | |
- uses: google-github-actions/setup-gcloud@v2 | |
- run: gcloud run services update-traffic ${{ env.SERVICE }} --to-tags=${{ needs.prepare.outputs.VERSION }}=100 --project=${{ env.PROJECT_ID }} --region=us-central1 | |
cleanup: | |
runs-on: ubuntu-latest | |
needs: promote | |
timeout-minutes: 3 | |
steps: | |
- uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: "${{ secrets.GCP_SA_KEY }}" | |
- uses: google-github-actions/setup-gcloud@v2 | |
- name: cleanup old revisions | |
run: | | |
gcloud run revisions list --service=${{ env.SERVICE }} --project=${{ env.PROJECT_ID }} --region=us-central1 --sort-by=CREATE_TIME --format="value(REVISION)" | tail -n +4 | xargs -I {} gcloud run revisions delete {} --project=${{ env.PROJECT_ID }} --region=us-central1 --quiet |