Skip to content

test: testing gh action #78

test: testing gh action

test: testing gh action #78

Workflow file for this run

name: Database Deployment
on:
push:
branches:
- '**'
jobs:
terraform:
name: 'Terraform'
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Authenticate to Google Cloud
id: gcloud_auth
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.DEV_GCP_MOBILITY_FEEDS_SA_KEY }}
- name: Google Cloud Setup
uses: google-github-actions/setup-gcloud@v1
- name: Set Variables
run: |
echo "Setting variables"
echo "FUNCTION_BUCKET_NAME=mobility-batch-processing" >> $GITHUB_ENV
echo "BUCKET_NAME=mobility-feeds-terraform-dev" >> $GITHUB_ENV
echo "OBJECT_PREFIX=terraform-state-${{ env.FUNCTION_BUCKET_NAME }}" >> $GITHUB_ENV
echo "PROJECT_ID=mobility-feeds-dev" >> $GITHUB_ENV
echo "REGION=us-central1" >> $GITHUB_ENV
echo "DEPLOYER_SERVICE_ACCOUNT=ci-impersonator@mobility-feeds-dev.iam.gserviceaccount.com" >> $GITHUB_ENV
- name: Populate Variables
run: |
scripts/replace-variables.sh -in_file infra/backend.conf.rename_me -out_file infra/batch/backend.conf -variables BUCKET_NAME,OBJECT_PREFIX
scripts/replace-variables.sh -in_file infra/batch/vars.tfvars.rename_me -out_file infra/batch/pre-vars.tfvars -variables FUNCTION_BUCKET_NAME,REGION,PROJECT_ID,DEPLOYER_SERVICE_ACCOUNT
scripts/replace-variables.sh -in_file infra/batch/pre-vars.tfvars -out_file infra/batch/vars.tfvars -variables FUNCTION_ENV_VARIABLE -no_quotes
env:
FUNCTION_ENV_VARIABLE: '"BUCKET_NAME"="mobility-datasets", "POSTGRES_USER"="${{ secrets.DEV_POSTGRE_USER_NAME }}", "POSTGRES_PASSWORD"="${{ secrets.DEV_POSTGRE_USER_PASSWORD }}", "POSTGRES_DB"="${{ vars.DEV_POSTGRE_SQL_DB_NAME }}", "POSTGRES_PORT"="5432", "POSTGRES_HOST"="${{ secrets.DEV_DB_PUBLIC_IP }}"'
- name: Zip source code
run: |
cd infra/batch
zip -r -j datasets.zip datasets/*
# Clearing previous versions of the source code
- name: Check for changes in infra/batch/datasets
id: check_files
run: |
if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep 'infra/batch/datasets'; then
echo "CLEAR_PREVIOUS_VERSION=true" >> $GITHUB_ENV
else
echo "CLEAR_PREVIOUS_VERSION=false" >> $GITHUB_ENV
fi
- name: Clear Folder in GCP Bucket
if: env.CLEAR_PREVIOUS_VERSION
continue-on-error: true # In case the bucket is created yet
run: gsutil rm gs://${{env.FUNCTION_BUCKET_NAME}}/datasets/*
- name: Install Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.5.3
terraform_wrapper: false
- name: Terraform Init
run: |
cd infra/batch
terraform init -backend-config=backend.conf
env:
GOOGLE_CREDENTIALS: ${{ secrets.DEV_GCP_MOBILITY_FEEDS_SA_KEY }}
PROJECT_ID: ${{ env.PROJECT_ID }}
- name: Terraform Import
continue-on-error: true
run: |
cd infra/batch
terraform import -var-file=vars.tfvars google_storage_bucket.bucket "${{ env.PROJECT_ID }}/${{ env.FUNCTION_BUCKET_NAME }}"
terraform import -var-file=vars.tfvars google_cloudfunctions_function.function projects/${{ env.PROJECT_ID }}/locations/${{ env.REGION }}/functions/dataset-batch-function
terraform import -var-file=vars.tfvars google_cloud_scheduler_job.job projects/${{ env.PROJECT_ID }}/locations/${{ env.REGION }}/jobs/dataset-batch-job
- name: Terraform Plan
run: |
cd infra/batch
terraform plan -var-file=vars.tfvars -out=tf.plan
terraform show -no-color tf.plan > terraform-plan.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Terraform Apply
run: |
cd infra/batch
terraform apply -auto-approve tf.plan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}