Skip to content

Merge pull request #136 from julwrites/staging #78

Merge pull request #136 from julwrites/staging

Merge pull request #136 from julwrites/staging #78

Workflow file for this run

name: Build, Stage and Deploy Automation
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
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 ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev
- name: Docker Build and Stage
env:
TELEGRAM_ID: ${{secrets.TELEGRAM_ID}}
ADMIN_ID: ${{secrets.TELEGRAM_ADMIN_ID}}
GCLOUD_PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}}
ARTIFACT_ID: ${{secrets.GCLOUD_ARTIFACT_REPOSITORY_ID}}
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 ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/$GCLOUD_PROJECT_ID/$ARTIFACT_ID/root:latest .
docker push ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/$GCLOUD_PROJECT_ID/$ARTIFACT_ID/root:latest
- name: Deployment
env:
GCLOUD_PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}}
ARTIFACT_ID: ${{secrets.GCLOUD_ARTIFACT_REPOSITORY_ID}}
TELEGRAM_ID: ${{secrets.TELEGRAM_ID}}
run: |
gcloud run deploy scripturebot --image ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/$GCLOUD_PROJECT_ID/$ARTIFACT_ID/root:latest --region ${{ secrets.GCLOUD_REGION }} --allow-unauthenticated
SERVICE_URL=$(gcloud run services describe scripturebot --region ${{ secrets.GCLOUD_REGION }} --format 'value(status.url)')
echo "Setting webhook for $SERVICE_URL"
go run cmd/webhook/main.go -url "$SERVICE_URL"