google-github-actions / deploy-appengine

A GitHub Action that deploys source code to Google App Engine.
https://cloud.google.com/appengine
254 stars 72 forks source link

`project_id` arg mapped to `--project` for deploy command #355

Closed harveysanders closed 6 months ago

harveysanders commented 8 months ago

TL;DR

The project_id Action argument is mapped to project when passed to the deploy command. https://github.com/google-github-actions/deploy-appengine/blob/24e0c36ed7593b83beee803db490735c270338d6/src/main.ts#L161-L162

So if one passes a GCP project ID (number) instead of the project name, you get an error like this:

failed to execute gcloud command `gcloud app deploy --quiet --format json app.yaml --project ***..`
The value of ``--project'' flag was set to Project number. To use this command, set it to PROJECT ID instead.

Expected behavior

The action arg probably would be clearer if named project and/or pass the action's project_id value as the --project-id deploy arg.

Observed behavior

Using a GCP project ID (ex: 1011234567890) Results in an error:

Error: google-github-actions/deploy-appengine failed with: failed to execute gcloud command `gcloud app deploy --quiet --format json app.yaml --project *** --version 20240308-commit-8860de5 --promote`: ERROR: (gcloud.app.deploy) The value of ``--project'' flag was set to Project number.To use this command, set it to PROJECT ID instead.

Action YAML

name: Deploy

on:
  push:
    branches: [main]
  workflow_run:
    workflows: ["Test"]
    types: [completed]
    branches: [main]
  workflow_dispatch:

# Cancel any existing deployments so only latest one is deployed
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build-deploy-to-app-engine:
    # TODO: Fix condition to run on successful tests run
    # if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
    permissions:
      contents: "read"
      id-token: "write"

    environment: production
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - id: "auth"
        uses: "google-github-actions/auth@v2"
        with:
          workload_identity_provider: "${{ secrets.WIF_PROVIDER }}"
          service_account: "${{ secrets.GCP_SA_EMAIL }}"

      - name: 🏗 App Version
        # Ex version: "20231213-commit-643ef27"
        run: |
          echo "GIT_HEAD=$(git rev-parse HEAD)" >> $GITHUB_ENV
          echo "APP_VERSION=$( date '+%Y%m%d' )-commit-$(git rev-parse --short HEAD)" >> $GITHUB_ENV

      - id: "deploy"
        uses: "google-github-actions/deploy-appengine@v2"
        with:
          project_id: "${{ secrets.GCP_PROJECT_ID}}" # Ex: 1011234567890
          version: "${{ env.APP_VERSION }}"
          deliverables: "app.yaml"
          promote: true
          build_env_vars: |-
            GOFLAGS=-mod=mod

Log output

Run google-github-actions/deploy-appengine@v2
/usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /home/runner/work/_temp/[redacted] -f /home/runner/work/_temp/[redacted]
Successfully authenticated
Running: gcloud app deploy --quiet --format json app.yaml --project *** --version 20240308-commit-8860de5 --promote
Error: google-github-actions/deploy-appengine failed with: failed to execute gcloud command `gcloud app deploy --quiet --format json app.yaml --project *** --version 20240308-commit-8860de5 --promote`: ERROR: (gcloud.app.deploy) The value of ``--project'' flag was set to Project number.To use this command, set it to PROJECT ID instead.

Additional information

No response

sethvargo commented 6 months ago

Hi @harveysanders thank you for reporting an issue. --project matches the gcloud flag name, which is our goal. gcloud does not accept project numbers.