From d55732753e6503926666ccd53c5dbd43c43010ec Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Mon, 4 Nov 2024 13:26:09 +0000 Subject: [PATCH] refactor: update workflow names and paths for cloudrun deployment --- .github/workflows/deploy_api.yml | 14 ++++++++------ .github/workflows/deploy_app.yml | 19 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/deploy_api.yml b/.github/workflows/deploy_api.yml index b7fb4bc..eec6901 100644 --- a/.github/workflows/deploy_api.yml +++ b/.github/workflows/deploy_api.yml @@ -1,11 +1,11 @@ -name: Deploy API to cloud-run +name: Deploy api to cloudrun on: pull_request: paths: - "api/**" - "services/**" - "utils_pkg/**" - - ".github/workflows/api.yml" + - ".github/workflows/deploy_api.yml" push: branches: - main @@ -13,7 +13,7 @@ on: - "api/**" - "services/**" - "utils_pkg/**" - - ".github/workflows/api.yml" + - ".github/workflows/deploy_api.yml" tags: - "release-*" @@ -55,6 +55,8 @@ jobs: runs-on: ubuntu-latest needs: [prepare] timeout-minutes: 10 + permissions: + pull-requests: write env: VERSION: ${{ needs.prepare.outputs.VERSION }} steps: @@ -114,7 +116,7 @@ jobs: runs-on: ubuntu-latest if: ${{ github.ref == 'refs/heads/main' }} needs: [prepare, deploy] - timeout-minutes: 2 + timeout-minutes: 3 steps: - uses: google-github-actions/auth@v2 with: @@ -125,12 +127,12 @@ jobs: cleanup: runs-on: ubuntu-latest needs: promote - timeout-minutes: 2 + timeout-minutes: 3 steps: - uses: google-github-actions/auth@v2 with: credentials_json: "${{ secrets.GCP_SA_KEY }}" - uses: google-github-actions/setup-gcloud@v2 - - name: Cleanup older revisions + - name: cleanup older revisions run: | gcloud run revisions list --service=${{ env.SERVICE }} --project=${{ env.PROJECT_ID }} --region=us-central1 --sort-by=CREATE_TIME --format="value(REVISION)" | tail -n +4 | xargs -I {} gcloud run revisions delete {} --project=${{ env.PROJECT_ID }} --region=us-central1 --quiet diff --git a/.github/workflows/deploy_app.yml b/.github/workflows/deploy_app.yml index 309175a..fb917c9 100644 --- a/.github/workflows/deploy_app.yml +++ b/.github/workflows/deploy_app.yml @@ -1,11 +1,10 @@ -name: Deploy app to Google Cloudrun +name: Deploy app to cloudrun on: pull_request: paths: - "app/**" - "services/**" - "utils_pkg/**" - - ".streamlit" - ".github/workflows/deploy_app.yml" push: branches: @@ -14,7 +13,6 @@ on: - "app/**" - "services/**" - "utils_pkg/**" - - ".streamlit" - ".github/workflows/deploy_app.yml" tags: - "release-*" @@ -36,6 +34,7 @@ jobs: prepare: runs-on: ubuntu-latest outputs: + SHORT_SHA: ${{ steps.prepare_env.outputs.SHORT_SHA }} VERSION: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || format('main-{0}', steps.prepare_env.outputs.SHORT_SHA) }} steps: - uses: actions/checkout@v4 @@ -44,7 +43,13 @@ jobs: - id: prepare_env run: | echo "TAGGED=${{ startsWith(github.ref, 'refs/tags/api') }}" >> $GITHUB_OUTPUT - echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + SHORT_SHA=$(git rev-parse --short HEAD) + echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_OUTPUT + + RAW=$(git branch -r --contains $SHORT_SHA) + TAG_BRANCH_NAME="${RAW##*/}" + echo "TAG_BRANCH_NAME=$TAG_BRANCH_NAME" >> $GITHUB_OUTPUT deploy: runs-on: ubuntu-latest @@ -52,10 +57,10 @@ jobs: timeout-minutes: 10 permissions: pull-requests: write + env: + VERSION: ${{ needs.prepare.outputs.VERSION }} steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - uses: actions/setup-python@v5 with: python-version: "3.12" @@ -83,7 +88,7 @@ jobs: with: service: ${{ env.SERVICE }} source: ./ - tag: ${{ needs.prepare.outputs.VERSION }} + tag: ${{ env.VERSION }} no_traffic: true timeout: "5m" gcloud_version: "482.0.0"