From f45910a4191d404fad3195d46b04015348472499 Mon Sep 17 00:00:00 2001 From: Eric Rosas Date: Tue, 19 Sep 2023 16:59:59 -0600 Subject: [PATCH] Added worklows to int EPO-8491 Added workflows to int --- .github/workflows/main-pr-gae.yaml | 118 +++++++++++++++++++++++++++ .github/workflows/main-push-gae.yaml | 39 +++++++++ 2 files changed, 157 insertions(+) create mode 100644 .github/workflows/main-pr-gae.yaml create mode 100644 .github/workflows/main-push-gae.yaml diff --git a/.github/workflows/main-pr-gae.yaml b/.github/workflows/main-pr-gae.yaml new file mode 100644 index 0000000..31dcb2c --- /dev/null +++ b/.github/workflows/main-pr-gae.yaml @@ -0,0 +1,118 @@ +name: 'Build Image on PR Creation to Int ~ Optional: Deploy Preview Instances' + +on: + pull_request: + types: + - 'opened' + - 'synchronize' + - 'reopened' + - 'closed' + branches: + - 'main' + +jobs: + build-image-no-deploy: + name: 'Build Image Without Deploy - No Preview' + runs-on: ubuntu-latest + if: ${{ (github.event.action != 'closed') && (startsWith(github.head_ref, 'preview') == false) }} + + # 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.SKYVIEWER_INT_SERVICE_ACCOUNT }} + project_id: edc-int-6c5e + export_default_credentials: true + + - name: Get secret to create .env + run: gcloud secrets versions access latest --secret=investigations-api-env > ./api/.env + + - name: Setup docker build + uses: docker/setup-buildx-action@v2 + id: buildx + with: + install: true + + - name: Build client, but don't deploy + run: docker build . + + build-push-deploy: + name: 'Build Image and Deploy Preview Version' + runs-on: ubuntu-latest + if: ${{ (github.event.action != 'closed') && (startsWith(github.head_ref, 'preview') == true) }} + + # 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.SKYVIEWER_INT_SERVICE_ACCOUNT }} + project_id: edc-int-6c5e + export_default_credentials: true + + - name: Get app.yaml + run: gcloud secrets versions access latest --secret=investigations-api-appyaml > app.yaml + + - name: Format version name + id: version_name + run: echo "version_name=$(echo \"${{ github.head_ref }}\" | tr -cd '[:alnum:]' | tr '[:upper:]' '[:lower:]' | tr -d 'preview')" >> $GITHUB_ENV + + - name: Deploy to App Engine + env: + BRANCH_NAME: ${{ env.version_name }} + run: | + gcloud app deploy app.yaml \ + --no-promote \ + --version=${BRANCH_NAME,,} + + # Create or update a comment with the URL + - name: Find Comment + uses: peter-evans/find-comment@v1 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: A preview of this PR + + - name: Create or update a comment with the URL to the PR + uses: peter-evans/create-or-update-comment@v1 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + A purreview of this PR will be available at https://${{ github.head_ref }}-dot-investigations-api-dot-skyviewer.uw.r.appspot.com until the request is closed. :cat2: + reactions: '+1' + edit-mode: replace + + cleanup: + name: 'Cleanup PR Preview' + runs-on: ubuntu-latest + if: ${{ (github.event.action == 'closed') && (startsWith(github.head_ref, 'preview') == true) }} + + # 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.SKYVIEWER_INT_SERVICE_ACCOUNT }} + project_id: edc-int-6c5e + export_default_credentials: true + + # Destruct! + - name: Destroy version + env: + BRANCH_NAME: ${{ env.version_name }} + run: gcloud app versions delete ${BRANCH_NAME,,} --service=investigations-api \ No newline at end of file diff --git a/.github/workflows/main-push-gae.yaml b/.github/workflows/main-push-gae.yaml new file mode 100644 index 0000000..47711f7 --- /dev/null +++ b/.github/workflows/main-push-gae.yaml @@ -0,0 +1,39 @@ +name: 'Push to Development after PR Merge' + +on: + push: + branches: + - 'main' + +jobs: + build-push-deploy: + name: 'Deploy Development Version' + 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.SKYVIEWER_INT_SERVICE_ACCOUNT }} + project_id: edc-int-6c5e + export_default_credentials: true + + - name: Get app.yaml + run: gcloud secrets versions access latest --secret=investigations-api-appyaml > app.yaml + + - name: Format version name + id: version_name + run: echo "version_name=$(echo \"${{ github.head_ref }}\" | sed 's/[_.,\/]/-/g' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + - name: Deploy to App Engine + env: + BRANCH_NAME: ${{ env.version_name }} + run: | + gcloud app deploy app.yaml \ + --promote