Update deploy action to use latest Google Action versions #238
Workflow file for this run
This file contains 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: Run tests and deploy to Cloud Run | |
on: | |
push: | |
branches: | |
- 'main' | |
- '**' # Run on any branch | |
env: | |
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
RUN_REGION: us-central1 | |
SERVICE_NAME: ${{ secrets.GCP_SERVICE_NAME }} | |
jobs: | |
test: | |
name: Run tests | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [20.x, 22.x] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Install npm dependencies | |
run: npm install | |
- name: Run jest unit tests | |
run: npm run test | |
- name: Run JS linter | |
run: npm run lint | |
deploy: | |
name: Build and deploy to Cloud Run | |
runs-on: ubuntu-latest | |
needs: test | |
if: github.ref_name == 'update-deps-actions' | |
steps: | |
- uses: actions/checkout@v4 | |
- id: auth | |
name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY_JSON }} | |
# Docker auth | |
- name: Docker Auth | |
uses: docker/login-action@v3 | |
with: | |
registry: 'gcr.io' | |
username: _json_key | |
password: ${{ secrets.GCP_SA_KEY_JSON }} | |
# Docker build & push to GCP | |
- name: Build and Push Container | |
run: |- | |
docker buildx build --platform linux/amd64 -t gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ github.sha }} --build-arg GITHUB_SHA_ARG=${{ github.sha }} . | |
docker push gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ github.sha }} | |
# Deploy the container that was just pushed | |
- name: Deploy to Cloud Run | |
id: deploy | |
uses: google-github-actions/deploy-cloudrun@v2 | |
with: | |
service: ${{ env.SERVICE_NAME }} | |
image: gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ github.sha }} | |
region: ${{ env.RUN_REGION }} |