This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
Set Up Staging Environment #7
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: Staging | |
on: pull_request | |
jobs: | |
# This job is based on one that was auto-generated by the Firebase CLI | |
# https://github.com/firebase/firebase-tools | |
ui: | |
name: 'Generate PR #${{ github.event.pull_request.number }} Staging UI Preview' | |
if: github.event.pull_request.head.repo.full_name == github.repository && github.event.action != 'closed' | |
runs-on: ubuntu-latest | |
environment: staging | |
concurrency: 'staging:ui' | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
cache: npm | |
- run: npm ci | |
- run: cp firebase.json tmp.json && jq '(.hosting.rewrites[] | select(.source == "/api/**").run.serviceId) = $serviceId' tmp.json --arg serviceId 'staging-server' > firebase.json | |
- run: npx nx build ui | |
- id: deploy | |
uses: FirebaseExtended/action-hosting-deploy@v0 | |
with: | |
repoToken: '${{ secrets.GITHUB_TOKEN }}' | |
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_IMYOURMANZI_SPOTIFYPLAYLISTMGR }} | |
projectId: imyourmanzi-spotifyplaylistmgr | |
channelId: staging | |
outputs: | |
url: ${{ steps.deploy.outputs.details_url }} | |
server: | |
name: 'Deploy PR #${{ github.event.pull_request.number }} to Staging Server' | |
if: github.event.pull_request.head.repo.full_name == github.repository && github.event.action != 'closed' | |
runs-on: ubuntu-latest | |
environment: staging | |
concurrency: 'staging:server' | |
needs: ui | |
steps: | |
- uses: actions/checkout@v3 | |
- id: gcp_auth | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: '${{ secrets.SERVER_DEPLOY_KEY }}' | |
token_format: access_token | |
- uses: google-github-actions/setup-gcloud@v1 | |
with: | |
project_id: imyourmanzi-spotifyplaylistmgr | |
- run: docker build --platform=linux/amd64 . -t us-central1-docker.pkg.dev/imyourmanzi-spotifyplaylistmgr/server-images/server:pr-${{ github.event.pull_request.number }}-latest | |
- run: echo '${{ steps.gcp_auth.outputs.access_token }}' | docker login -u oauth2accesstoken --password-stdin https://us-central1-docker.pkg.dev | |
- run: docker push us-central1-docker.pkg.dev/imyourmanzi-spotifyplaylistmgr/server-images/server:pr-${{ github.event.pull_request.number }}-latest | |
- run: gcloud run deploy staging-server --region us-central1 --image us-central1-docker.pkg.dev/imyourmanzi-spotifyplaylistmgr/server-images/server:pr-${{ github.event.pull_request.number }}-latest --revision-suffix "pr-${{ github.event.pull_request.number }}-$(date +'%Y%m%d-%H%M%S')" --update-env-vars=SPOTIFY_REDIRECT_URI=${{ needs.ui.outputs.url }}/callback/ |