Skip to content

Merge pull request #152 from julwrites/staging #85

Merge pull request #152 from julwrites/staging

Merge pull request #152 from julwrites/staging #85

Workflow file for this run

name: Build, Stage and Deploy Automation
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
GCLOUD_PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}}
GCLOUD_REGION: ${{secrets.GCLOUD_REGION}}
ARTIFACT_ID: ${{secrets.GCLOUD_ARTIFACT_REPOSITORY_ID}}
TELEGRAM_ID: ${{secrets.TELEGRAM_ID}}
ADMIN_ID: ${{secrets.TELEGRAM_ADMIN_ID}}
GCLOUD_SERVICE_ACCOUNT: ${{secrets.GCLOUD_SERVICE_ACCOUNT}}
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.23.x
- name: Checkout 🛎️
uses: actions/checkout@v4 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
persist-credentials: false
- name: gcloud Auth (Deployment)
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCLOUD_CICD_SA_KEY }}
project_id: ${{secrets.GCLOUD_PROJECT_ID}}
- name: Configure gcloud auth with Docker
run: |
gcloud auth configure-docker $GCLOUD_REGION-docker.pkg.dev
- name: Docker Build and Stage
run: |
printf "TELEGRAM_ID: \"$TELEGRAM_ID\"\nADMIN_ID: \"$ADMIN_ID\"\nGCLOUD_PROJECT_ID: \"$GCLOUD_PROJECT_ID\"\n" >> secrets.yaml
cat secrets.yaml
docker build --build-arg GCLOUD_PROJECT_ID=$GCLOUD_PROJECT_ID -f Dockerfile -t $GCLOUD_REGION-docker.pkg.dev/$GCLOUD_PROJECT_ID/$ARTIFACT_ID/root:latest .
docker push $GCLOUD_REGION-docker.pkg.dev/$GCLOUD_PROJECT_ID/$ARTIFACT_ID/root:latest
- name: Deployment
run: |
gcloud run deploy scripturebot --image $GCLOUD_REGION-docker.pkg.dev/$GCLOUD_PROJECT_ID/$ARTIFACT_ID/root:latest --region $GCLOUD_REGION --service-account $GCLOUD_SERVICE_ACCOUNT --allow-unauthenticated
SERVICE_URL=$(gcloud run services describe scripturebot --region $GCLOUD_REGION --format 'value(status.url)')
echo "Setting webhook for $SERVICE_URL"
go run cmd/webhook/main.go -url "$SERVICE_URL"