Skip to content

Change build id return #479

Change build id return

Change build id return #479

name: 'PR preview to Dev'
on:
pull_request:
types:
- 'opened'
- 'synchronize'
- 'reopened'
- 'closed'
branches:
- 'develop'
jobs:
build-push-deploy:
name: 'Build and Deploy PR preview to Development'
runs-on: ubuntu-latest
if: ${{ github.event.action != 'closed'}}
# Checkout the repository to the GitHub Actions runner
steps:
- name: Checkout
uses: actions/checkout@v2
# gcloud CLI setup
- name: Login to GCP
uses: google-github-actions/setup-gcloud@v0
with:
service_account_key: ${{ secrets.DEV_SA_KEY }}
project_id: ${{ secrets.SV_PROJ_NAME }}
export_default_credentials: true
- name: Build Container Image
run: |-
docker build \
-t "gcr.io/${{ secrets.SV_PROJ_NAME }}/investigations-client:${{ github.sha }}" \
--build-arg NEXT_PUBLIC_API_URL=https://investigations-api-dot-skyviewer.uw.r.appspot.com/api \
--build-arg NEXT_PUBLIC_BASE_URL=https://investigations-client-dot-skyviewer.uw.r.appspot.com \
--build-arg NEXT_PUBLIC_GOOGLE_APP_ID=688095955960-sc5krqd8e3tpu2i692mic0kj2nckptu1.apps.googleusercontent.com \
--build-arg GOOGLE_APP_SECRET=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 \
--build-arg CRAFT_SECRET_TOKEN=1128f3c472c118caa63 \
--build-arg CRAFT_EDUCATOR_SCHEMA_SECRET_TOKEN=KPYySxz0TZjIPAtNCdnYUkguZz6y6BU- \
--build-arg CRAFT_STUDENT_SCHEMA_SECRET_TOKEN=vPNHdjzu4XwKhiYC0jDrQENzGxb2Ltx3 \
.
- name: Configure Docker Auth
run: gcloud --quiet auth configure-docker
- name: Push Container Image to GCR
run: docker push gcr.io/${{ secrets.SV_PROJ_NAME }}/investigations-client:${{ github.sha }}
- name: Get app.yaml
run: gcloud secrets versions access latest --secret=investigations-client-appyaml > app.yaml
- name: Format version name
id: version_name
run: echo "version_name=$(echo \"${{ github.head_ref }}\" | tr -cd '[:alnum:]' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Deploy branch-tagged version to App Engine
run: |-
gcloud app deploy app.yaml \
--image-url=gcr.io/${{ secrets.SV_PROJ_NAME }}/investigations-client:${{ github.sha }} \
--version=${{ env.version_name }} \
--no-promote \
--project=${{ secrets.SV_PROJ_NAME }}
- name: Get the version URL
id: get_version
run: echo "version_url=$(gcloud app versions list --uri --service=investigations-client --filter=version.id:${{ env.version_name }})" >> $GITHUB_ENV
- name: Post the URL to the PR
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
A preview of this PR will be available at ${{ env.version_url }} until the request is closed.
reactions: '+1'
cleanup:
name: 'Cleanup PR Preview'
runs-on: ubuntu-latest
if: ${{ github.event.action == 'closed'}}
# Checkout the repository to the GitHub Actions runner
steps:
- name: Checkout
uses: actions/checkout@v2
# gcloud CLI setup
- name: Login to GCP
uses: google-github-actions/setup-gcloud@v0
with:
service_account_key: ${{ secrets.DEV_SA_KEY }}
project_id: ${{ secrets.SV_PROJ_NAME }}
export_default_credentials: true
- name: Format version name
id: version_name
run: echo "version_name=$(echo \"${{ github.head_ref }}\" | tr -cd '[:alnum:]' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
# Destruct!
- name: Destroy version
run: gcloud app versions delete ${{ env.version_name }} --service=investigations-client