Skip to content

Commit

Permalink
automate deployment of review application (#228)
Browse files Browse the repository at this point in the history
* set `deploy-cloudrun` to v1
* checkout repository in deploy workflow
* setup deployment flag
  • Loading branch information
cameronraysmith committed Apr 27, 2023
1 parent 70c0b4d commit 9ee355a
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,45 @@ env:
IMAGE_NAME: pyrovelocityapp

jobs:
build-and-push-image:
set-deploy-flag:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
deploy_flag: ${{ steps.set-deploy-flag.outputs.deploy_flag }}

steps:
- name: "Print github context"
run: |
echo " EVENT_NAME:" "$GITHUB_EVENT_NAME"
echo " REF:" "$GITHUB_REF"
echo "REPOSITORY OWNER:" "$GITHUB_REPOSITORY_OWNER"
echo " REF NAME:" "$GITHUB_REF_NAME"
echo " full_name: ${{ github.event.repository.full_name }}"
echo " repository: ${{ github.repository }}"
echo "repository_owner: ${{ github.repository_owner }}"
echo " default_branch: ${{ github.event.repository.default_branch }}"
echo "REPOSITORY_OWNER:" "$GITHUB_REPOSITORY_OWNER"
echo " REF_NAME:" "$GITHUB_REF_NAME"
echo " HEAD_REF:" "$GITHUB_HEAD_REF"
echo " BASE_REF:" "$GITHUB_BASE_REF"
echo " SHA:" "$GITHUB_SHA"
- name: Set deploy flag
id: set-deploy-flag
run: |
DEPLOY_FLAG=false
if [[ "${{ inputs.deploy }}" == "true" ]] || \
[[ "${{ github.event_name }}" == "push" && \
"${{ github.ref }}" == "refs/heads/${{ github.event.repository.default_branch }}" && \
"${{ github.repository_owner }}" == "pinellolab" ]]; then
DEPLOY_FLAG=true
fi
echo "deploy_flag will be set to: $DEPLOY_FLAG"
echo "deploy_flag=$DEPLOY_FLAG" >> "$GITHUB_OUTPUT"
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
Expand Down Expand Up @@ -80,21 +103,23 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}

deploy-cloud-run:
needs: build-and-push-image
needs: [build-and-push-image, set-deploy-flag]
runs-on: ubuntu-latest
if: ${{ inputs.deploy }}
if: ${{ needs.set-deploy-flag.outputs.deploy_flag }}
permissions:
contents: read
packages: read

steps:
- name: Checkout
uses: actions/checkout@v3
- name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_DATA }}"
- name: Deploy to Cloud Run
id: "deploy"
uses: google-github-actions/deploy-cloudrun@v2
uses: google-github-actions/deploy-cloudrun@v1
with:
service: pyrovelocityapp
image: ${{ env.GAR_REGISTRY }}/${{ secrets.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
Expand Down

0 comments on commit 9ee355a

Please sign in to comment.