Integrate CI (cont'd) #3
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: Build and Deploy to Google Cloud Run | |
on: | |
pull_request: | |
branches: [ main ] | |
jobs: | |
setup-build-deploy: | |
name: Setup, Build, and Deploy | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [ 14.x, 16.x, 18.x ] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Install dependencies | |
run: npm install | |
- name: Run tests | |
run: npm test | |
- name: Verify Environment Variables | |
run: | | |
if [ -z "${{ secrets.GCLOUD_SERVICE_KEY }}" ]; then | |
echo "GCLOUD_SERVICE_KEY is not set." | |
exit 1 | |
else | |
echo "GCLOUD_SERVICE_KEY is set." | |
fi | |
if [ -z "${{ secrets.GCP_PROJECT_ID }}" ]; then | |
echo "GCP_PROJECT_ID is not set." | |
exit 1 | |
else | |
echo "GCP_PROJECT_ID is set." | |
fi | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v0.2.0 | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
service_account_key: ${{ secrets.GCLOUD_SERVICE_KEY }} | |
export_default_credentials: true | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v0.5.0 | |
with: | |
credentials_json: ${{ secrets.GCLOUD_SERVICE_KEY }} | |
- name: Configure Docker to use the gcloud command-line tool as a credential helper | |
run: gcloud auth configure-docker us-central1-docker.pkg.dev --quiet | |
- name: Build and Push Docker image to Google Artifact Registry | |
run: | | |
docker build -t us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/react-labs-test/react-labs:latest . | |
docker push us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/react-labs-test/react-labs:latest | |
- name: Deploy to Cloud Run (CLI) | |
run: | | |
gcloud run deploy react-labs \ | |
--image=us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/react-labs-test/react-labs:latest \ | |
--project=${{ secrets.GCP_PROJECT_ID }} \ | |
--service-account=gh-actions-pipeline@${{ secrets.GCP_PROJECT_ID }}.iam.gserviceaccount.com \ | |
--region=us-central1 \ | |
--platform=managed \ | |
--quiet \ | |
--no-allow-unauthenticated \ | |
--verbosity=debug |