Exemplo de action para deploy de uma Gcloud Function
name : Deploy Cloud Function
on :
push :
branches :
- main
env :
PROJECT_ID : my-project
FUNCTION_NAME : helloworld
REGION : us-central1
RUNTIME : python310
jobs :
deploy :
runs-on : ubuntu-latest
steps :
- name : Checkout code
uses : actions/checkout@v2
- name : Setup Python
uses : actions/setup-python@v4
with :
python-version : '3.10'
- name : Install pipenv
run : |
pip install --upgrade pip
pip install pipenv
- name : Cache pipenv
uses : actions/cache@v3
with :
path : ~/.local/share/virtualenvs
key : ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
restore-keys : |
${{ runner.os }}-pipenv-
- name : Install dependencies
run : make install
- name : Lint
run : make lint
- id : 'auth'
uses : 'google-github-actions/auth@v1'
with :
credentials_json : ${{ secrets.SERVICE_ACCOUNT_CREDENTIALS_JSON }}
- name : Set up Cloud SDK
uses : google-github-actions/setup-gcloud@v1
with :
project_id : ${{ env.PROJECT_ID }}
- name : setup dist files
run : make build
- name : Deploy function
run : |
gcloud functions deploy ${{ env.FUNCTION_NAME }} \
--gen2 \
--entry-point=${{ env.FUNCTION_NAME }} \
--region=${{ env.REGION }} \
--runtime=${{ env.RUNTIME }} \
--trigger-http \
--source=./dist/ \
--allow-unauthenticated
Criar uma chave json na Service Account com permissão para deploy de funções e criar a secret nas actions do projeto chamada SERVICE_ACCOUNT_CREDENTIALS_JSON
com o json. Remova as quebras de linha da chave json.