add permissions #118
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
"on": | |
push: | |
branches: | |
- main | |
- wif | |
paths: | |
# only run when the source code changes or this file changes | |
- "functions/api/**" | |
- "go.*" | |
- ".github/workflows/deploy-api.yml" | |
- "internal/**" | |
- "Dockerfile" | |
name: Deploy API to cloud run | |
jobs: | |
deploy-api: | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
runs-on: ubuntu-latest | |
env: | |
IMAGE_NAME: us-central1-docker.pkg.dev/asianamericans-wiki/asianamericanswiki-api/api | |
steps: | |
- uses: actions/checkout@v4 | |
- id: "auth" | |
name: "Authenticate to Google Cloud" | |
uses: "google-github-actions/auth@v2" | |
with: | |
project_id: "asianamericans-wiki" | |
workload_identity_provider: "projects/424340922093/locations/global/workloadIdentityPools/github-action-wif/providers/github" | |
- name: Set outputs | |
id: vars | |
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v1 | |
- name: Configure Docker | |
run: gcloud auth configure-docker --quiet us-central1-docker.pkg.dev | |
- id: deploy | |
name: Deploy | |
uses: "google-github-actions/deploy-cloudrun@v2" | |
with: | |
timeout: 90 | |
service: "api2" | |
region: "us-central1" | |
labels: githash=${{ steps.vars.outputs.sha_short }} | |
image: ${{ env.IMAGE_NAME }}:latest | |
env_vars: | | |
GIT_HASH=${{ steps.vars.outputs.sha_short }} | |
- name: "Use output" | |
run: 'curl "${{ steps.deploy.outputs.url }}"/api/v1/version' |