Merge pull request #112 from julwrites/staging #68
This file contains hidden or 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
| name: Build, Stage and Deploy Automation | |
| on: | |
| push: | |
| branches: | |
| - master | |
| jobs: | |
| build-and-test: | |
| 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: Install, Build, Test 🔧 # This runs a series of commands as if building a live version of the project | |
| run: | | |
| go mod tidy | |
| go test github.com/julwrites/ScriptureBot/pkg/utils \ | |
| github.com/julwrites/ScriptureBot/pkg/app \ | |
| github.com/julwrites/ScriptureBot/pkg/bot | |
| - name: gcloud Auth | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCLOUD_SA_KEY }} | |
| project_id: ${{secrets.GCLOUD_PROJECT_ID}} | |
| - name: Test gcloud | |
| run: | | |
| gcloud info | |
| - 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}} | |
| PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} | |
| ARTIFACT_ID: ${{secrets.GCLOUD_ARTIFACT_REPOSITORY_ID}} | |
| run: | | |
| printf "TELEGRAM_ID: \"$TELEGRAM_ID\"\nADMIN_ID: \"$ADMIN_ID\"\nPROJECT_ID: \"$PROJECT_ID\"\n" >> secrets.yaml | |
| cat secrets.yaml | |
| docker build -f Dockerfile -t ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/$PROJECT_ID/$ARTIFACT_ID/root:latest . | |
| docker push ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/$PROJECT_ID/$ARTIFACT_ID/root:latest | |
| - name: Deployment | |
| env: | |
| PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} | |
| ARTIFACT_ID: ${{secrets.GCLOUD_ARTIFACT_REPOSITORY_ID}} | |
| APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} | |
| TELEGRAM_ID: ${{secrets.TELEGRAM_ID}} | |
| run: | | |
| gcloud run deploy scripturebot --image ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/$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" | |