Merge pull request #95 from julwrites/staging #61
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 | |
| # Add "id-token" with the intended permissions. | |
| permissions: | |
| contents: 'read' | |
| id-token: 'write' | |
| 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: | |
| workload_identity_provider: ${{ secrets.GCLOUD_WORKLOAD_IDENTITY_PROVIDER }} | |
| service_account: ${{ secrets.GCLOUD_SERVICE_ACCOUNT }} | |
| project_id: ${{secrets.GCLOUD_PROJECT_ID}} | |
| - name: Test gcloud | |
| run: | | |
| gcloud info | |
| - name: Configure gcloud auth with Docker | |
| run: | | |
| gcloud auth configure-docker us-central1-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 us-central1-docker.pkg.dev/$ARTIFACT_ID/$PROJECT_ID/root:latest . | |
| docker push us-central1-docker.pkg.dev/$ARTIFACT_ID/$PROJECT_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 }} | |
| run: | | |
| gcloud run deploy scripturebot --image us-central1-docker.pkg.dev/$ARTIFACT_ID/$PROJECT_ID/root:latest --region us-central1 | |