Skip to content

Commit

Permalink
Add support for specifying version constraints
Browse files Browse the repository at this point in the history
This adds support for specifying a version _constraint_ for the version of gcloud. Since the GitHub Actions runners pre-install a version of gcloud, this can dramatically reduce CI times.
  • Loading branch information
sethvargo committed Feb 2, 2023
1 parent fb149a7 commit 62eba4a
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 2,140 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/integration.yml
Expand Up @@ -38,6 +38,12 @@ jobs:
- name: 'Build'
run: 'npm ci && npm run build'

# Constraint installation
- name: 'Install constraint'
uses: './'
with:
version: '>= 1.0.0'

# Default installation
- name: 'Install version'
uses: './'
Expand Down
47 changes: 43 additions & 4 deletions README.md
Expand Up @@ -41,6 +41,8 @@ jobs:

- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
with:
version: '>= 363.0.0'

- name: 'Use gcloud CLI'
run: 'gcloud info'
Expand All @@ -50,13 +52,48 @@ jobs:

### Cloud SDK inputs

- `version`: (Optional) A string representing the version of the Cloud SDK
(`gcloud`) to install (e.g. `"290.0.1"`). The default value is "latest",
which will install the latest available Cloud SDK version.
- `version`: (Optional) A string representing the version or version
constraint of the Cloud SDK (`gcloud`) to install (e.g. `"290.0.1"` or `">=
197.0.1"`). The default value is `"latest"`, which will always download and
install the latest available Cloud SDK version. This can take a considerable
amount of time, especially on Windows.

If you do not need the latest version of the `gcloud` CLI, we strongly
recommend setting a minimum version constraint instead. This can
dramatically speed up your GitHub Action runs, since the GitHub Action
runner comes with a [pre-installed version of gcloud][github-runners].

```yaml
- uses: 'google-github-actions/setup-gcloud@v1'
with:
version: '>= 416.0.0'
```

If there is no installed `gcloud` version that matches the given constraint,
this GitHub Action will download and install the latest available version
that still matches the constraint. To always use the system-provided
version, specify a version of `> 0.0.0`:

```yaml
- uses: 'google-github-actions/setup-gcloud@v1'
with:
version: '> 0.0.0'
```

**Warning!** Workload Identity Federation requires version
[363.0.0](https://cloud.google.com/sdk/docs/release-notes#36300_2021-11-02)
or newer.
or newer. If you need support for Workload Identity Federation, specify your
version constraint as such:

```yaml
- uses: 'google-github-actions/setup-gcloud@v1'
with:
version: '>= 363.0.0'
```

You are responsible for ensuring the `gcloud` version matches the features
and components required. See the [gcloud release
notes][gcloud-release-notes] for a full list of versions.

- `project_id`: (Optional) Project ID (**not** project _number_) of the Google
Cloud project. If provided, this will configure the `gcloud` CLI to use that
Expand Down Expand Up @@ -233,3 +270,5 @@ See [LICENSE](LICENSE).
[sa-iam-docs]: https://cloud.google.com/iam/docs/service-accounts
[sa]: https://cloud.google.com/iam/docs/creating-managing-service-accounts
[wif]: https://cloud.google.com/iam/docs/workload-identity-federation
[github-runners]: https://github.com/actions/runner-images
[gcloud-release-notes]: https://cloud.google.com/sdk/docs/release-notes
11 changes: 6 additions & 5 deletions action.yml
Expand Up @@ -21,18 +21,19 @@ description: |-
inputs:
version:
description: |-
Version of the gcloud SDK to install. If unspecified or set to "latest",
the latest available gcloud SDK version for the target platform will be
installed. Example: "290.0.1".
default: latest
Version or version constraint of the gcloud SDK to install. If
unspecified, it will accept any installed version of the gcloud SDK. If
set to "latest", it will download the latest available SDK. If set to a
version constraint, it will download the latest available version that
matches the constraint. Examples: "290.0.1" or ">= 197.0.1".
default: 'latest'
required: false

project_id:
description: |-
ID of the Google Cloud project. If provided, this will configure gcloud to
use this project ID by default for commands. Individual commands can still
override the project using the --project flag which takes precedence.
default: null
required: false

install_components:
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

0 comments on commit 62eba4a

Please sign in to comment.